17 September 2014
You have up to 20 minutes. Please write your answers on this page, and your name at the top. You may not use the computer, notes, or books.
Which of the following statements prints exactly this text, as shown:
We the
PEOPLE
Select all that apply.
cout << "We the PEOPLE" << endl;
cout << "We the" << "endl" << "PEOPLE" << "endl";
cout << "We" << " the" << endl << "PEOPLE" << endl;
cout << "We the" << endl << "PEOPLE" << endl;
cout << "WE the" << endl << "people";
Both c and d produce the required output.
Given a variable maxDays = 14
, which statement prints 14
?
cout >> maxDays;
cout << maxDays;
cout << "maxDays";
print maxDays;
Only b.
Which of these are valid C++ comments, that will be ignored by the compiler? Select all that apply.
/* Hello world */
"Hello world"
# Hello world
/* Hello world
-- Hello world
(( Hello world ))
// Hello world
The valid comment forms are a, g.
Circle and describe any syntax errors in this program:
#include <iostream>
using namespace;
INT main( )
{
int score = 100;
cout << 'Hello world.' << endl
cout < score < '%';
return 0;
}
std
INT
<<
on second cout
#include <iostream>
using namespace std;
int main()
{
int lisa = 8;
int bart = lisa + 2;
int maggie = bart - 7;
cout << maggie << ", " << bart << lisa << endl;
return 0;
}
3, 108