C++ Midterm
A _____ is a diagram that graphically illustrates the structure of the program.
Flowchart
<iomanip>
Header file that must be used for manipulating output. (i.e. when using setw( )).
Short Circuit Evaluation
If the sub-expression on the left side of an && operator is false, the expression on the right side will not be checked. If the sub-expression on the left side of an || operator is true, the expression on the right will not be checked.
Associativity
If two operators have the same precedence they move left to right.
_____ is information a program gathers from the outside world.
Input
Indentation and spacing
Is for human readers of a program, not the compiler.
&&
Is known as the logical AND operator. (Best one to use to check if a number is INSIDE a range).
||
Is known as the logical OR operator. (Best one to use to check if a number is OUTSIDE a range).
loop header
It consists of the key word (while/for) followed by an expression enclosed in parenthesis.
Conditionally Executed
It is performed only when a certain condition exists.
Post-test loop
Its expression is tested AFTER each iteration. (do-while). It always performs at least one iteration. (Can be used as a user control loop).
Type Case Expression
Lets you manually promote or demote a value.
_____ is the only language computers really process.
Machine Language
Both main memory and secondary storage or types of memory. Describe the difference between the two.
Main memory is like RAM and Secondary Storage is like the Hard Drive.
Read position
Marks the location of the next byte that will be *read* from a file.
Does this line contain a valid comment? /* This is a //*// First Rate Program //*//
No
_____ are characters or symbols that perform operations on one or more operands.
Operators
_____ is information a program sends to the outside world.
Output
!
Performs a logical NOT operation. It takes an operand and reverses its truth or falsehood.
Computers can do many different jobs because they can be _____.
Programmed
_____ characters or symbols mark the beginning or ending of programming statements, or separate items in a list.
Punctuation
Input Validation
The process of inspecting data given to a program by the user and determining if it is valid.
Reading Data
The process of retrieving data from a file.
Writing Data
The process of saving data in a file.
Priming Read
The read operation that takes place just before a loop. It provides the first value for the loop to test.
body of a loop
The statement that is repeated if the condition is true.
Precision or Significant Digits
The total number of digits that appear before and after the decimal point.
Accumulator
The variable used to keep a running total.
Formatting
The way a value is printed.
Logical Operators
These operators connect two or more relational expression into one, or reverse the logic of an expression. (AND, OR NOT... && || !)
Relational Operators
These operators determine whether a specific relationship exists between two values.
Division By Zero
This is mathematically impossible to perform and it normally causes a program to crash.
cout.fill( )
This member function of cout changes the fill character, which is a space by default. (fill characters are used when using setw( )).
Conditional Operator
This operator consists of the question mark (?) and colon (:). (A ternary operator).
Switch Statement
This statement lets the value of a variable or expression determine where the program will branch.
Decrement
To decrease a value.
Increment
To increase a value.
The character escape sequence to represent a double quote is:
\"
The character escape sequence to represent a single quote is:
\'
The character escape sequence to represent a backslash is:
\\
The character escape sequence to force the cursor to go to the next line is:
\n
The character escape sequence to force the cursor to advance forward to the next tab setting is:
\t
what do // mark the beginning of?
a comment
perform operations on data
assignment operator
How is a value stored in a variable?
assignment statement
Declare a variable hasPassedTest , and initialize it to true .
bool hasPassedTest; hasPassedTest = true;
Declare a variable isACustomer , suitable for representing a true or false value .
bool isACustomer;
useful for evaluating conditions that are either true or false
bool variables
assign values to variables as part of the definition
initialization
The three primary activities of a program are _____, _____, and _____.
input, processing, output
A program is a set of _____.
instructions
Declare an integer variable cardsInHand and initialize it to 13.
int cardsInHand = 13;
Declare and initialize the following variables : A variable monthOfYear , initialized to the value 11 A variable companyRevenue , initialized to the value 5666777 A variable firstClassTicketPrice , initialized to the value 6000 A variable totalPopulation , initialized to the value 1222333
int monthOfYear = 11, companyRevenue = 5666777, firstClassTicketPrice = 6000, totalPopulation = 1222333;
Write a statement that declares an int variable presidentialTerm and initializes it to 4.
int presidentialTerm = 4;
...
int temp; temp=firstPlaceWinner; firstPlaceWinner=secondPlaceWinner; secondPlaceWinner=temp;
Write a declaration of an int variable year and initialize it to 365.
int year = 365;
Words that have special meaning in a programming language are called _____.
key words
_____ languages are close to the level of the computer.
low-level
Comments are generally added to programs because
many programs are complicated and comments help explain what is going on
Input validation
The process of inspecting data given to a program by a user and determining if it is valid.
<fstream>
A header file that contains all the declarations necessary for file operations.
Nested Loop
A loop that is inside another loop.
Write the necessary preprocessor directive to enable the use of the C++ string class .
#include <string>
Write a character literal representing a comma.
','
Write a character literal representing the digit 1 .
'1'
Write a character literal representing the (upper case) letter A .
'A'
Stream extraction operator
(>>) Gets characters from the stream object on its left and stores them in the variable whose name appears on its right.
Compound Operators
+=, -=, *=, /=, %=. Also known as combined assignment operators and arithmetic assignment operators.
How many spaces printed out by this statement: cout << "how" << "now" << "brown" << "cow" << "?";
0
How many bytes are needed to store: "" ?
1
How many bytes are needed to store: '\n' ?
1
How many bytes are needed to store: 'n' ?
1
For loop
1. Initializes a counter variable; 2. Tests an Expression; 3. Updates the Expression (Best used if testing for "false").
The three rules to using the pow( ) function
1. Must include <cmath> header file. 2. The arguments that you pass should be doubles. 3. The variable used to store pow's the return value should be a double.
File Use in a Program
1. Open the file 2. Process the file 3. Close the file
How many bytes are needed to store: "\n", ?
2
How many bytes are needed to store: "n" ?
2
Write a literal representing the largest character value . Suppose we are using unsigned one-byte characters .
255
How many bytes are needed to store: "\\n" ?
3
What's the difference in UNICODE value between '3' and '0'? (consult a table of UNICODE values):
3
What's the difference in UNICODE value between 'E' and 'A'? (consult a table of UNICODE values):
4
What's the difference in UNICODE value between 'e' and 'a'? (consult a table of UNICODE values):
4
How many spaces printed out by this statement: cout << "abc\ndef\tghi\njkl" << endl << endl << "mno\n\npqr\n";
6
What's the difference in UNICODE value between '6' and '0'? (consult a table of UNICODE values):
6
Write a literal representing the character whose ASCII value is 65 .
65
Library Function
A "routine" that performs a specific operation.
Flag
A boolean (or integer) variable that signals when a condition exists.
C++ Library
A collection of specialized functions.
loop
A control structure that causes a statement or group of statements to repeat.
Text file
A file that contains data that has been encoded as text, using a scheme such as ASCII or Unicode.
Binary File
A file that contains data that has not been converted to text.
Input File
A file that data is read from.
Output File
A file that data is written to.
Block of Code
A group of statements enclosed inside a set of braces.
<cmath>
A header file needed in order to work with some of the math library functions such as pow( )
Count-controlled loop
A loop that repeats a specific number of times. (for). It must posses three elements: 1. An initialized counter variable 2. Test the counter by comparing it to a max value. 3. Update the counter during each iteration.
While Loop
A pretest loop. It is especially useful for validating input. (Best used when testing for "true").
Decision Structure
A program that executes some statements only under certain circumstances. A specific action is taken only when a specific condition exists.
expression
A programming statement that has a value. It usually consists of an operator and its operands.
File Buffer
A small "holding section" of memory that file-bound data is first written to.
Sentinel
A special value that marks the end of a list of values and cannot be mistaken as a member of the list.
cin
A standard input object that can be used to read data typed at the keyboard. (It causes a program to wait until data is typed at the keyboard and the enter key is pressed).
Continue Statement
A statement that causes a loop to stop its current iteration and begin the next one.
Break Statement
A statement that causes a loop to terminate early.
Running total
A sum of numbers that accumulates with each iteration of a loop.
Counter
A variable that is regularly incremented or decremented each time a loop iterates.
User-controlled loop
Allows the user to decide the number of iterations. (The do-while is a good choice for repeating a menu).
Menu-Driven Program
Allows the user to determine the course of action by selecting it from a list of actions.
File Stream Object
An *object* that is associated with a specific *file*, and provides a way for the program to work with that file.
Null Statement
An empty statement that does nothing.
Test Expression
An expression that controls the execution of the loop. As long as it is true, the body of the loop will repeat.
Relational Expression
An expression used to determine whether a specific relationship exists between two values.
Explain the difference between an object file and an executable file?
An object file is the location that holds the translated machine language. Once the Linker has finished, it becomes an executable file.
Internally, the CPU consist of the _____ and the _____.
Arithmetic and Logic unit, Control Unit
Why is it easier to write a program in a high - level language then in machine language?
Because Machine Language consists of 1's and 0's. (0010011100101001)
Why must programs written in a high - level language be translated into machine language before they can be run?
Because a computer's CPU can only understand Machine Language.
Expressions that have a true or false value
Boolean expressions
The job of the _____ is to fetch instructions, carry out the operations commanded by the instructions, and produce some outcome or resultant information.
CPU
Conditional Expression
Consists of three sub-expressions separated by the ? and : symbols.
Infinite Loop
Continues to repeat until the program is interrupted.
Loop control variable
Controls the number of times that a loop iterates.
Arguments
Data being sent to a function.
Iteration
Each repetition of a loop.
Conditional Loop
Executes as long as a particular condition exists.
Boolean Expressions
Expressions that are either true or false.
setprecision( )
Set the total number of digits that will appear before and after the decimal point. It remains in effect until it is changed.
Filename Extensions
Short sequences of characters that appear at the end of a filename preceded by a period (known as a "dot").
Sequence Structures
Statements that are executed in a sequence, without branching off in another direction.
What is the difference between a syntax error and a logical error?
Syntax Errors are illegal uses of key word, operators, punctuation, and other language elements. Logical Errors are mistakes that cause the program to produce erroneous results.
What type of software controls the internal operations of the computers hardware?
System Software
What is the difference between system software and application software?
System Software includes the Operating Systems, Utility Programs, Software Development Tools. Application Software includes programs used by the user.
Prompt
Tells the user what data he/she should enter.
Pretest Loop
Tests its expression before each iteration. (while & for).
Initialization Expression
The first expression in a for loop. It is normally used to initialize a counter variable to its starting value. (It is only done once in the loop).
Trailing Else
The last else clause.
Postfix Mode
The operator is placed after the variable. The increment or decrement will happen last.
Prefix Mode
The operator is placed before the variable. The increment or decrement will happen first.
Scope
The part of the program where the variable may be used.
static_cast<dataType>(value)
Type cast conversion. It lets you manually promote or demote a value.
Update the Expression
Typically a statement that increments/decrements a loop's counter variable.
setw( )
Used to establish print fields of specified width. Only works with the value that immediately follows it.
Local scope or Block Scope
Variables defined inside a set of braces. They may only be used in the part of the program between their definition and the block's closing brace.
Type coercion
When C++ is working with an operator, it strives to convert the operands to the same type.
Promoted
When a value is converted to a higher data type.
Demoted
When a value is converted to a lower data type.
Overflow
When a variable is assigned a number that is too large for its data type. (It will wrap around to its lowest possible value).
Underflow
When a variable is assigned a number that is too small for its data type.
fixed-point notation
When the fixed manipulator is used, all floating-point numbers that are subsequently printed will be displayed with the number of digits to the right of the decimal point specified by the setprecision manipulator.
Round-Off Error
When two values are different, but because of rounding are comparing to be of equal value. (This happens mostly with floating-point numbers. You should use < or > rather than ==).
Integer Division
When you divide an integer by another integer in C++, the result is always an integer.
Does this line contain a valid comment? int twoPi = 3.14459; /* holds the value of two times pi */
Yes
Sequential Access File
You *access* the data from the beginning of the file to the end of the file.
Random Access File or Direct Access File
You can jump directly to the desired data in this type of file without reading the data that comes before it.
Declare a character variable named c .
char c;
Assume that word is a string variable . Write a statement to display the message "Today's Word-Of-The-Day is: " followed by the value of word on standard output .
cout << "Today's Word-Of-The-Day is: " << word ;
Assume that message is a string variable . Write a statement to display its value on standard output .
cout << message ;
A variable must be _____ before it can be used in a program.
defined
Declare a numerical variable precise and initialize it to the value 1.09388641.
double precise = 1.09388641;
Given two double variables , bestValue and secondBestValue , write some code that swaps their values . Declare any additional variables as necessary.
double temp; temp = bestValue; bestValue = secondBestValue; secondBestValue = temp;
Write a literal representing the false value in C++.
false
3 data types that can represent floating point numbers
float or single precision (4 bytes) double or double precision (8 bytes) long double or long double precision (8 bytes)
Declare a variable temperature and initialize it to 98.6.
float temperature = 98.6;
Used to define variable that can hold real numbers; a data type that allows fractional values
floating-point data types
A group of one or more programming statements that collectively has a name
function
_____ languages are close to the level of humans in terms of readability.
high-level
C++ uses ___ to organize the names of program entities.
namespaces
Write a statement to set the value of num to 4 (num is a variable that has already been declared ).
num = 4;
the data that operators work with
operands
A program's ability to run on several different types of computer systems is called _____.
portability
Reads your program before it is compiled and only executes those lines beginning with the # symbol
prepocessor directive
"sets up" your source code for the compiler
preprocessor directive
the line in the program that begins with a # is called a
preprocessor directive
Since computers can't be programmed in natural human language, algorithms must be written in a _____ language.
program
Words or names defined by the programmer are called _____.
programmer-defined identifiers
the part of the program that has access to the variable
scope
Declare a string variable named empty and initialize it to the empty string .
string empty;
Declare a string variable named mailingAddress .
string mailingAddress;
Declare a string variable named oneSpace and initialize it to a string consisting of a single space.
string oneSpace; oneSpace = " ";
Declare a string variable named str and initialize it to Hello .
string str; str = "Hello";
Declare 3 string variables named winner , placed and show .
string winner, placed, show;
The rules that must be followed when constructing a program are called _____.
syntax
Write a literal representing the true value .
true
A _____ is a named storage location.
variable