CIS251 Midterm Wallace
What is an example of an invalid name for a memory location in C++?
2ndname
Which symbol is used in C++ for the logical And operator? a. && b. @ c. || d. %
a. &&
What is the value of the variable innerNum at the end of the execution of the following code? int outerNum; int innerNum; for (outerNum = 1; outerNum < 2; outerNum++) { for (innerNum = 1; innerNum < 2; innerNum++) cout << "innerNum: " << innerNum << endl; } a. 2 b. 4 c. 1 d. 3
a. 2
What value is stored in the letter variable after the following code is executed? char letter = 'a'; char letter2 = ' '; letter2 = toupper(letter); a. a b. A c. a blank space d. none of the above
a. a
What are the consequences of writing selection structures to include an unnecessary nested selection structure? a. more efficient code b. less efficient code c. always correct results d. always incorrect results
a. always correct results
Which of the following applications would require a nested repetition structure? a. clock b. egg timer c. thermometer d. weathervane
a. clock
In a for statement, which argument or arguments are required? a. condition b. initialization and update c. initialization d. initialization and condition
a. condition
What is used to terminate a counter-controlled loop? a. counter b. sentinel value c. updater d. boolean value
a. counter
Which of the following data types can contain a real number? a. float b. bool c. char d. int
a. float
The short data type can store a number in the range from -32,768 to +32,767. How many bytes of memory is required for the short data type? a. four b. one c. two d. eight
a. four
In a repetition structure, what is the requirement for repeating the instructions called? a. looping condition b. exit condition c. infinite loop d. sentinel value
a. looping condition
If the default clause is the last clause in a switch statement, what statement is required after the default clause? a. no statement is required b. a case statement c. an exit statement d. a break statement
a. no statement is required
What type of loop is often used in programs that allow the user to select from a menu? a. posttest b. for c. pretest d. while
a. posttest
What type of decision is always made by an outer selection structure? a. primary b. secondary c. alternative d. outer
a. primary
In a switch statement, what immediately follows the switch clause? a. selectorExpression b. case clause c. break clause d. alternativeExpression
a. selectorExpression
The data type of the value in a case clause within a switch statement must be compatible with the data type of which of the following? a. selectorExpression b. if statement c. else clause d. default Expression
a. selectorExpression
Which of the following is another name for a sentinel value? a. trip value b. priming value c. looping value d. exiting value
a. trip value
In a pretest loop, what should you include in the loop body to ensure that there is a way to enter the sentinel value after the loop body instructions are processed the first time? a. update read b. trailer value c. priming read d. trip value
a. update read
What is the result of the following arithmetic expression in C++? 2 + 4 * 2 a. 12 b. 10 c. 8 d. 16
b. 10
What is the output of the following code? int xNum = 0; int yNum = 0; do { xNum += yNum; } while (xNum == yNum++); cout << xNum; a. 0 b. 3 c. 1 d. 2
b. 3
Each case clause within a switch statement contains a value followed by which punctuation mark? a. semicolon b. colon c. comma d. period
b. colon
Which for clause is correct? a. for (int i = 1; i += 1) b. for (int i = 1; i < 10; i += 1) c. for (i < 10; int i = 1; i += 1) d. for (int i = 1)
b. for(int i = 1; i<10; i+=1)
Stream manipulators that do not have arguments, such as fixed and scientific, are defined in which file? a. namespace b. iomanip c. iostream d. none of the above
b. iostream
A secondary decision is always made by which selection structure? a. inner b. nested c. alternative d. single-alternative
b. nested
What can you do to stop an endless loop in a C++ program? a. type break b. press Ctrl+c c. type end d. press End
b. press Ctrl+c
A programmer determines whether a problem's solution requires a nested selection structure by studying which of the following? a. flow model b. problem specification c. data validation tables d. none of the above
b. problem specification
What type of objects are used in C++ to handle standard input and output operations? a. inout b. stream c. io d. data
b. stream
When a counter is incremented or decremented, what process is occurring to the variable? a. accumulating b. updating c. initializing d. counting
b. updating
What symbol is used in C++ for the modulus operator? a. & b. # c. % d. $
c. %
Which of the following would be a good sentinel value used in a loop that uses a miles per hour value as the looping condition? a. 1000 b. 0 c. -1 d. 100
c. -1
What is the binary equivalent of the decimal number 7? a. 1001 b. 1010 c. 0011 d. 0111
c. 0111
What would be the result of the following C++ code (assuming all necessary directives)? double number = 1234.567; cout << scientific << number << endl; a. 1234.567000 b. 1.234567e+03 c. 1234.567 d. 1234.6
c. 1.234567e+03
What is the output of the following code? int xNum = 0; int yNum = 0; do { for(yNum = 0; yNum < 3; yNum += 1) xNum += yNum; } while (xNum < 10); cout << xNum; a. 10 b. 13 c. 12 d. 11
c. 12
How many times will the instruction in the loop body of the following code be processed? int x = 0; do { x += 3; } while (x <= 3); a. 0 b. infinite c. 2 d. 1
c. 2!! i am not wrong
What is the decimal equivalent of the binary number 110? a. 8 b. 4 c. 6 d. 2
c. 6
AND and OR are the two most commonly used examples of which type of operator? a. relational b. comparison c. boolean d. assignment
c. boolean
What type of clause is needed in a switch statement if you want a block of code to be executed when there is no match with any of the case clauses? a. default b. if c. break d. else
c. break
What type of value is used to update a counter? a. floating point b. negative c. constant d. variable
c. constant
In regards to the repetition structure, which of the following is true? a. each case statement has a break statement b. every increment operation has a corresponding decrement operation c. every looping condition has an opposing loop exit condition d. every sentinel value has a corresponding initial value
c. every looping condition has an opposing loop exit condition
Which development component combines the object file with other machine code necessary for your C++ program to run correctly? a. source code b. object code c. linker d. IDE
c. linker
What is an item of data that can appear in a program instruction and can be stored in a memory location? a. variable b. named constant c. literal constant d. keyword
c. literal constant
Which character is used to separate each clause in a for statement? a. comma b. colon c. semicolon d. space
c. semicolon
What type of selection structure occurs when there are one or more actions to be taken only when its condition evaluates to true? a. dual-alternative b. if/else c. single-alternative d. conditional block
c. single-alternative
If there is no default clause in a switch statement and no match is found, what happens? a. the computer loops to the beginning of the switch statement b. the program execution is terminated c. the instruction after the closing brace is executed d. an error code is generated
c. the instruction after the closing brace is executed
What is used to tell the compiler where it can find the definitions of keywords and classes? a. IDE b. $keyword statement c. using directive d. linker
c. using directive
What would be the result of the following C++ code (assuming all necessary directives)? double number = 1234.567; cout << fixed << number << endl; a. 1235 b. 1234.567000 c. 1234.567 d. 1234.6
d. 1234.6
What would be the result of the following C++ code (assuming all necessary directives)? double number = 1234.56; cout << fixed; cout << setprecision(0); cout << number << endl; a. 1234.567000 b. 1234 c. 1234.6 d. 1235
d. 1235
What is the ASCII value of the '0' character? a. 0 b. 0.0 c. 66 d. 48
d. 48
Examine the following switch statement. What is needed to make a valid switch statement? switch { case 10: cout << "The answer is 10."; break; case 20: case 30: cout << "The answer is 20 or 30."; break; default: cout << "The answer is none of them."; break; case 40: cout << "The answer is 40."; } a. the default clause must be moved to the end b. a statement block is needed after the case 20: clause c. a break statement is needed after case 40: d. a selectorExpression is needed
d. a selectorExpression is needed
In C++, which file contains all of the machine code necessary to run a program as many times as desired without the need for translating the program again? a. source file b. executable file c. object file d. compiler
d. compiler
In a flowchart, what does a diamond that has more than two flow lines represent? a. optional selection structure b. dual-alternative selection structure c. single-alternative selection structure d. extended selection structure
d. extended selection structure
Which file must be included in any program that uses the cin or cout objects? a. namespace b. stream c. io d. iostream
d. iostream
Which of the following is a word that has a special meaning in the programming language you are using? a. variable b. named constant c. hashtag d. keyword
d. keyword
Which of the following is NOT a rule for naming a memory location in C++? a. the name must begin with a letter b. the name cannot contain spaces c. the name cannot be a keyword d. names in C++ are not case sensitive
d. names in C++ are not case sensitive
What is the result of the following code? int xNum = 0; int yNum = 0; do { xNum = xNum + yNum; yNum += 1; cout << "xNum: " << xNum; } while (xNum > 2); a. no output, the loop is never executed b. endless loop c. xNum: 2 is printed d. xNum: 0 is printed
d. xNum: 0 is printed
Selection structures that contain instructions on both the true and false paths are referred to as which of the following? a. single-alternative b. dual-alternative c. two path d. none of the above
dual-alternative
For a program to use the setprecision stream manipulator, it must include which file? ??????????????? a. b. c. d.
either iostream or namespace i guess???