SCMP 118
Indexes are numberes starting at ______.
0. The correct answer is: 0
Consider the array declaration below: double a[10]; How many double values can array a store? Answer:
10 The correct answer is: 10
What is the value of (pow(2,sqrt(9.0)+ceil(0.99)))? Answer: ________________
16 The correct answer is: 16
What output is produced by the following code, when embedded in a complete program? int number = 22; { int number = 42; cout << number; } cout << number; Answer:
42 22 The correct answer is: 4222
Arrays can be passed to functions. Select one: True False
True The correct answer is 'True'.
A semicolon by itself is a valid C++ statement. Select one: True False
True The correct answer is 'True'.
After execution of the code int x = 3; the variable x has the value 3. Select one: True False
True The correct answer is 'True'.
The body of a do-while loop always executes at least once. Select one: True False
True The correct answer is 'True'.
cout << "My name is Georgia.\n"; is a legal C++ statement. Select one: True False
True The correct answer is 'True'.
Recursive functions may return any type of value Select one: True False
True. The correct answer is 'True'.
A _________ expression is an expression that can be thought of as being true or false.
Logical (Boolean??) The correct answer is: logical
Consider the array declarition below: int myArray[9]={1,2,3,6,5,4,7,1,2}; What is the index that will access number 7 in the array? Select one: a. 2 b. 7 c. 8 d. 6 e. 5
The correct answer is: 6
Give a C++ statement that will change the value of the variable sum to the sum of the values in the variables n1 and n2. The variables are all of type int. Select one: a. sum = n1 + n2; b. sum = add(n1, n2); c. n1 + n2 = sum; d. sum(n1, n2); e. (assign (sum (+ n1 n2)))
a. In an assignment statement, first the expression on the right-hand side of the equal sign is evaluated, and then the variable on the left-hand side of the equal sign is set equal to this value. SYNTAX Variable = Expression; EXAMPLES distance = rate * time; count = count + 2; The correct answer is: sum = n1 + n2;
If you want a loop to quit iterating if x < 10 and y > 3, what would be the proper loop condition test? Select one: a. (x >=10 || y <=3) b. (x < 10 && y > 3) c. (x >10 || y < 3) d. (x >=10 && y <=3)
a. The correct answer is: (x >=10 || y <=3)
What is the output of the following program fragment? cout << pow(4,2) << endl; Select one: a. 16 b. 8 c. 4 d. 2
a. The correct answer is: 16
In the array referance below, which part is the index? result = grades[7] * 10; Select one: a. 7 is the index b. 10 is the index c. result is the index d. Grades is the index. e. There is no index in this example.
a. The correct answer is: 7 is the index
What is the differance between the == and = operators? Select one: a. The = operator is for value assignment, and the == is for value comparison. b. The == and the = operators are identical in function, and may be used interchangably. c. The == operator is for value assignment, and the = is for value comparison. d. The == is used for comparing numbers, while = is used for comparing strings. e. The == operator tests for exact value match, while = tests for "near" value match.
a. The correct answer is: The = operator is for value assignment, and the == is for value comparison.
The postcondition of a function Select one: a. tells what will be true after the function executes. b. declares the function for the compiler. c. tells what must be true before the function executes. d. determines how the function will complete its job.
a. The correct answer is: tells what will be true after the function executes.
Which of the following is a valid identifier? Select one: a. three_com b. 3-com c. 3_com d. 3com
a. The correct answer is: three_com
What is wrong with the following code? double scores[10], total; Select one: a. Nothing is wrong with the code. b. The 10 should be replaced with a variable name (such as size) whose value would be input by the user. c. Arrays must be made of up integers. d. You may not declare array and regular variables together.
a. The correct answer is: Nothing is wrong with the code.
What is the output of the following code? cout << "This is a \\" << endl; Select one: a. This is a \ b. This is a endl c. This is a d. Nothing. It is a syntax error.
a. The correct answer is: This is a \
Which of the following is true about vectors in C++. Select one or more: a. They serve the same purpose as arrays. b. They can grow in length as the program runs. c. They can be used to make arrays of other types (int, long, char, etc) d. They can shrink in length as the program runs.
all correct The correct answers are: They can grow in length as the program runs., They can shrink in length as the program runs., They serve the same purpose as arrays., They can be used to make arrays of other types (int, long, char, etc)
Select ALL of the ways to create an integer variable num, and initialize it to 12. Select one or more: a. num(12) int; b. int num(12); c. int num <- 12; d. int num = 12; e. int(12) num;
b, d. The correct answers are: int num = 12;, int num(12);
Suppose you have two function definitions with the following function declarations: double the_answer(double data1, double data2); double the_answer(double time, int count); Which function definition would be used in the following function call? (x and y are of type double.) x = the_answer(y, 6.0); Select one: a. Both b. double the_answer(double data1, double data2); c. double the_answer(double time, int count); d. The selection is random e. Neither
b. The correct answer is: double the_answer(double data1, double data2);
What is the value of str after the following code? string str; Select one: a. length(str) b. str.length() c. str.getLength() d. getLength(str)
b. The correct answer is: str.length()
What is the value returned by the following function? int function() { int value = 35; return value + 5; value += 10; } Select one: a. 35 b. 40 c. 50 d. 10
b. The correct answer is: 40
Given the following code, what is the final value of i? int i; for(i=0; i<=4;i++) { cout << i << endl; } Select one: a. 4 b. 5 c. 0 d. 3
b. The correct answer is: 5
Every time a recursive function call is executed, a new __________ is put on the top of the stack. Select one: a. Activity frame b. Activation frame c. program d. Activity record
b. The correct answer is: Activation frame
What is the purpose of the ! operator in C++. Select one: a. It is the exponent operator b. It is the not operator c. It is not legal in C++ d. It is the and operator.
b. The correct answer is: It is the not operator
Which of the following is true for a void function? Select one: a. The value of 0 should be returned. b. Nothing is returned. c. The value of void should be returned. d. There cannot be a return statement.
b. The correct answer is: Nothing is returned.
What happens if you try to assess a element beyond the end of a vector using square brackets? Select one: a. The size of the vector is automatically increased. b. Something bad, it depends on the compiler and the library.
b. The correct answer is: Something bad, it depends on the compiler and the library.
Which of the following is not a good reason for choosing a particular loop control? Select one: a. The purpose of the loop b. Whether the loop is inside a function c. The ending condition for the loop d. The number of times the loop should execute
b. The correct answer is: Whether the loop is inside a function
The following is an example of: int getRandomNumber() { return 4; // chosen for a dice roll. // guaranteed to be random } Select one: a. an abstraction b. a stub c. a black box d. a driver
b. The correct answer is: a stub
Which of the following function prototypes are not valid? Select one: a. all are not valid b. all are valid c. void doSomething(int& x, int y); d. void doSomething( int x, int y); e. void doSomething( int& x, int& y);
b. The correct answer is: all are valid
Multiple arguments to a function are separated by Select one: a. semicolons b. commas c. colons d. comments e. periods
b. The correct answer is: commas
Which loop structure always executes at least once? Select one: a. sentinel b. do-while c. while d. for
b. The correct answer is: do-while
The expression static_cast<double>(3) is called a Select one: a. multiplier b. type cast c. polymorphism d. doubler
b. The correct answer is: type cast
A definition that defines a concept or a formula in terms of the concept or formula is called Select one: a. reduction b. a recursive definition c. indecision d. iteration
b. The correct answers are: a recursive definition
Which of the following are used to create a loop in C++ (select ALL that apply) Select one or more: a. if b. break c. while d. do while e. for
c, d, e. The correct answers are: for, while, do while
Which of the following is a valid identifier? Select one: a. 3com b. dollar$ c. three_com d. 3-com e. 3_com
c. Identifiers are used as names for variables and other items in a C++ program. An identifier must start with either a letter or the underscore symbol, and the remaining characters must all be letters, digits, or the underscore symbol. The correct answer is: three_com
What is the output of the following code? float value; value = 33.5; cout << "value" << endl; Select one: a. 33 b. garbage c. value d. 33.5
c. If something is in quotes, the literal characters are used, not the value of a variable. The correct answer is: value
If you want to read into a c-string, you must ensure that the user does not enter more characters than Select one: a. The size of the c-string + 1 b. It doesn't matter. c. The size of the c-string -1 d. The size of the c-string
c. The correct answer is: The size of the c-string -1
Using functions in a program is known as Select one: a. poor programming style b. data abstraction c. procedural abstraction d. calculus
c. The correct answer is: procedural abstraction
How many times is Kenyon printed to the screen? for (int i = 0; i < 14; i++); cout << "Kenyon" << endl; Select one: a. 14 b. 15 c. 1 d. 13 e. 0
c. The correct answer is: 1
When overloading a function, which of the following must be true? Select one: a. The names should be the same with the same number and/or types of parameters. b. The names should be different with different numbers and/or types of parameters. c. The names should be different with the same number and/or types of parameters. d. The names should be the same with different numbers and/or types of parameters.
c. The correct answer is: The names should be the same with different numbers and/or types of parameters.
When a void function is called, it is known as: Select one: a. a comment b. a returned value c. an executable statement d. an output function
c. The correct answer is: an executable statement
Which boolean operation is described by the following table? A B Operation True True True True False False False True False False False False Select one: a. not b. or c. and d. maybe
c. The correct answer is: and
Given that the integer variable x has been declared and given a value of 5 prior to this code being executed, what is the output of the following code? if (x<3) { cout << "small"; } else { if (x<4) { cout << "medium"; } else { if (x<6) { cout << "large"; } else { cout << "giant"; } } } Select one: a. giant b. medium c. large d. no output e. small
c. The correct answer is: large
When the address of the actual argument is passed to the formal parameter, this is called ____________.
call-by-reference The correct answer is: call-by-reference
What is the output of the following (when embedded in a complete program)? int n = 5; while (--n > 0) { if (n == 2) break; cout << n << " "; } cout << "End of Loop"; Select one: a. 5 4 3 2 1 End of Loop b. 4 3 2 1 End of Loop c. 4 3 1 End of Loop d. 4 3 End of Loop e. 5 4 3 2 1 0 End of Loop
d. The correct answer is: 4 3 End of Loop
Given the following function definition: int trial(int &a, int b) { if (b > a) { a = b; return -a; } else { return 0; } } What is the output of the following code fragment? int x = 0, y = 5, z; z = trial(y, x); cout << z << ' ' << x << ' ' << y << endl; Select one: a. -5 0 0 b. 0 5 0 c. 5 0 0 d. 0 0 5
d. The correct answer is: 0 0 5
What is the output of the following code fragment? cout << static_cast <double>(3)/4 << endl; Select one: a. 3 b. 0 c. Nothing at all d. 0.75
d. The correct answer is: 0.75
Which of the following is a reason it might be a good idea to use a named constant in declaring the size of an array? Select one: a. Readability of the code b. Makes changing the program easier c. Helps reduce logic errors d. All of the above
d. The correct answer is: All of the above
You specify an individual member of a struct by using Select one: a. an ampersand b. an underscore c. the assignment operator d. The dot operator
d. The correct answer is: The dot operator
What does the following code print to the screen? cout << "hello"; Select one: a. nothing b. hello; c. "hello" d. hello
d. The correct answer is: hello
What is the value of x after the following code fragment executes? float x = 36.0; Select one: a. 6.0 b. 2.456 c. 3.0 d. 36.0
d. The correct answers are: 36.0
What is the output of the final line of the following code fragment? int x = 0; while (x < 5) { cout << x << endl; x++; } cout << x << endl; Select one: a. Impossible to determine b. 0 c. 4 d. 5
d. The correct answer is: 5
A loop that always executes the loop body at least once is known as a ________________ loop.
do while The correct answer is: do while
If we want to test if a given function works correctly, we would write a _________ to test it.
driver The correct answer is: Driver
What is the output of the following (when embedded in a complete program)? for (int n = 10; n > 0; n = n − 2) { cout << "Hello "; cout << n << endl; } Select one: a. Nothing b. Hello 10 Hello 8 Hello 6 Hello 4 c. Hello 8 Hello 6 Hello 4 Hello 2 d. Hello 10 Hello 9 Hello 8 Hello 7 Hello 6 Hello 5 Hello 4 Hello 3 Hello 2 Hello 1 e. Hello 10 Hello 8 Hello 6 Hello 4 Hello 2
e. The correct answer is: Hello 10 Hello 8 Hello 6 Hello 4 Hello 2
Multiple arguments to a function should be separated by Select one: a. semi-colons b. comments c. colons d. periods e. commas
e. The correct answer is: commas
Which of the following data types can be used in the controlling expression of a switch statement? Select one: a. int b. double c. char d. (a) and (b) e. (a) and (c) f. All of the above
e. The correct answer is: (a) and (c)
A mistake in a computer program is called a(n) Answer: ______________
error The correct answer is: Bug
Declared constants that might be used in different functions should be declared as _____________.
global The correct answer is: Global
In the expression cout << score[i] << endl; i is called the
index The correct answer is: index
if-else statements that are inside other if-else statements are said to be _________.
nested The correct answer is: nested
What type of value does a void function return? Answer: ___________
none The correct answer is: void ?????????
The character '\0' is called the ___________ character
null The correct answer is: null
All nested if-else statements can be converted into switch statements. Select one: True False
False The correct answer is 'False'.
In a function with call-by-reference parameters, it is the values of the arguments which are passed to the function. Select one: True False
False The correct answer is 'False'.
It is illegal to call other functions from inside a function definition. Select one: True False
False The correct answer is 'False'.
The indexed variables (members) of an array must be integers. Select one: True False
False The correct answer is 'False'.
pow(2, 3) is the same as pow(3, 2). Select one: True False
False The correct answer is 'False'.
Loops are used when we need our program to make a choice between two or more things. Select one: True False
False The correct answer is 'False'.
The parameters listed in a function declaration are considered global variables. Select one: True False
False The correct answer is 'False'.
There are 8 bytes in 1 bit. Select one: True False
False The correct answer is 'False'.
The part of the computer that controls and executes programs is called the ___________________.
CPU The correct answer is: CPU
The __________ of a function determines how a particular function will work.
Definition The correct answer is: definition
