Computer Science 1 Final Exam
The ________ directive causes the contents of another file to be inserted into a program.
#include
The expression 5 % 2 evaluates to
1
The expression 7 % 2 evaluates to
1
________ is an example of volatile memory, used for temporary storage while a program is running.
RAM
_______ must be included in a program in order to use the cout object.
The iostream header file
Characters or symbols that perform operations on one or more operands are
operators
When converting some algebraic expressions to C++, you may need to insert ________ and ________ that do not appear in the algebraic expression.
operators, parentheses
The term hardware refers to the
physical components that make up a computer.
#include is an example of a(n)
preprocessor directive
A(n) ________ is a set of instructions that tells the computer how to solve a problem.
program
Creating a program requires many steps. Three of these are
program design, writing source code, and testing.
The computer's main memory is commonly known as
random-access memory (RAM).
Operator associativity is either left to right or
right to left
A ________ is used to mark the end of a complete C++ programming statement.
semicolon
The ________ stream manipulator can be used to establish a field width for the value immediately following it.
setw
A C++ character literal is enclosed in ________ quotation marks, whereas a string literal is enclosed in ________ quotation marks.
single, double
The statements written by a programmer are called
source code
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.
Internally, the central processing unit (CPU) consists of two parts:
the arithmetic and logic unit (ALU) and the control unit.
The CPU includes
the arithmetic and logic unit (ALU) and the control unit.
When the final value of an expression is assigned to a variable, it will be converted to
the data type of the variable.
none
A trailing else placed at the end of an if/else if statement provides a default action when ________ of the if conditions is/are true.
flag
A(n) ________ is a variable, usually a bool, that signals when a condition exists.
Which of the following statements doubles the value stored in answer?
Both answer *= 2; and answer = answer * 2;, but not answer += 2;
Which of the following is/are valid C++ identifiers?
Both department_9 and aVeryLongVariableName , but not last-name.
Which of the following expressions will evaluate to 2.5?
Both static_cast<double>(5)/2 and 5/static_cast<double>(2), but not static_cast<double> (5/2)
________ can be used to override the rules of operator precedence.
Parentheses
True/False: Before a computer can execute a program written in a high level language, such as C++, it must be translated into object code.
True
True/False: C++ is a case-sensitive language.
True
all of these
Which of the following is an example of a secondary storage device?
In a C++ program, two slash marks ( // ) indicate the beginning of
a comment
Every C++ program must have
a function called main..
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.
An integrated development environment (IDE) normally includes
all of these
Which of the following definitions will allow the variable average to hold floating-point values?
all of these
In the C++ statement pay = rate * hours; the * symbol is an example of
an operator.
A variable must be defined
before it can be used.
A ________ variable can hold only one of two values: true or false.
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
Which of the following will cause the next output to begin on a new line?
cout << endl;
At the heart of a computer is its central processing unit (CPU). Its job is to
do all of these
Which of the following will allow an entire line of text to be read into a string object, even if it contains embedded blanks?
getline()
The bool data type
has only two values: true and false.
To use stream manipulators, you should include the ________ header file.
iomanip
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 programmer usually enters source code into a computer using
none of these
Which of the following statements will assign number a value from 90 — 100.
number = rand() % 11 + 90;
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.
C++ automatically places ________ at the end of a string literal.
the null terminator
The purpose of a memory address is
to identify the location of a memory cell.
Memory locations that can hold data are called
variables
The expression 5 / 2 evaluates to
2
The expression 7 / 2 evaluates to
3
What value will be assigned to the variable number by the following statement? int number = 3.75;
3
What does the following C++ expression evaluate to? 6 - 6 / 3 + 3
7
What value will be assigned to the variable number by the following statement? int number = 7.8;
7
What value will be assigned to the variable number by the following statement? int number = 7.8;
7
The ________ operator always follows the cin object, and the ________ operator follows the cout object.
>> , <<
Program code that can be evaluated to a value is called a(n).
Expression
If number is an int variable, both of the following statements will print out its value: cout << number; cout << "number";
False
True/False: A variable of the char data type can hold a set of characters like "January".
False
True/False: Executable code is computer code that contains no errors.
False
True/False: If a variable is defined as int sum; it may be written in the program code as sum or Sum, but not SUM.
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: Most modern computers can understand and execute pseudocode.
False
True/False: Once a value has been stored in a variable it cannot be changed.
False
True/False: The cin object lets the user enter a string that contains embedded blanks.
False
True/False: The following C++ statement will assign 1.5 to the result variable. int result = 3.0 / 2.0;
False
True/False: The following is a legal C++ statement to define and initialize a variable. char firstName = "Jack";
False
True/False: The following pair of C++ statements is legal. const double taxRate; taxRate = .05;
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 sets the value of total to -3. total -= 3;
False
True/False: The following two C++ statements perform the same operation. wages - regPay + overTIme; regPay + overTime = wages;
False
True/False: The following two statements both assign the value 5 to the variable dept. 5 = dept; dept = 5;
False
True/False: The purpose of the compiler is to convert object code into source code.
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
all of these.
High-level programming languages include
the iostream header file.
In any program that uses the cin object, you must #include
Which of the following is/are valid C++ identifiers?
June_2010
________ are data items whose values cannot change while the program is running.
Literals
True/False: Most of the lines in a program contain something meaningful; however, some of the lines may contain nothing at all.
True
True/False: Syntax involves rules that must be followed when writing a program.
True
True/False: The cin object can be used to input more than one value in a single statement.
True
True/False: The following two statements could be used interchangeably in a C++ program. // Program Payroll /* Program Payroll */
True
True/False: When an operator's operands are of different data types, such as int and double, C++ automatically converts one of them so that they are the same data type.
True
True
True/False: A pair of characters or a pair of string objects can be compared with any of the relational operators.
False
True/False: Assuming goodData is a Boolean variable, the following two tests are logically equivalent. if (goodData == false) if (!goodData)
False
True/False: In C++, the 5 basic arithmetic operators are addition ( +), subtraction ( -), multiplication ( *), division ( /), and exponentiation ( ^).
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
True/False: The rule for matching an else with an if is that an else goes with the last if statement before it that doesn't have its own else.
The ________ coordinates the computer's operations by fetching the next instruction and using control signals to regulate the other major computer components.
control unit
The ________ is used to display information on the computer's screen.
cout object
A variable definition always specifies the name of a variable and tells
what type of data it can hold.