1. Given the following string variables, write a statement that would add str2 t
ID: 3628083 • Letter: 1
Question
1. Given the following string variables, write a statement that would add str2 to the end of str1. Do not use an assignment statement to do this.string str1 = "Here is an ";
string str2 = "example string";
2. Given the following string variable, write a statement that would output the number of characters in str1.
string str1 = "Here is an example string";
3. Create an output format statement which would generate lines in the table which appear as shown below. The Employee Name Field displays an employee name contained in the name variable. YYY displays an integer value from the age variable which ranges from 1 thru 100 and should be right justified. XXXXX.XX displays a monetary value from the salary variable which ranges from 0.01 to 99999.99 and should also be right justified. Use the variables shown below in your output statements.
Employee Name Field------YYY----$XXXXX.XX
char name[25]; int age; double salary;
Explanation / Answer
1. str1 += str2;
2. cout << str1.length();
3. #include <iomanip>
cout <<setw(25)<<right<<name<<setw(3)<<right<<age<<setw(8)<<right<<setprecision(2)<<salary<<endl;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.