Reference no: EM133548630
Exercise 1
Summarize a brief description of the lab project below and outline the objectives of this of the various exercises.
You can organize the subsections according to different parts of the project (e.g. "Exercise 1", "Exercise 2" and so on), and include the problem statement, source code, results, and your observations under each subsection. Discuss the problems you encountered and how you resolved them. Summarize what is achieved in the lab project.
(a). Build a new project and add the following simple C++ program in it. Make sure that you type in the program exactly as shown.
// This is our first C++ program.
#include <iostream>
using namespace std;
int main()
{
couts << " What is your favorite" << endl;
cout << " flavor of ice cream? " << endl;
return 0;
}
(b). Build the project. What do you see in the Output window? Clearly show the error message in your lab report (you need to show error messages for all subsequent exercises, if any).
(c). Go to the line with error, which is indicated in the error message, correct the error by replacing "couts" with "cout". Build the project again and show the results in your lab report.
(d). Remove the semicolon from the end of the line
couts << " What is your favorite" << endl;
Try to compile this altered version. How does your compiler respond?
(e). Correct the error introduced in Step (d), and then remove the closing brace } at the end of the program. Try to compile this altered version. How does your compiler respond? Correct the error and rebuild the program.
Exercise 2
(a). Omit the following lines
#include <iostream>
using namespace std;
from the corrected program in Exercise 1 and try to compile the modified version. Record what happens.
(b). Remove both cout statements (not just the word cout, a statement ends with ;) from the modified program in Step (a) and try to compile the program. Explain the results.
Exercise 3
(a). Remove "<< endl" from the line
cout << " What is your favorite" << endl;
from the corrected program in Exercise 1 and try to compile the modified version. Record what happens and explain what "<< endl" does from your observation.
(b). Now your program is free of error, but it does not show the sentence
"What is your favorite flavor of ice cream?" properly. How do you solve this problem? Record what you did and the new results.
Exercise 4
(a). Replace the procedural part of the function main in Exercise 1 with the following lines, one line at a time. Build the program, if it contains error, record the error message, otherwise record the results. (That means you need to repeat the steps change-> build-> run-> record for four times.)
cout << "Oh, I love to program in C++." << endl;
cout << "Oh, I love to program in "C++"." << endl;
cout << "Oh, I love to program in ""C++""." << endl;
cout << "Oh, I love to program in \"C++\"." << endl;
What rule can you derive about printing sentences containing quotation marks?
(b). What is the meaning of the backslash mark?
Exercise 5
Build a program that prints the message:
My name is Hector; I am a vector.
I am the subject of many Physics lectures!
a). All on one line
(b). On two lines
(c). On two lines and inside a box drawn with asterisks (*).
For these three cases, include your programs and the corresponding outputs in your lab report.