Advance Programming Midterm
What is the value of the expression ( j = 7 )?
7
cout << pow(3, 2); will display
9
Are 'a' and "a" the same?
False
Is the following code acceptable to put 7 into the variable age? int age; 7 = age;
False
Is this correct? char m; m = "Y";
False
It this a correct c++ statement? cout << "Alcorn State University ranked number one among HBCU in Mississippi." << endl;
False
What will be displayed with the following statement? double d = 4.2; if (d > 3) cout << "Good"; else if(d > 2) cout << "Average"; else cout << "Poor";
Good
What will be displayed with the following statement? double d = 4.2; if (d > 3) cout << "Good"; else if (d > 2) cout << "Average"; else cout << "Poor";
Good
Which of the following is incorrect? Main memory is commonly known as random-access memory (RAM) Harddisk is faster than RAM. Harddisk can hold data without power to the computer. Data in RAM will be lost without power.
Harddisk is faster than RAM.
What are the three primary activities of a computer program?
Input, processing, and output
For the following code: cout << "Hello" << endl; Which of the following is correct? It is one statement that is spread out over two lines. It has two statements, one on each line. It is incorrect. It has three statements.
It is one statement that is spread out over two lines.
What will be displayed with the following code if the user entered John Smith? string fullname; cin >> fullname; cout << fullname;
John
Which of the following statements is incorrect? The compiler will make an executable program. The compiler can detect syntax errors in the source code. The compiler can generate object file. The compiler itself is a program.
The compiler will make an executable program.
Why is the "for" loop called a counter-controlled loop?
The for loop is also called a counter-controlled loop. There is a variable that we call "counter." It counts how many times we have run the loop body. The counter variable can often be used in the coding for other purposes.
Is this a correct c++ statement? cout << "I am a student in " << "the department of Social Science." << endl;
True
What will be displayed if variable a's value is 7? if (a > 8) { cout << "You made an A"; } else { cout << "You made a B"; }
You made a B
What will be displayed if variable a's value is 7? if ( a > 8 ) cout << "You made an A"; else cout << "You made a B"; cout << "You made a C";
You made a BYou made a C
What will be displayed if variable a's value is 7? if ( a > 8 ) { cout << "You made an A"; } else { cout << "You made a B"; } cout << "You made a C";
You made a BYou made a C
To display a random number using the following statement: cout << rand()%8<<endl; What random numbers are in the range for display? ([x, y] means from x to y, including x and y. e.g., [1,3] means 1,2,3.
[0,7]
int a, b, c, d; a = b = c = d = 7; c = 9; Which of the statements is true?
a is still 7 after 9 is put into c.
When to use the "for" loop?
a. When you know how many times you want to run the loop body. b. Example of not knowing how many times you want to run the loop body: Keep running the loop body until the user answers "No". c. Example of knowing how many times you want to run the loop body: Ask the user to enter a positive number. Display all the integers from 0 to that number.
MS-Word is
application software
Which of the following is true? c++ is a low-level language. c++ is a hardware. c++ is a software. c++ is a high-level language.
c++ is a high-level language.
Write a statement to declare a double constant pi. Make it equal to 3.14. (Use space only when you have to. In this example, you can have up to two spaces.)
const double pi=3.14;
int i = 3; int j = 2; how to display the result 3/2 as 1.5?
cout << (double)i/j;
Write a statement to display a random number. (DO NOT USE SPACE).
cout<<rand();
A variable must be _____ before a variable is used.
defined
Write a complete program (From #include to the end, pay attention to the details, declare variables as you need): 1. Display "How old are you?" 2. Get user input from keyboard. 3. Display "You are ??? years old." The ??? is the value that the user just entered.
do in notebook
Write a for loop?
for (x = 1; x <= 10; x=x+1) { cout << x << endl; }
string greeting; ______________ cout << greeting. You are asked to enter a line of code to get the input from the user what the greeting message is. The requirement is that if the user entered "Good morning, Alcorn.", the cout will display "Good morning, Alcorn." PLEASE DO NOT USE ANY SPACE ANYWHERE IN YOUR ANSWER. YOUR ANSWER SHOULD BE A COMPLETE STATMENT WITH THE ";" AT THE END.
getline(cin,greeting);
What will be displayed? Hint: read the question very carefully int i = 0; if ( i = 0 ) cout << "i is 0"; else cout << "i is not 0";
i is not 0
To fill the blank line, which of the following is right to do the following: if intage is greater than 17, display "Go to vote." Hint: pay attention to the ; and ( ) int intage; cin >> intage; _______________________ { cout << "Go to vote." << endl; }
if ( intage > 17 )
How to write a if statement to express "if a's value is 6 and b's value is greater than 100"?
if (a==6 && b>100)
Which of the following check whether variable intage equals to 18. if (intage == 18) if (intage = 18) if (intage equals to 18) if (intage != 18)
if (intage == 18)
How to write a statement to express "if x is 5 or y is 5"?
if (x == 5 || y == 5)
Where does cin read its input from?
keyboard
The linker converts ____________ into ______________
object code, executable code
The code you write, such as cout << "I like c+++"; is called
source code
MS-Windows is a
system software
How to write a while loop? Write in notebook
while (x <= 10) { cout << x << endl; x = x + 1; }