3. Show what is printed by the following program: #include <iostream> #include <
ID: 3832655 • Letter: 3
Question
3. Show what is printed by the following program:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string first = “Lincoln”;
string last = “Z”;
string final = “Abc”;
char>
string::size_type k,m;
k = final.size();
m = first.length();
cout << k << “ ” << m <<endl;
k = first.find(“col”,0);
m=first.find(‘g’,0);
cout << k << “ “ << m << endl;
final = final + last;
last = “Truman”;
first[5] = ‘W’;
cout << first << “ “ << last << “ “ << final << ends;
last.erase(1,2) ;
last.insert(0,”Honest”);
cout << final << endl;
return 0;
}
Explanation / Answer
The output:
3 7
3 18446744073709551615
LincoWn Truman AbcZAbcZ
#include <iostream>
#include <string>
using namespace std;
int main()
{
string first = "Lincoln";
string last = "Z";
string final = "Abc";
char;
string::size_type k,m;
k = final.size(); // k will be 3
m = first.length(); // m will be 7
cout << k << " " << m <<endl; // The output will be 3 7
k = first.find("col",0); // k will be 3
m=first.find('g',0); // As g is not present a random value will be assigned.
cout << k << " " << m << endl; //
final = final + last; // final will become AbcZ
last = "Truman"; //last will be Truman
first[5] = 'W'; // first will be LincoWn
cout << first << " " << last << " " << final << ends; //LincoWn Truman AbcZ will be presented
last.erase(1,2) ;
last.insert(0,"Honest");
cout << final << endl;//AbcZ will be printed
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.