C++ Exam1 Flashcards

1
Q

#include <iostream></iostream>

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

using namespace std;

A

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 .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

int main()

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Common Escape Sequences

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

string literal, a string constant, or simply a string

A

In programming terms, the group of characters inside the
quotation marks
is called a string literal, a string constant, or simply a string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

semicolon

A

many C++ lines, such as comments, preprocessor directives, and the beginning of functions, are not complete statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

number = 5;

A

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 ).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

variable definition

A

It tells the compiler the variable’s name and the type
of data
it will hold . Notice that the definition gives the data type first, then the name of the variable, and ends with a semicolon.

int number ;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

To use stream manipulators, you should include the ________ header file.

A

iomanip

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Program code that can be evaluated to a value is called a(n)

A

expression.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which of the following statements will assign number a value from 90 - 100?

A

number = rand() % 11 + 90;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

________ must be included in a program in order to use the cout object.

A

The iostream header file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A variable must be defined

A

before it can be used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

True/False: The cin object lets the user enter a string that contains embedded blanks.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

True/False: In C++, the 5 basic arithmetic operators are
addition (+), subtraction (-), multiplication (*), division (/), and exponentiation (^).

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

To use the sqrt() function, or other mathematical library functions, you must #include the ________ header file in your program.

A

cmath

18
Q

For data validation, it is best to use a(n)

A

while loop.

19
Q

The while loop has two important parts: a condition that is tested and a statement or block of statements that is

A

repeated as long as the condition is true.

20
Q

A(n) ________ is a variable that controls the number of times a loop iterates.

A

loop control variable

21
Q

In a for statement, the ________ expression is executed only once

A

initialization

22
Q

The ideal type of loop to use if you want a user to enter exactly 20 values is a(n) ________ loop.

A

for

23
Q

To use files in a C++ program you must include the ________ header file.

A

fstream

24
Q

A variable that keeps a running total of data values is called a(n)

A

accumulator.

25
Q

The ideal type of loop to use for repeating a menu is a(n) ________ loop.

A

do-while

26
Q

To use files in a C++ program you must include the ________ header file.

A

fstream

27
Q

Common Escape Sequences

A
28
Q

Identifiers

A
29
Q

Math Func(1)

A
30
Q

Math Func(2)

A
31
Q

Stream Manipulators

A
32
Q

cstdlib

A

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.

33
Q

seed

A

Th e algorithm needs a starting value, called a seed, to generate the numbers. (As in random numbers)

34
Q

Limiting the Range of a Random Number

A

number = (rand() % (maxValue - minValue + 1)) + minValue;

35
Q

Hand tracing

A

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.

36
Q

Precedence of Relational Expressions

A
37
Q

Relational Expressions

A
38
Q

Setting Up a Program for File Input / Output

A
39
Q

File Stream Data Type

A
40
Q

Creating a File Stream Object and Opening a File

A