Cs131 Midterm
What does the following C++ expression evaluate to? 6 - 6 / 3 + 3
7
The ________ operator is used in C++ to test for equality.
==
a variable is?
A storage location in the computer's memory that can hold a piece of data
The following 4 lines of C++ code, use strings. string firstName; // Define a string object char lastName[7]; // Define a C-string firstName = "Abraham"; // Assign a value to the string object lastName = "Lincoln"; // Assign a value to the C-string
A. The 2 string definitions are correct, but the 2 assignment statements are wrong. B. The string object is defined incorrectly because no size is given for it. C. The C-string is assigned a value correctly, but the string object is not. D. All 4 lines of code are correct. Answer The string object is assigned a value correctly, but the C-string is not.
Two different variables in the same program may have the same name
A. if the second one is never declared. B. if they always hold different values. C. if the second one is initialized with a different value than the first one. D. never. A program cannot have two variables with the same name. Answer if they have different scope.
The statement cout << setw(4) << num4 << " ";
A. outputs the value of num4 rounded to 4 decimal places. B. outputs the first 4 digits of the number stored in num4. C. outputs "setw(4)" before the value in the variable num4. D. outputs the value stored in num4 four times. Answer does none of above.
Which of the following statements about named constants is/are true?
A.The initial value of a named constant, cannot be changed during the program execution. B.The identifier name of a named constant can only contain capital letters and underscores. C. A named constant must be initialized with a value at the time it is declared. Answer Statements A and C are true, but B is not.
If s1 and s2 are string objects, s1 == s2 is true when
A.s1 = "dog" and s2 = "DOG". B.s1 = "cat" and s2 = "cat ". C. s1 = "lion" and s2 = "lioness". D. None of these because string objects cannot be compared with relational operators. Answer None of these because in each case one or more characters in the strings have different ASCII codes.
A software package that includes a text editor, compiler, debugger, and assorted utilities for creating, testing, and running software is called
Aa software utility package (SUP). B. a low-level programming language. C. an operating system. D. a high-level programming language. Answer none of the above.
What will the following statement do if x equals 17 and answer = 20? answer = x > 100 ? 0 : 1;
Assign 1 to answer.
High-level programming languages include
C++ and JavaScript. C++ and Java. C++ and Visual Basic.
________ is an example of volatile memory, used for temporary storage while a program is running.
RAM
Which of the following is an example of a secondary storage device?
a hard disk drive a DVD a USB flash drive a CD
Even when there is no power to the computer, data can be held in
a secondary storage device.
A storage location in the computer's memory that can hold a piece of data is called
a variable.
In the C++ statement pay = rate * hours; the * symbol is an example of
an operator.
A flag is a variable, usually of data type ________, that signals whether or not some condition exists.
bool
The ________ object causes data to be input from the keyboard.
cin
To use the sqrt() function, or other mathematical library functions, you must #include the ________ header file in your program.
cmath
True/False: A switch statement branches to a particular block of code depending on the value of a numeric (i.e. integer or floating-point) variable or constant.
false
True/False: Executable code is computer code that contains no errors.
false
True/False: If the sub-expression on the left side of an && operator is true, the expression on the right side will not be checked.
false
True/False: If the value of dollars is 5.0, the following statement will output 5.00 to the monitor: cout << fixed << showpoint << setprecision(4) << dollars << endl;
false
True/False: In C++, the 5 basic arithmetic operators are addition (+), subtraction (-), multiplication (*), division (/), and exponentiation (^).
false
True/False: Most modern computers can understand and execute pseudocode.
false
True/False: Relational operators connect two or more relational expressions into one, or reverse the logic of an expression.
false
True/False: The cin object lets the user enter a string that contains embedded blanks.
false
True/False: The following C++ test checks if the variable child is in the range 3-12. if (child >= 3 && <= 12)
false
True/False: The following pair of C++ statements will cause 3.5 to be output. double number = 7 / 2; cout << number;
false
True/False: The following statement s will not print anything. x = 5; if (x < 5) cout << "Hello "; cout << "world \n";
false
True/False: The following statement sets the value of total to -3. total -= 3;
false
True/False: The setw manipulator is used to set the precision of a number.
false
True/False: When a C++ expression is evaluated, binary operations are performed before unary operations.
false
True/False: When an operator has two operands of different data types, C++ always converts them both to double before performing the operation.
false
The ________ statement executes one statement, or block of statements, if a condition is true and skips it, doing nothing, if the condition is false.
if
The ________ statement acts like a chain of if statements. Each performs its test, one after the other, until one of them is found to be true.
if/else if
When a program lets the user know that an invalid menu choice has been made, this is an example of
input validation.
Three primary activities of a typical program are
input, processing, and output.
IDE stands for
integrated development environment.
Words with a special meaning that may be used only for their intended purpose are known as
keywords.
Mistakes that allow a program to run, but cause it to produce erroneous results are called
logic errors.
The cin object must be followed by
one or more stream extraction (>>) operators.
When an arithmetic expression contains two or more different operators, such as * and +, the order in which the operations is done is determined by
operator precedence.
When converting some algebraic expressions to C++, you may need to insert ________ and ________ that do not appear in the algebraic expression.
operators, parentheses
The expression x < y is called a(n) ________ expression.
relational
Operator associativity is either left to right or
right to left.
A ________ is a complete instruction that causes the computer to perform some action.
statement
The programs that control and manage the basic operations of a computer are generally referred to as
system software.
A software package that includes a text editor, compiler, debugger, and assorted utilities for creating, testing, and running software is called
the answer will be none of the above
The programmer usually enters source code into a computer using
the answer will be none of the above
Internally, the central processing unit (CPU) consists of two parts:
the arithmetic and logic unit (ALU) and the control unit.
The default section of a switch statement performs a similar task as the ________ portion of an if/else if statement.
trailing else
True/False: Assuming moreData is a Boolean variable, the following two tests are logically equivalent. if (moreData == true) if (moreData)
true
True/False: If a new value is stored in a variable, it replaces whatever value was previously there.
true
True/False: In C++ an expression that evaluates to 5, -5, or for that matter anything other than 0, is considered true by an if statement.
true
True/False: Relational expressions and logical expressions are both Boolean, which means they evaluate to true or false.
true
True/False: Syntax involves rules that must be followed when writing a program.
true
True/False: The following statement sets sum1, sum2, and sum3 all to zero. sum1 = sum2 = sum3 = 0;
true
True/False: The following two expressions evaluate to the same thing: c + a * b c + (a * b)
true
What will the following expression evaluate to? !( 6 > 7 || 3 == 4)
true
A variable definition always specifies the name of a variable and tells
what type of data it can hold.
The ________ operator is known as the logical OR operator.
||