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
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