Question
Here are the three functions that are implemented in the code below: void get_string(string &str_to_store); void set_replace_string(string copy_str, string &dash_str); int get_search_replace(char c, string copy_str,
Here are the three functions that are implemented in the code below:
void get_string(string &str_to_store); void set_replace_string(string copy_str, string &dash_str); int get_search_replace(char c, string copy_str, string &dash_str);
1a. Please change the prototypes in the code below to (Do not change the purpose of each function, modify the program so it works with the updated prototypes):
void get_string(string *str_to_store); void set_replace_string(string copy_str, string *dash_str); int get_search_replace(char c, string copy_str, string *dash_str);
1b. Please explain what has been passed into these pointer variables, and tell the difference between pass by reference and pass by pointers.
#include
void get_string(string& str_to_store); void set_replace_string(string copy_str, string& dash_str); int get_search_replace(char c, string copy_str, string& dash_str);
int main(){ string str_to_store, dash_str; char c; int count; get_string(str_to_store); set_replace_string(str_to_store,dash_str);
cout<<"Dash string : " << dash_str << endl; cout<<"Enter a character to search : "; cin >> c; cin.ignore(1024,' '); count = get_search_replace(c,str_to_store,dash_str); cout<<"Updated dash string: " << dash_str<
return 0; }
void get_string(string& str_to_store){ cout<<"Enter a string : "; getline(cin, str_to_store,' '); } void set_replace_string(string copy_str, string& dash_str){ dash_str =""; for(int i=0; i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started