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