Question: 3. Consider the following C++ code: string str1; string str2; char ch; int index; cin >> str1; cin >> str2; cin >> index; ch =
3. Consider the following C++ code:
string str1;
string str2;
char ch;
int index;
cin >> str1;
cin >> str2;
cin >> index;
ch = str1[index];
str1[index] = str2[index];
str2[index] = ch;
cout << str1 << " " << str2 << endl;
Answer the following questions:
a. What is the output if the input is Hello There 2?
b. What is the output if the input is Diamond Gold 0?
c. What is the output if the input is C++ Java 1?
4. Suppose that you have the following statements:
string str1, str2;
cin >> str1 >> str2;
if (str1 == str2)
cout << str1 + '!' << endl;
else if (str1 > str2)
cout << str1 + " > " + str2 << endl;
else
cout << str1 + " < " + str2 << endl;
Answer the following questions:
a. What is the output if the input is Programming Project?
b. What is the output if the input is Summer Trip?
c. What is the output if the input is Winter Cold?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
