CS 150 Quiz 1-10
In C++, the null character is represented as ____.
'\0'
The length of the string "Hello There. " is ____.
13
In C++, ____ is called the scope resolution operator.
: :
A step-by-step problem-solving process in which a solution is arrived at in a finite amount of time is called a(n) ____. A. Algorithm B. Linker C. Analysis D. Design
A
A(n) ____ consists of data and the operations on those data. A. Disk B. Compiler C. Interpreter D. Object
A
A(n) ____-controlled while loop uses a bool variable to control the loop. A. Flag B. Sentinel C. EOF D. Nested
A
Assume you have three int variables: x = 2, y = 6, and z. Choose the value of z in the following expression: z = (y / x > 0) ? x : y;. A. 2 B. 3 C. 4 D. 6
A
Consider the following C++ program. #include <iostream> using namespace std; int main() { cout << "Hello World " return 0; } In the cout statement, the missing semicolon in the code above will be caught by the ____. A. Compiler B. Editor C. Assembler D. Control unit
A
Consider the following code. // Insertion Point 1 using namespace std; const float PI = 3.14; int main() { //Insertion Point 2 float r = 2.0; float area; area = PI * r * r; cout << "Area = " << area <<endl; return 0; } // Insertion Point 3 In this code, where does the include statement belong? A. Insertion Point 1 B. Insertion Point 2 C. Insertion Point 3
A
Consider the following statements: string str1 = "Gone with the wind"; string str2; After the statement str2 = str1.substr(5,4); executes, the value of str2 is "____". A. With B. The wind C. Gone D. Wind
A
Given the function prototype: float test(int, int, int); which of the following statements is legal? A. cout << test(7, 14, 23); B. cout >> test(7.0, 14, 23); C. cout << test(2, 27, 15) D. cout << test(7.0, 14.5, 'A');
A
Suppose that alpha and beta are int variables. The statement alpha = --beta; is equivalent to the statement(s) ____. A. beta = beta - 1; alpha = beta; B. alpha = beta - 1; beta = alpha; C. alpha = beta; beta= alpha - 1; D. beta = alpha; alpha = beta - 1;
A
Suppose that x is an int variable, ch is a char variable, and the input is: 276. Choose the values after the following statement executes: cin >> ch >> x; A. ch = '2', x = 76 B. ch = '27', x = 6 C. ch = '0', x = 276 D. ch = '276', x = 0
A
The digit 0 or 1 is called a binary digit, or ____. A. Bit B. Bytecode C. Unicode D. Hexcode
A
The statement: return 2 * 3 + 1, 1 + 5; returns the value ____. A. 6 B. 8 C. 11 D. 5
A
The value of the expression 33/10, assuming both values are integral (integer) data types, is ____. A. 3 B. 3.3 C. 21 D. 14
A
What is the output of the following C++ code? num = 10; while (num > 10) num = num - 2; cout << num << endl; A. 10 B. 2 C. 15 D. 12
A
What is the output of the following code? char lastInitial = 'A'; switch (lastInitial) { case 'A': cout << "section 1" <<endl; break; case 'B': cout << "section 2" <<endl; break; case 'C': cout << "section 3" <<endl; break; case 'D': cout << "section 4" <<endl; break; default: cout << "section 5" <<endl; } A. section 1 B. section 2 C. section 3 D. section 5
A
What is the output of the following code? enum courses {ALGEBRA, BASIC, PASCAL, PHILOSOPHY, ANALYSIS}; courses registered; registered = ALGEBRA; cout << registered << endl; A. 0 B. Algebra C. Basic D. Pascal
A
What is the output of the following statements? cout << "123456789012345678901234567890" << endl cout << setfill('#') << setw(10) << "Mickey" << setfill(' ') << setw(10) << "Donald" << setfill('*') << setw(10) << "Goofy" << endl; A. 123456789012345678901234567890 ####Mickey Donald*****Goofy B. 123456789012345678901234567890 ####MickeyDonald*****Goofy C. 123456789012345678901234567890 ####Mickey***** Donald*****Goofy D. 123456789012345678901234567890 ####Mickey*****DonaldGoofy
A
When the power is switched off, everything in ____ is lost. A. Main Memory B. Secondary storage C. Hard disks D. Floppy disks
A
Which of the following correctly declares name to be a character array and stores "William" in it? A. char name[8] = "William"; B. name[8] = "William"; C. char name[8] = "William" D. char [8] = "William";
A
Which of the following is a valid C++ statement? A. typedef int integer; B. typedef int integer C. int typedef integer; D. integer typedef int;
A
A variable or expression listed in a call to a function is called the ____.
Actual Parameter
A program that loads an executable program into main memory is called a(n) ____. A. Compiler B. Loader C. Linker D. Assembler
B
A sequence of eight bits is called a ____. A. Binary Digit B. Byte C. Character D. Double
B
Consider the following code. (Assume that all variables are properly declared.) cin >> ch; while (cin) { cout << ch; cin >> ch; } This code is an example of a(n) ____ while loop. A. Flag B. EOF C. Sentinel D. Do
B
Suppose str = "xyzw";. After the statement str[2] = 'Y'; The value of str is "____". A. xYzw B xyYw C. xyzw D. xXyz
B
Suppose that you have the following declaration. enum cars {FORD, GM, TOYOTA, HONDA}; cars domesticCars = FORD; The statement: domesticCars = static_cast<cars>(domesticCars + 1); sets the value of domesticCars to ____. A. Ford B. GM C. Toyota D. Honda
B
Suppose x is 5 and y is 7. Choose the value of the following expression: (x != 7) && (x <= y) A. False B. True C. 0 D. null
B
The conditional operator ?: takes ____ arguments. A. two B. three C. four D. five
B
The devices that feed data and programs into computers are called ____ devices. A. Entry B. Input C. Output D. Secondary
B
The expression static_cast<int>(9.9) evaluates to ____. A. 10 B. 9 C. 9.9 D. 0
B
The term GB refers to ____. A. Giant Byte B. Gigabyte C. Group Byte D. Great Byte
B
What is the output of the following C++ code? int alpha[5] = {2, 4, 6, 8, 10}; int j; for (j = 4; j >= 0; j--) cout << alpha[j] << " "; cout << endl; A. 2 4 6 8 10 B. 10 8 6 4 2 C. 8 6 4 2 D. 2 4 6 8
B
What is the output of the following C++ code? int x = 35; int y = 45; int z; if (x > y) z = x + y; else z = y - x; cout << x << " " << y << " " << z << endl; A. 35 45 80 B. 35 45 10 C. 35 45 -10 D. 35 45 0
B
Which of the following function prototypes is valid? A. funcTest (int, int, float); B. int funcTest(int, int, float); C. int funcTest(int, int, float) D. funcTest(int, int, float)
B
The ____ statement can be used to eliminate the use of certain (flag) variables.
Break
A program called a(n) ____ combines the object program with the programs from libraries. A. Assembler B. Decoder C. Linker D. Compiler
C
A program called a(n) ____ translates instructions written in high-level languages into machine code. A. Assembler B. Decoder C. Compiler D. Linker
C
Assume you have the following declaration char nameList[100];. Which of the following ranges is valid for the index of the array nameList? A. 0 through 100 B. 1 through 100 C. 0 through 99 D. 1 through 99
C
Choose the output of the following C++ statement: cout << "Sunny " << '\n' << "Day " << endl; A. Sunny B. Day C. Sunny Day D. Sunny Day
C
Given the following function prototype: double tryMe(double, double);, which of the following statements is valid? Assume that all variables are properly declared. A. cout << tryMe(2.0, 3.0) B. cin >> tryMe(2.0, 3.0); C. cout << tryMe(2.0, 3.0); D. cout >> tryMe(2.0, 3.0);
C
Main memory is an ordered sequence of items, called ____. A. Pixels B. Registers C. Memory Cells D. Addresses
C
The devices that the computer uses to display results are called ____ devices. A. Exit B. Entry C. Output D. Input
C
The expression in an if statement is sometimes called a(n) ____. A. selection statement B. action statement C. decision maker D. action maker
C
The value of the expression 17 % 7 is ____. A. 4 B. 6 C. 3 D. 5
C
What does <= mean? A. less than B. greater than C. less than or equal to D. greater than or equal to
C
When one control statement is located within another, it is said to be ____. A. blocked B. compound C. nested D. closed
C
Which of the following expressions correctly determines that x is greater than 10 and less than 20? A. 10 < x < 20 B. (10 < x < 20) C. 10 < x && x < 20 D. 10 < x || x < 20
C
Which of the following is the "not equal to" relational operator? A. ! B. | C. != D. &
C
Which of the following loops is guaranteed to execute at least once? A. Sentinel loop B. While...Do loop C. Do...While loop D. Flag controlled loop
C
____ represent information with a sequence of 0s and 1s. A. Analog signals B. Application programs C. Digital Signals D. System programs
C
A variable listed in a header is known as a(n) ____ parameter. A. Informal B. True C. False D. Formal
D
Suppose j, sum, and num are int variables, and the input is 26 34 61 4 -1. What is the output of the code? sum = 0; cin >> num; for (int j = 1; j <= 4; j++) { sum = sum + num; cin >> num; } cout << sum << endl; A. 59 B. 201 C. 85 D. 125
D
Suppose that sum and num are int variables and sum = 5 and num = 10. After the statement sum += num executes, ____. A. sum = 5 B. sum = 10 C. sum = -5 D. sum = 15
D
Suppose that x and y are int variables. What would be a valid input statement? A. cin >> x >> y B. cin << x << y; C. cin << x << y D. cin >> x >> y;
D
The ____ is the brain of the computer and the single most expensive piece of hardware in your personal computer. A. MM B. ROM C. RAM D. CPU
D
What is a valid int value? A. 1.9 B. 1458.7 C. 10.0 D. 46259
D
An example of a floating point data type is ____.
Double
True or False A mixed arithmetic expression contains all operands of the same type.
False
True or False In C++, reserved words are the same as predefined identifiers.
False
True or False An operator that has only one operand is called a unique operator.
False
True or False Arrays can be passed as parameters to a function by value, but it is faster to pass them by reference.
False
True or False If the formal parameter list of a function is empty, the parentheses after the function name are not needed.
False
True or False The following return statement returns the value 10. return 10, 16;
False
True or False When you compile your program, the compiler identifies the logic errors and suggests how to correct them
False
True or False Assume that all variables are properly declared. The following for loop executes 20 times. for (i = 0; i <= 20; i++) cout << i;
False
True or False? A comma is also called a statement terminator.
False
True or False? The devices that feed data and programs into computers are called output devices.
False
A loop that continues to execute endlessly is called a(n) ____ loop.
Infinite
In ____ structures, the computer repeats particular statements a certain number of times depending on some condition(s).
Looping
Before using the data type string, the program must include the header file ____.
String
The ____ function is used to interchange the contents of two string variables.
Swap
The ____ rules of a programming language tell you which statements are legal, or accepted by the programming language.
Syntax
Main memory is directly connected to the CPU. True or False?
True
True or False All components of an array are of the same data type.
True
True or False Assume all variables are properly declared. The output of the following C++ code is 2 3 4 5. n = 1; while (n < 5) { n++; cout << n << " "; }
True
True or False Once you write and properly debug a function, you can use it in the program (or different programs) again and again without having to rewrite the same code repeatedly.
True
True or False Suppose a = 5. After the execution of the statement ++a; the value of a is 6.
True
True or False The extraction operator >> skips all leading blanks when searching for the next data in the input stream.
True
True or False The following is a legal C++ enumeration type: enum colorType {BLUE, GREEN, PINK, YELLOW, RED};
True
True or False? Information stored in main memory must be transferred to some other device for permanent storage.
True
True or False? The devices that feed data and programs into computers are called output devices.
True
Functions that do not have a return type are called ____ functions.
Void
What is a newline character?
\n
Suppose that alpha and beta are int variables and alpha = 5 and beta = 10. After the statement alpha *= beta; executes, ____.
alpha = 50
What is a reserved word in C++?
char
When you want to process only partial data, you can use the stream function ____ to discard a portion of the input.
ignore
Consider the following program segment. ifstream inFile; //Line 1 int x, y; //Line 2 ... //Line 3 inFile >> x >> y; //Line 4 Which of the statements at Line 3 can be used to open the file progdata.dat and input data from this file into x and y at Line 4?
inFile.open("progdata.dat");
The declaration int a, b, c; is equivalent to what?
int a,b,c;
What is a legal identifier?
program_1