Quiz 2 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Which of the following statements is not a repetition structure?
1. while
2. for
3. do while
4. if - else if - else

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

Loops may be “nested” inside of other loops. True or false?

A

True.

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

In the following for loop, what is the bolded section of the loop known as?

for(int i = 0; i < 10; i++){
// do stuff
}

A

initialization statement

remember, it’s initializing the variable i

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

The for loop is a post-test loop. True or false?

A

False. It is a pre-test loop

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

The while loop is a pretest loop. True or false?

A

True.

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

A while loop is ideal for performing \_\_\_\_\_\_\_\_\_\_\_\_\_\_ iterations?
1. a fixed number
2. 0 or more
3. 1 or more

A
  1. 0 or more
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The for loop is best described as which of the following?
1. a post-test loop
2. a condition-controlled loop
3. a while loop
4. a count-controlled loop

A

a count-controlled loop

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

Which loop is a post-test loop?

A

The do while loop

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

In C++ the Boolean value false is stored in memory as the numeric value 1. True or false?

A

False. It is stored as 0.

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

Assume the following, x = 8, y = 10, and z = 12. What is the result of the Boolean Expression: x != 8 || x <= y?

A

True

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

In C++, when characters are compared (char datatype) the integer ASCII values are used. True or false?

A

True.

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

You should always close a file when you are done with it. True or false?

A

True.

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

In the following for loop, what is the bolded section of the loop known as?

for(int i = 0; i < 10; i++){
// do stuff
}

A

update statement

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

If you try to open a file to read from it, and the file does not exist, the program will fail to compile. True or false?

A

False

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

When you call an ofstream object’s open function, the file will be erased if it already exists. True or false?

A

True.

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

When you call an ifstream object’s open function, the file will be erased if it already exists. True or false?

A

False.

17
Q

Which of the following statements correctly closes the file object my_file that has been opened and connected to the file data.txt?

A

my_file.close();

18
Q

Which header would you need to include to define variables for input and output file objects?

A

fstream

19
Q

You can use the same tools with files that you have used so far with std::cin (>>, getline(), .get() ), if the file has been opened correctly such that you can read from it. True or false?

A

True.

20
Q

To read data from a file, you need to create an instance (variable) of the type \_\_\_\_\_\_\_\_\_\_.

A

ifstream

21
Q

To write data to a file, you need to create an instance (variable) of the type \_\_\_\_\_\_\_\_\_\_.

A

ofstream