Computer Science I Midterm

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

A statement that starts with a # is called a comment True False

False

If you use a C++ key word as an identifier, your program will compile, link, but not execute. True False

False

The following code correctly determines whether x contains a value in the range of 0 through 100. if (x >= 0 && <= 100) True False

False

When using the equality operator to compare integer values there will be potential round-off errors. True False

False

What is the value of donuts after the following code executes? int donuts = 10; if (donuts ! = 10) donuts = 0; else donuts + = 2; A)12 B)10 C)0 D)2

A)12

What will the value of x be after the following statements execute? int x = 0; int y = 5; int z = 4; x = y + z * 2; A)13 B)18 C)0 D)none of the above

A)13

After execution of the following code, what will be the value of input_value if the value 0 is entered at the keyboard at run time? cin >> input_value; if (input_value > 5) input_value = input_value + 5; else if (input_value > 2) input_value = input_value + 10; else input_value = input_value + 15; A)15 B)10 C)25 D)0 E)5

A)15

What will the following segment of code output if 11 is entered at the keyboard? int number; cin >> number; if (number > 0) cout << "C++"; else cout << "Soccer"; cout << "is"; cout << "fun" << endl; A)C++ is fun B)Soccer is fun C)C++ D)C++fun E)Soccerfun

A)C++ is fun

Which of the following is not one of the five major components of a computer system? A)Preprocessor B)CPU C)main memory D)I/O devices E)secondary storage

A)Preprocessor

Without this statement appearing in a switch construct, the program "falls through" all of the statements below the one with the matching case expression. A)break B)exit C)switch D)scope E)none of these

A)break

When a program lets the user know that an invalid choice has been made, this is known as: A)input validation B)output validation C)compiler criticism D)output validation E)none of these

A)input validation

What is the value of the following expression? true && true A)true B)false C)-1 D)+1

A)true

Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main () 5 { 6 int number = 5; 7 8 if (number >= 0 && <= 100) 9 cout << "passed. \n" <<; 10 else 11 cout << "failed. \n" <<; 12 return 0; 13} A)6 B)8 C)10 D)9

B)8

_____________ represent storage locations in the computer's memory A)Literal B)Variable C)Comments D)Integers E)none of these

B)Variable

Given that x = 2, y = 1, and z = 0, what will the following cout statement display? cout << "answer" << (x I I !y && z) << endl; A)answer = 0 B)answer = 1 C)answer = 2 D)none of these

B)answer = 1

In C++ the = operator indicates: A)equality B)assignment C)subtraction D)negation E)none of these

B)assignment

What will be the output of the following code segment after the user enters 0 at the keyboard? int x = -1; cout << "Enter a 0 or a 1 from the keyboard: "; cin >> x; if (x) cout << "true" << endl; else cout << "false" << endl; A)nothing will be displayed B)false C)x D)true

B)false

If you place a semicolon after the statement if (x < y) A)the code will not compile B)the compiler will interpret the semicolon as a null statement C)the if statement will always evaluate to false D)all of these E)none of these

B)the compiler will interpret the semicolon as a null statement

When a relational expression is false, it has the value ________. A)one B)zero C)zero, one, or minus one D)none of these

B)zero

What is the value of donuts after the following code executes? int donuts = 10; if (donuts = 1) donuts = 0; else donuts + = 2; A)12 B)10 C)0 D)1

C)0

What is the output of the following segment of code if 4 is input by the user when asked to enter a number? int num; int total = 0; cout << "Enter a number from 1 to 100: "; cin >> num; switch (num) { case 1: case 2: total = 5; case 3: total = 10; case 4: total = total + 3; case 8: total = total + 6; default: total = total + 4; } cout << total << endl; A)0 B)3 C)13 D)28 E)none of these

C)13

Assuming x is 5, y is 6, and z is 8, which of the following is false? 1. x == 5; 2. 7 <= (x + 2); 3. z <= 4; 4. (1 + x) ! = y; 5. z >= 8; 6. x >= 0; 7. x <= (y * 2) A)3, 4, 6, 7 are false. B)only 5 is false. C)3 and 4 false. D)all are false. E)none of these.

C)3 and 4 false.

Which value can be entered to cause the following code segment to display the message "That number is acceptable." int number; cin >> number; if (number > 10 && number < 100) cout << "That number is acceptable. \n"; else cout << "That number is not acceptable. \n"; A)100 B)10 C)99 D)0 E)all of these

C)99

When an if statement is placed within the conditionally-executed code of another if statement, this is known as: A)complexity B)overloading C)nesting D)validation E)none of these

C)nesting

The default section of a switch statement performs a similar task as the ________ portion of an if/else if statement. A)conditional B)break C)trailing else D)all of these E)none of these

C)trailing else

Which of the following expressions will determine whether x is less than or equal to y? A)x > y B)x =< y C)x <= y D)x >= y

C)x <= y

Input values should always be checked for: A) Appropriate range B) Reasonableness C) Division by zero, if division is taking place D) All of these E) None of these

D) All of these

What is the output of the following code? int w = 98; int x = 99; int y = 0; int z = 1; if (x >= 99) { if (x < 99) cout << y << endl; else cout << z << endl; } else { if (x == 99) cout << x << endl; else cout << w << endl; } A)98 B)99 C)0 D)1

D)1

What will the following program segment display? int funny = 7, serious = 15; funny = serious % 2 if (funny ! = 1) { funny = 0; serious = 0; } else if (funny == 2) { funny = 10; serious = 10; } else { funny = 1 serious = 1 } cout << funny << " " << serious << endl; A)7 15 B)0 0 C)10 10 D)1 1 E)none of these

D)1 1

Given the following code segment, what is output after "result = "? int x = 1, y = 1, z = 1; y = y + z; x = x + y; cout << "result" = " << (x < y ? y : x) << endl; A)0 B)1 C)2 D)3 E)none of these

D)3

What will following segment of code output? int x = 5; if (x = 2) cout << "This is true!" << endl; else cout << "This is false!" << endl; cout << "This is all folks!" << endl; A)This is true! B)This is false! C)This is true! This is false! D)This is true! This is all folks! E)none of these

D)This is true! This is all folks!

An example of a secondary storage device is a hard drive True False

True

As a rule of style, when writing an if statement you should indent the conditionally-executed statements. True False

True

Both of the following if statements perform the same operation. if (sales > 10000) commissionRate = 0.15; if (sales > 10000) commissionRate = 0.15; True False

True

Floating point constants are normally stored in memory as doubles True False

True

If the sub-expression on the left side of an && operator is false, the expression on the right side will not be checked. True False

True

If the sub-expression on the left side of the || operator is true, the expression on the right side will not be checked. True False

True

The following code correctly determines whether x contains a value out of the range of 0 through 100. if (x < 0 || x > 100) True False

True

Variables need to be declared before they can be used. True False

True

You should be careful when using the equality operator to compare floating point values because of potential round-off errors. True False

True


Ensembles d'études connexes

Ch. 9 - Chemical Names and Formulas

View Set

Neurosensory and Musculoskeletal ATI

View Set

QuickBooks Online Certification Test Study Guide

View Set

Clinical Psychology Science Exam 1

View Set