lab 2
What will the following program print on the screen? #include <iostream> using namespace std; int main() { int x = 0, y = 2; x = y * 4; cout << x << endl << y << endl; return 0; }
8 2
Of the following, which is a valid C++ identifier? A) June1997 B) _employee_number C) ___department D) myExtraLongVariableName E) All of the above are valid identifiers.
E
What will the following code display? cout << "Four\n" << "score\n"; cout << "and" << "\nseven"; cout << "\nyears" << " ago" << endl;
Four score and seven years ago
What will the following code display? cout << "Four " << "score "; cout << "and " << "seven/n"; cout << "years" << "ago" << endl;
Four score and seven/nyearsago
What will the following code display? cout << "Four" << "score" << endl; cout << "and" << "seven" << endl; cout << "years" << "ago" << endl;
Fourscore andseven yearsago
Modify the following program so it prints two blank lines between each line of text. #include <iostream> using namespace std; int main() { cout << "Two mandolins like creatures in the"; cout << "dark"; cout << "Creating the agony of ecstasy."; cout << " - George Barker"; return 0; }
#include <iostream> int main() { cout << "Two mandolins like creatures in the\n\n\n"; cout << "dark\n\n\n"; cout << "Creating the agony of ecstasy.\n\n\n"; cout << " - George Barker\n\n\n"; return 0; }
What will the following code display? int x = 0, y = 1, z = 2; cout << x << y << z << endl;
012
12. What is the output of the following statement? cout << 4 * (15 / (1 + 3)) << endl;
12
12. What is the value of cookies after the execution of the following statements? int number = 38, children = 4, cookies; cookies = number % children;
2
What will the value of x be after the following statements execute? int x; x = 18 % 4;
2
What will the following program print on the screen? #include <iostream> using namespace std; int main() { int a, x = 23; a = x % 2; cout << x << endl << a << endl; return 0; }
23 1
Which one of the following would be an illegal variable name?
3dGraph
What will the value of x be after the following statements execute? int x; x = 18 / 4;
4
What will the value of x be after the following statements execute? int x; x = 18.0 / 4;
4.5
What will the following program print on the screen? #include <iostream> using namespace std; int main() { cout << "Be careful\n"; cout << "This might/n be a trick "; cout << "question\n"; return 0; }
Be careful This might/n be a trick question
What will the following program print on the screen? #include <iostream> using namespace std; int main() { cout << "I am the incredible"; cout << "computing\nmachine"; cout << "\nand I will\namaze\n"; cout << "you."; return 0; }
I am the incrediblecomputing machine and I will amaze you.
What will the following code display? cout << "Monday"; cout << "Tuesday"; cout << "Wednesday";
MondayTuesdayWednesday
There are a number of syntax errors in the following program. Locate as many as you can. */ What's wrong with this program? /* #include iostream using namespace std; int main(); } int a, b, c \\ Three integers a = 3 b = 4 c = a + b Cout << "The value of c is %d" < C; return 0; {
The C-style comments symbols are backwards. iostream should be enclosed in angle brackets. There shouldn't be a semicolon after int main. The opening and closing braces of function main are reversed. There should be a semicolon after int a, b, c. The comment \\ Three integers should read // Three integers. There should be a semicolon at the end of the following lines: a = 3 b = 4 c = a + b cout begins with a capital letter. The stream insertion operator (that appears twice in the cout statement) should read << instead of <. The cout statement uses the variable C instead of c.
What will the following code display? int number = 7; cout << "The number is " << "number" << endl;
The number is number
A variable whose value can be either true or false is of this data type.
bool