C++ Exam1 Flashcards
#include <iostream></iostream>
When a line begins with a # it indicates it is a preprocessor directive.
The #include directive causes the preprocessor to include the contents of another file in the program .
The word inside the brackets, iostream, is the name of the file that is to be included . The iostream file contains code that allows a C++ program to display output on the screen and read input from the keyboard.
Because the cout statement prints output to the computer screen, we need to include this file. Its contents will be placed in the program at the point the #include statement appears.
The iostream file is called a header file, so it should be included at the head, or top, of the program.
It is part of the input - output stream library. The iostream
header file contains information describing iostream objects. Without it, the compiler will not know how to properly compile a program that uses cout .
Any program that uses the cout object must contain the extensive setup information found in the iostream file.
using namespace std;
Variables, functions, and objects are examples of program entities that must have names. C++ uses namespaces to
organize the names of program entities.
The statement using namespace std; declares that the program will be accessing entities whose names are part of the namespace called std . (Yes, even namespaces have names.)
The program needs access to the std namespace because every name created by the iostream file is part of that namespace. In order for a program to use the entities in iostream, it must have access to the std namespace .
int main()
This marks the beginning of a function. A function can be thought of as a group of one or more programming statements that has a name. The name of this function is main, and the set of parentheses that follows the name indicates that it is a function . The word int stands for “integer.” It indicates that the function sends an integer value back to the operating system when it is finished executing.
Common Escape Sequences

string literal, a string constant, or simply a string
In programming terms, the group of characters inside the
quotation marksis called a string literal, a string constant, or simply a string.
semicolon
many C++ lines, such as comments, preprocessor directives, and the beginning of functions, are not complete statements
number = 5;
This is an assignment statement, and the = sign is called the assignment operator. This operator copies the value on its right (5) into the variable named on its left (number ).
variable definition
It tells the compiler the variable’s name and the type
of datait will hold . Notice that the definition gives the data type first, then the name of the variable, and ends with a semicolon.
int number ;
To use stream manipulators, you should include the ________ header file.
iomanip
Program code that can be evaluated to a value is called a(n)
expression.
Which of the following statements will assign number a value from 90 - 100?
number = rand() % 11 + 90;
________ must be included in a program in order to use the cout object.
The iostream header file
A variable must be defined
before it can be used.
True/False: The cin object lets the user enter a string that contains embedded blanks.
False
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.
True
True/False: In C++, the 5 basic arithmetic operators are
addition (+), subtraction (-), multiplication (*), division (/), and exponentiation (^).
True
To use the sqrt() function, or other mathematical library functions, you must #include the ________ header file in your program.
cmath
For data validation, it is best to use a(n)
while loop.
The while loop has two important parts: a condition that is tested and a statement or block of statements that is
repeated as long as the condition is true.
A(n) ________ is a variable that controls the number of times a loop iterates.
loop control variable
In a for statement, the ________ expression is executed only once
initialization
The ideal type of loop to use if you want a user to enter exactly 20 values is a(n) ________ loop.
for
To use files in a C++ program you must include the ________ header file.
fstream
A variable that keeps a running total of data values is called a(n)
accumulator.
The ideal type of loop to use for repeating a menu is a(n) ________ loop.
do-while
To use files in a C++ program you must include the ________ header file.
fstream
Common Escape Sequences

Identifiers

Math Func(1)

Math Func(2)

Stream Manipulators

cstdlib
It returns a non-negative integer each time it is called. _To use the rand() function_, you must include the cstdlib header file in your program.
seed
Th e algorithm needs a starting value, called a seed, to generate the numbers. (As in random numbers)
Limiting the Range of a Random Number
number = (rand() % (maxValue - minValue + 1)) + minValue;

Hand tracing
Hand tracing is a debugging process where you pretend that you are the computer executing a program. You step through each of the program ‘s statements one by one.
Precedence of Relational Expressions

Relational Expressions

Setting Up a Program for File Input / Output

File Stream Data Type

Creating a File Stream Object and Opening a File
