COP 3014 Test 1
Software engineering is a field that encompasses designing, writing, testing, debugging, documenting, modifying, and maintaining computer programs.
True
The CPU is the most important component in a computer because without it, the computer could not run software.
True
The cin << statement will stop reading input when it encounters a newline character.
True
The only difference between the get function and the >> operator is that get reads the first character typed, even if it is a space, tab, or the [Enter] key.
True
The preprocessor reads a program before it is compiled and only executes those lines beginning with # symbol.
True
The term "bit" stands for binary digit.
True
When C++ is working with an operator, it strives to convert the operands to the same type.
True
When the fixed manipulator is used, the value specified by the setprecision manipulator will be the number of digits to appear after the decimal point.
True
When typing your source code into the computer, you should be careful since most of your C++ instructions, header files, and variable names are case sensitive.
True
You should be careful when using the equality operator to compare floating point values because of potential round-off errors.
True
An Integrated Development Environment (IDE) typically consists of
a text editor a compiler a debugger d. All of the above
Input values should always be checked for
an appropriate range reasonableness division by zero, if division is taking place d. All of these
Arithmetic operators that share the same precedence have right to left associativity.
False
Because C++ is case-sensitive, all programs must have a function called main or Main.
False
C++ 11 introduced an alternative way to define variables, using the template key word and an initialization value.
False
If you want to know the length of the string that is stored in a string object, you can call the object's size member function.
False
In C++ you are required to name your variables so they indicate the purpose they will be used for.
False
In C++, it is impossible to display the number 34.789 in a field of 9 spaces with 2 decimal places of precision.
False
In programming, the terms "line" and "statement" always mean the same thing.
False
Machine language is an example of a high-level language.
False
Programs are often referred to as hardware
False
Pseudocode is a form of a program statement that will always evaluate to "false."
False
The conditional operator takes two operands.
False
The default section is required in a switch statement.
False
The fixed manipulator causes a number to be displayed in scientific notation.
False
The following code correctly determines whether x contains a value in the range of 0 through 100, inclusive. if (x > 0 && <= 100)
False
The following statement will output $5.00 to the screen: cout << setprecision(5) << dollars << endl;
False
The preprocessor executes after the compiler.
False
The value of result in the following expression will be 0 if x has the value of 12. result = x > 100 ? 0 : 1;
False
When a program uses the setw manipulator, the iosetwidth header file must be included in a preprocessor directive.
False
At the heart of a computer is its central processing unit. The CPU's job is:
To fetch instructions To carry out the operations commanded by the instructions To produce some outcome or resultant information d. All of these
A CPU only understands machine language instructions.
True
A named constant is like a variable, but it its content cannot be changed while the program is running.
True
A value is stored in a variable with an assignment statement.
True
An expression that has any value other than 0 is considered true by an if statement.
True
As a rule of style, when writing an if statement you should indent the conditionally-executed statements.
True
Both of the following if statements perform the same operation. 1. if (sales > 10000) commissionRate = 0.15; 2. if (sales > 10000) commissionRate = 0.15;
True
C++ does not have a built-in data type for storing strings of data.
True
Escape sequences are always stored internally as a single character.
True
Floating point constants are normally stored in memory as doubles.
True
If the expression on the left side of the following is false, the expression on the right side will not be checked. (a > = b) && (c == d)
True
If the expression on the left side of the following is true, the expression on the right side will not be checked. (a > = b) || (c == d)
True
In C++, key words are written in all lowercase letters.
True
Programming style refers to the way a programmer uses elements such as identifiers, spaces, and blank lines.
True
Besides the decimal number system that is most common (base 10), two other number systems that can be used in C++ programs are
b. octal and hexadecimal
A computer monitor is a type of
b. output device
When a variable is assigned a number that is too large for its data type, it
b. overflows
The two methods used by C++ to write computer programs are:
b. procedural programming and object-oriented programming
This is used in a program to mark the beginning or ending of a statement, or separate items in a list:
b. punctuation
When a programmer saves to a file the statements he or she writes to create a program, these statements are
b. source code
This is a complete instruction that causes the computer to perform some action:
b. statement
In the following statement, the characters Hello! are a(n) cout << "Hello!";
b. string literal
If you place a semicolon after the statement: if (x < y)
b. the compiler will interpret the semicolon as a null statement
Which of the following must be included in any program that uses the cin object?
b. the header file iostream
Which of the following must be included in any program that uses the cout object?
b. the header file iostream
When C++ is working with an operator, it strives to convert operands to the same type. This is known as
b. type conversion
A(n) __________ represents a storage location in the computer's memory.
b. variable
You must have a _____________ for every variable you intend to use in a program.
b. variable definition
This operator represents the logical OR:
b. ||
A debugging process where you, the programmer, pretend you are a computer and step through each statement while recording the value of each variable at each step is known as
c. hand tracing
Which statement allows you to properly check the char variable code to determine whether it is equal to a C and then output This is a check?
c. if(code=='C') cout << "This is a check\n";
When a user types values at the keyboard, those values are first stored
c. in the keyboard buffer
Three primary activities of a program are:
c. input, processing, output
The numeric data types in C++ can be broken into two general categories which are
c. integers and floating-point numbers
Words that have a special meaning and may be used only for their intended purpose are known as
c. key words
This manipulator causes the field to be left justified with padding spaces printed to the right:
c. left
Associativity is either right to left or
c. left to right
Which of the following statements correctly assigns the character M to the variable named letter?
c. letter='M';
Assuming that a program has the following string object definition, which statement correctly assigns the string literal "Jane" to the string object?
c. name="Jane";
When an if statement is placed within the conditionally-executed code of another if statement, this is known as
c. nesting
In memory, C++ automatically places a(n) __________ at the end of string literals which __________.
c. null terminator, marks the end of the string
Characters or symbols that perform operations on one or more operands are:
c. operators
A statement that starts with a hashtag (or pound) symbol (#) is called a
c. preprocessor directive
A(n) __________ is a set of instructions that the computer follows to solve a problem.
c. program
Whereas < is called a relational operator, x < y is called a(n)
c. relational expression
A variable's __________ is the part of the program that has access to the variable.
c. scope
Programs are normally stored in __________ and loaded into main memory as needed.
c. secondary storage
This manipulator is used to establish a field width for the value that follows it:
c. setw
Character constants in C++ are always enclosed in
c. single quotation marks ( ' ' )
Computer programs are also known as
c. software
The two parts of the CPU are
c. the Control Unit and the Arithmetic and Logic Unit
When the final value of an expression is assigned to a variable, it will be converted to
c. the data type of the variable
A variable definition tells the computer
c. the variable's name and the type of data it will hold
The default section of a switch statement performs a similar task similar to the __________ portion of an if/else if statement.
c. trailing else
Which part of the following line is ignored by the compiler? double userName = "janedoe"; // user's name is janedoe
c. user's name is janedoe
This operator takes an operand and reverses its truth or falsehood:
d. !
Which of the following is evaluated first, given the expression: A && B || C && !D
d. !D
What is assigned to the variable result given the statement below with the following assumptions: x = 10, y = 7, and x, result, and y are all int variables. result = x >= y;
d. 1
Which of the following is not a valid C++ identifier?
d. 1user
The __________ decodes an instruction and generates an electronic signal.
d. Control Unit
In C++11, if you want an integer literal to be treated as a long long int, you can append __________ at the end of the number.
d. LL
In the process of translating a source file into an executable file, which of the following is the correct sequence?
d. Source code, preprocessor, modified source code, compiler, object code, linker, executable code.
What is the output of the following code segment? int x = 5; if (x = 2) cout << "This is true!" << endl; else cout << "This is false!" << endl; cout << "That's all, folks!" << endl;
d. This is true! That's all folks
Which data type typically requires only one byte of storage?
d. char
The first step in writing a program is to
d. clearly define what the program is to do
For every opening brace ({) in a C++ program, there must be a
d. closing brace
The function pow(x, y), requires which header file?
d. cmath
If you intend to place a block of statements within an if statement, you must place __________ around the block:
d. curly braces { }
A character literal is __________, whereas a string literal is __________
d. enclosed in single quotation marks, enclosed in double quotation marks
A variable, usually a bool or an int, that signals when a condition exists is known as a(n)
d. flag
Which of the following statements will read an entire line of input into the string object, address?
d. getline(cin, address);
A model often used when creating a program that begins with the overall task and refines it into smaller subtasks is a(n)
d. hierarchy chart
Which of the following is not a common input device?
d. printer
Given the following code segment, what is the output? intx=1,y =1,z=1; y = y + z; x = x + y; cout << "result = " << (x < y ? y : x) << endl;
d. result = 3
Which of the following functions will return the value of x, rounded to the nearest whole number?
d. round(x)
Which of the following expressions will determine whether x is less than or equal to y?
d. x<=y
What is the value of cookies after the following statements execute? int number = 38, children = 4, cookies; cookies = number % children;
a. 2
What is the value stored in the variable myNum after the following assignment statement executes? myNum = 23 % 5
a. 3
How many characters will the following statement read into the variable myString? cin >> setw(10) >> myString;
a. 9
The __________ is an equality (or comparison) operator
a. ==
What is true about the following statement? cout << setw(4) << num4 << " ";
a. It allows four spaces for the value in num4.
Given the if/else statement: if (a < 5) b = 12; else d = 30;
a. a<5?b=12:d=30;
Without this statement appearing in a switch construct, the program "falls through" all of the statements below the one with the matching case expression.
a. break
Which of the following functions tells the cin object to skip one or more characters in the keyboard buffer?
a. cin.ignore
To use the rand()function, you must include the __________ header file?
a. cstdlib
In a cout statement, which of the following will advance the output position to the beginning of the next line?
a. endl or \n
The CPU's control unit retrieves the next instruction in a sequence of program instructions from main memory in the __________ stage.
a. fetch
A computer stores a program while it is running
a. in main memory
When a program lets the user know that an invalid choice has been made, this is known as:
a. input validation
Select all that apply. Using C++11: Which of the following can be used to initialize an integer variable named dozen with the value of 12?
a. intdozen=12; b. int dozen(12); e. int dozen{12};
Data items whose values do not change while the program is running are
a. literals
Which statement is equivalent to the following? number += 1;
a. number = number + 1;
You can control the number of significant digits in your output with the __________ manipulator.
a. setprecision
The float data type is considered ___________ precision and the double data type is considered __________ precision.
a. single, double
This statement uses the value of a variable or expression to determine where the program will branch to.
a. switch
This is a set of rules that must be followed when constructing a program:
a. syntax
Which of the following is not one of the major components of a computer system?
a. the preprocessor
A variable definition defines the name of a variable that will be used in a program, as well as:
a. the type of data it will be used to hold
The purpose of a memory address is:
a. to identify the location of a byte in memory
What is the value of the following expression? true && !false
a. true
What is the value of the following expression? true && true
a. true
What is the value of the following expression? true || false
a. true
A named storage location in the computer's memory that holds a piece of information is a(n):
a. variable
What is the value of x after the following code executes? int x; x = 3 / static_cast<int>(4.5 + 6.4);
b. 0
When a relational expression is false, it has the value
b. 0
What is output of the following statement? cout << 4 * (15 / (1 + 3)) << endl;
b. 12
What is the value of number after the following statements execute? int number; number = 18 % 4 + 2;
b. 4
What is the value of number after the following statements execute? int number; number = 18 / 4;
b. 4
Which of the following best describes an operator?
b. An operator allows you to perform operations on one or more pieces of data.
What is the output of the following code segment if the user enters 23? int number; cout << "Enter a number: "; cin >> number; if (number > 0) cout << "Hi, there!" << endl; else cout << "Good-bye." << endl;
b. Hi, there!
In a C++ program, two slash marks (//) indicate
b. The beginning of a comment
Select all that apply. Which of the following statements is(are) true about named constants?
b. The content of a named constant is read-only. c. The value of a named constant cannot be changed while the program is running. d. A named constant is defined using the const qualifier.
What does the term hardware refer to?
b. The physical components that make up a computer
The programmer usually enters source code into a computer with
b. a text editor
A set of well-defined steps for performing a task or solving a problem is known as a(n):
b. algorithm
The __________ causes a program to wait until information is typed at the keyboard and the [Enter] key is pressed.
b. cin object
Which step uncovers any syntax errors in your program?
b. compiling
During which stage does the central processing unit analyze the instruction and encode it in the form of a number, and then generate an electronic signal?
b. decode
The programming process consists of several steps, which include:
b. design, creation, testing, debugging
Using C++11: What data type does the compiler determine for the variable cost in the following statement? auto cost = 14.95;
b. double
Which of the following defines a double-precision floating-point variable named payCheck?
b. double payCheck;
After the following code executes, what is the output if user enters 0? int x = -1; cout << "Enter a 0 or 1: "; cin >> x; if (c) cout << "true" << endl; else cout << "false" << endl;
b. false
What is the value of the following expression? true && false
b. false
Every complete C++ program must have a
b. function named main
__________ reads a line of input, including leading and embedded spaces, and stores it in a string object.
b. getline
Mistakes that cause a running program to produce incorrect results are called:
b. logic errors
These operators connect two or more relational expressions into one, or reverse the logic of an expression.
b. logical
Which statement is equivalent to the following? number = number * 2;
b. number *= 2;
A multi-line comment
begins with /* and ends with */ can be used to mark as many lines as desired as comments allows everything in the selected lines to be ignored d. All of these are true
Which of the following lines must be included in a program that has string variables?
c. #include <string>
The __________ causes the content of another file to be inserted into a program.
c. #include directive
This operator represents the logical AND:
c. &&
What is the value of cube after the following code executes? double cube, side; side = 5.0; cube = pow(side, 3.0);
c. 125.0
What is the value of number after the following statements execute? int number = 10; number += 5; number -= 2; number *= 3;
c. 39
The __________ operator always follows the cin object, and the __________ operator follows the cout object.
c. >>, <<
A volatile type of memory that is used for temporary storage is
c. RAM
What will be displayed after the following statements execute? int num1 = 5; int num2 = 3; cout << "The result is " << (num1 * num2 + 10) << endl;
c. The result is 25
What will be the output after the following lines of code execute? bool choice; choice = true; cout << "Your choice is " << choice << endl;
c. Your choice is 1
Which control sequence is used to skip over to the next horizontal tab stop?
c. \t
The data type of a variable whose value can be either true or false is
c. bool
Which of the following will allow the user to input the values 15 and 20 and have them stored in variables named base and height, respectively?
c. cin >> base >> height;
Which of the following statements will pause the screen until the [Enter] key is pressed?
c. cin.get();
Which of the following statements will allow the user to enter three values to be stored in variables length, width, and height, in that order?
c. cin.get(length,width,height);
Relational operators allow you to __________ numbers.
c. compare
________ are used to translate each source code instruction into the appropriate machine language instruction.
c. compilers
Which of the following statements correctly defines a named constant named TAX_RATE that holds the value 0.075?
c. const double TAX_RATE = 0.075;
The __________ is(are) used to display information on the computer's screen.
c. cout object
The term that refers to the programmer reading the program from the beginning and stepping through each statement is
c. desk checking
This manipulator forces cout to print digits in fixed-point notation:
c. fixed
The data type used to declare variables that can hold real numbers is
c. float