q2) CONSIDER THE FOLLOWING CODE: Using the following input: \"James\", \"Catheri
ID: 3810034 • Letter: Q
Question
q2)
CONSIDER THE FOLLOWING CODE:
Using the following input: "James", "Catherine", "Bill"
void caller(string &str, int count)
{
string List = "";
string space = " ";
string name;
for (int i = 2; i >= 0; i--)
{
cout << "enter a name : ";
cin >> name;
List = List + name + space;
}
for (int i = 0;i<List.length();i++)
if (List.at(i) == str.at(0))
count++;
}
////////////////////////////////////////////////////////////////
void Question()
{
string a = "e";
int count = 10;
caller(a, count);
cout << " Result = " << count;
}
Select one:
a. Result = 12
b. Result = 10
c. Result = 13
d. Result = 11
please explain how you get the answer. Thank you
Explanation / Answer
the answer is Result=10
from the function Question(), two arguments are passed to the caller() function.From Question() function, the string variable and int variables are send to the caller function. In caller() function, the string variable is received as the
reference parameter, other arguments as the default integer variable.
In the caller() function, three names are received as input from the user, then three names are concatenated with spaces in between them.Each character in the joined string is checked with character received from the Question()
if the character is found in the joined string, then count is incremented by one.
since, count is received as the auto variable from the question(), increment in the count variable is not reflected
in the Question(), when the control return back to the Question() function.so the result is 10, when printed.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.