Computer science Test 1
What is output by the following code? cout << 9/4 << "..."; cout << 9/4.0 << "..."; cout << 9%4 << endl;
2...2.25...1
Given the following code, what value will be stored in j after this code is executed? int j = 12; double d = 45.90; j = d;
45
What is the output of the following program? int main () { int x, y, z; x = y = z = 4; x = x + 1; y += 2; z /= 2; cout << x << " " << y << " " << z << endl; }
5 6 2
This program will not compile because it is missing something. What is it? #include <iostream> using namespace std; int main() cout << "Hello, world!"; return 0; }
A { at the beginning of the line after int main()
Which of the following statements about identifiers is FALSE?
Any name is valid unless it is a C++ keyword.
This where the program (and its data) are stored while the program is running.
Main memory (RAM)
What is displayed to the screen when the following code is executed? int main() { /* cout << "Be careful "; //cout << "This might be a trick "; cout << "question."; */ }
There is no output.
Given variable declarations: int x; string y; which statements will input 9 into x and Patrick Mahomes into y if the user types the following when the program is running? 9 Patrick Mahomes
cin >> x; cin >> ws; getline(cin,y);
This translates each source code instruction into the appropriate machine language instruction
compiler
Which of the following is an example of a Named Constant?
const int TEN = 10;
Which of the following statements correctly inputs a value from the user into variable x?
cout << "Please enter a number: "; cin >> x;
Which data type can store the largest number?
double
Given the following declarations, I want to store x divided by y in a float variable z. Which of the answers below will keep the fractional part? int x; int y;
float z = static_cast<float>(x)/y;
Every complete C++ program must have a ________.
function named main
Which C++ statement below performs the following algebraic expression? ht12/4*k
g = (h + 12) / (4*k);
In the code below, which of the following is an example of a variable? int main () { int hello, goodbye; hello = 10; goodbye = 25; cout << hello / goodbye << endl; return 0; }
hello
Assuming all of the variables have already been declared (defined), which of the following is a valid assignment statements?
total = 0;
What is output by the following statements? float x = 12.3; cout << "!" << setw(5) << x;
! 12.3 (there is 1 space between ! and 1)
