Intro to Programming Midterm
These are used to declare variables that can hold real numbers
Floating point data types
In programming terms, a group of characters inside a set of quotation marks is called a:
String literal
In a C++ program, two slash marks ( // ) indicate:
The beginning of a comment
Internally, the CPU consists of two parts:
The control unit and the Arithmetic and Logic unit
_____________ represent storage locations in the computer's memory
Variables
Which of the following is not one of the five major components of a computer system?
preprocessor
computer programs are also known as
software
The purpose of a memory address is:
to identify the location of a byte in memory
What will the following code display? cout << "Four\n" << "score\n"; cout << "and" << "\nseven"; cout << "\nyears" << " ago" << endl;
Four score and seven years ago
What will the following code display? cout << "Four " << "score "; cout << "and " << "seven/n"; cout << "years" << "ago" << endl;
Four score and seven/nyearsago
Besides decimal, two other number systems you might encounter in C++ programs are
Hexadecimal and Octal
The _____ causes the contents of another file to be inserted into a program
#include directive
What is the modulus operator?
%
sizeof
'single quotation marks'
You can use these to override the rules of operator precedence in mathematical expression
(Parentheses)
Assume that x is an int variable. What value is assigned to x after the following assignment is executed? x =-3+4 % 6/5;
-3
Which line in the following program will cause a compiler error? 1- #include <iostream> 2-using namespcae std; 3- 4-int main() 5-{ 6- const int MY_VAL=77; 7-MY_VAL=99; 8-cout <<MY_VAL <<endl; 9-return 0; 10-}
7
Assuming you are using a system with 1-byte characters, how many bytes of memory will the following string literal occupy? "William"
8
How many characters does the string, "John Doe" require so it can be stored in memory properly?
9
A character literal is enclosed in ________ quotation marks, whereas a string literal is enclosed in ________ quotation marks.
single, double
The float data type is considered _____ precision, and the double data type is considered _______ precision
single, double
This function in C++ allows you to identify how many bytes of storage on your computer system an integer data value requires.
sizeof
The statements written by the programmer are called:
source code
This is a complete instruction that causes the computer to perform some action
statement
This may be used to write information to a file
stream insertion operator
When the final value of an expression is assigned to a variable, it will be converted to:
The data type of the variable
____________ must be included in any program that uses the cout object.
The header file iostream
What will the following code display? int number = 7; cout << "The number is " << "number" << endl;
The number is number
What does the term hardware refer to?
The physical components that a computer is made of
During which stage does the central processing unit retrieve from main memory the next instruction in the sequence of program instructions?
fetch
This stream manipulator forces cout to print the digits in fixed-point notation.
fixed
To allow file access in program, you must #include this header file
fstream
scope
function named main
Three primary activities of a program are:
input, processing, and output
How would you consolidate the following declaration statements into one statement? int x = 7; int y = 16; int z = 28;
int x = 7, y = 16, z = 28;
The numeric data types in C++ can be broken into two general categories:
integer and floating point
In any program that uses the cin object, you must include the ___
iostream header file
Words that have special meaning and may be used only for their intended purpose are known as:
key words
This manipulator causes the field to be left-justified with padding spaces printed to the right
left
Assume that a program has the following variable definition: char letter;
letter = 'Z';
Mistakes that cause running program to produce incorrect results are called:
logic errors
In a broad sense, the two primary categories of programming languages are:
low-level and high-level
Unix and Windows 2000 are examples of _______________ operating systems
multi-tasking
If you use a C++ key word as an identifier, your program will:
not compile
Which statements is equivalent to the following? number+=1;
number= number +1;
To write data to a file, you define an object of this data type
ofstream
A file must be___before data can be written to or read from it
opened
Characters or symbols that perform operations on one or more operands are:
operators
Assuming outFile is a file stream object and number is a variable, which statement writes the contents of number to the file associated with outFile?
outFile<<number;
When a variable is assigned a number that is too large for its data type, it:
overflows
When converting some algebraic expressions to C++, you many need to insert____that do not appear in the algebraic expression
parentheses
A statement that starts with a # is called a:
preprocessor directive
This is used in a program to mark the beginning or ending of a statement, or separate items in a list
punctuation
A variable's ___________ is the part of the program that has access to the variable
scope
Even when there is no power to the computer, data can be held:
secondary storage
This manipulator is used to establish a field width for the value immediately following it.
setw
Which of the following is a preprocessor directive
#include <iostream>
What is the value stored at x, given the statements: intx; x=3 / static_cast<int>(4.5+6.4);
0
What will the following code display? int x = 0, y = 1, z = 2; cout << x << y << z << endl;
012
What is the output of the following statement? cout << 4 * (15 / (1 + 3)) << endl;
12
What will the value of x be after the following statements execute? int x = 0; int y = 5; int z = 4; x = y + z * 2;
13
Look at the following program and answer the question that follows it. 1 // This program displays my gross wages. 2 // I worked 40 hours and I make $20.00 per hour. 3 #include <iostream> 4 using namespace std; 5 6 int main() 7 { 8 int hours; 9 double payRate, grossPay; 10 11 hours = 40; 12 payRate = 20.0; 13 grossPay = hours * payRate; 14 cout << "My gross pay is $" << grossPay << endl; 15 return 0; 16 } Which line(s) in this program cause output to be displayed on the screen?
14
What is the value of number after the following statements execute? int number= 10; number+=5; number-=2; number*=3;
15
The ___operator always follows the cin object, and the ___ operator follows the cout object
>>,<<
Which of the following best describes an operator?
An operator is a rule that must be followed when constructing a program
In the following C++ statements, what will be executed first according to the order of precedence. result= 6-3*2+7-10/2:
3*2
Which one of the following would be an illegal variable name?
3dGraph
What will the value of x be after the following statements execute? int x; x = 18 / 4;
4
What is the value of average after the following code executes? double average; average=1.0+2.0+3.0/ 3.0
4.0
What will the value of x be after the following statements execute? int x; x = 18.0 / 4;
4.5
The programmer usually enters source code into a computer using:
A text editor
What statement best describes a variable and its primary purpose?
A variable is a named storage location in the computer's memory used for holding a piece of information
A set of well-defined steps for performing a task or solving a problem is known as a(n)
Algorithm
For every opening brace in a C++ program, there must be a:
Closing brace
The____ decodes an instruction and generates electrical signals
Control Unit
This term refers to the programmer reading the program from the beginning and stepping through each statement
Desk Checking
Which is true about the following statement? cout<<setw(4)<<num4<<" ";
It allows four spaces for the value in the variable num4
Of the following, which is a valid C++ identifier?
June19997 _employee_number ___department myExtraLongVariableName
A variable declaration announces the name of a variable that will be used in a program, as well as:
The type of data it will be used to hold
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
What will the following code display? cout << "Four" << "score" << endl; cout << "and" << "seven" << endl; cout << "years" << "ago" << endl;
What will the following code display? cout << "Four" << "score" << endl; cout << "and" << "seven" << endl; cout << "years" << "ago" << endl;
Which character signifies the beginning of an escape sequence?
\
Which escape sequence causes the cursor to move to the beginning of the current line?
\r
function named main
\t
An example of a secondary storage device:
a hard disk
An Integrated Development Environment typically consists of:
a text editor a compiler a debugger
A variable whose value can be either true or false is of this data type.
bool
A file ___ is a small holding section of memory that file-bound information is first written to
buffer
Which data type typically requires only one byte of storage?
char
Which of the following lines of code defines an array that will hold 49 characters and the null terminator?
char str[50];
If you are reading data from a keyboard and you wanted the computer to recognize the space, tab, or enter key as the delimiter to separate two input values, you would use ___object.
cin
Assuming dataFile is a file stream object, the statement: dataFile.close();
closes file
The function, pow (x, 5.0), requires this header file
cmath
When using the sqrt function you must include this header file.
cmath
_____are used to translate each source code instruction into the appropriate machine language instruction.
compilers
This step will uncover any syntax errors in your programs
compiling
The ______ is/are used to display information on the computer's screen.
cout object
To use the rand() function, you must #include this header file in your program.
cstdlib
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?
decode
You must have a ___________ for every variable you intend to use in a program
definition
The programming process consists of several steps, which include:
design, creation, testing and debugging
Which of the following defines a double-precision floating point variable named payCheck?
double payCheck;
The character array company[12] can hold
eleven characters and the null terminator
To read data a file, you define an object of this data type
ifstream
Associativity is either right to left or:
left to right
Which statement is equivalent to the following? x=x*2;
x*=2;
In the C++ instruction, cookies = number % children; given the following declaration statement: int number = 38, children = 4, cookies; what is the value of cookies after the execution of the statement?
2
What will the value of result be after the following statement executes? result=6-3*2+7-10/2;
2
What will the value of x be after the following statements execute? int x; x = 18 % 4;
2
Which line in the following program will cause a compiler error? 1-#include <iostream> 2-using namespace std; 3- 4-int main() 5-{ 6-const int MY_VAL; 7-MY_VAL=77; 8-cout<<MY_VAL<< endl; 9- return 0; 10-}
6
Which statement will read a string into the following char array?
cin>>names;
These are data items whose values do not change while the program is running.
Literals
What will the following code display? cout << "Monday"; cout << "Tuesday"; cout << "Wednesday";
MondayTuesdayWednesday
The statement cin>>setw(10)>>str; will read up to this many characters into str.
Nine
In memory, C++ automatically places a ___________ at the end of string literals
Null terminator
A___is a set of instructions that the computer follows to solve a problem
Program
The computer's main memory is commonly known as:
RAM
This is a volatile type of memory, used for temporary storage
RAM
This is used to mark the end of a complete C++ programming statement
Semicolon
The total number of digits that appear before and after the decimal point is sometimes referred to as:
Significant digits and precision
In the process of translating a source file into an executable file, which of the following is the correct sequence?
Source code, preprocessor, modified source code, compiler object code, linker, executable code
The___ causes a program to wait until information is typed at the keyboard and the Enter key is pressed
cin object
You want the user to enter the length, width and height from the keyboard. Which cin statement is correctly written?
cin.get (length, width, height);
This reads an entire line of text until the Enter key is pressed
cin.getline()
This is a set of rules that must be followed when constructing a program
syntax
The name for a memory location that may hold data is:
variable
Progammer-defined names of memory locations that may hold data are:
variables