The _____ statement causes a loop to terminate early. The _____ statement causes a loop to stop its current iteration and begin the next one.
a.. continue, break
b. break, continue
Answers for C++ Course using "Starting out with C++ : from control structures through objects" by Tony Gaddis. 7/8th ed. I used the Pearson myprogramminglab to complete the homework. Here are my solutions/answers for the exercises/labs so please use the test bank as a GUIDE if you're stuck. Let me know if you find a better solution to a problem or any of the programming challenges. Thanks in advance for your support! Send in missing programming challenges to cplusplus.answers@gmail.com
Chapter 5 Quiz Starting Out With C++ 042
Reading and Writing files in C++. How can you tell if a file was successfully opened in C++?
assume inFile was defined as an ifstream object
a. test ifstream and see if it is true
b. test inFile and check if it is true
c. test open(inFile) == true
d. check if inFile returns an error.
assume inFile was defined as an ifstream object
a. test ifstream and see if it is true
b. test inFile and check if it is true
c. test open(inFile) == true
d. check if inFile returns an error.
Chapter 5 Quiz Starting Out With C++ 041
Writing and Reading files in C++. What can be used to read lines of data from a file?
a. the readLine() function
b. a loop
c. cin
d. inFile
a. the readLine() function
b. a loop
c. cin
d. inFile
Chapter 5 Quiz Starting Out With C++ 040
Reading and Writing files in C++. Will the following segment of code read the name of a city?
ifstream inFile;
string city;
inFile.open("cities.txt");
cout << "Reading city name from the file.\n";
inFile >> city; // Read the city name from the file
a. true
b. false
ifstream inFile;
string city;
inFile.open("cities.txt");
cout << "Reading city name from the file.\n";
inFile >> city; // Read the city name from the file
a. true
b. false
Chapter 5 Quiz Starting Out With C++ 039
Writing and Reading files in C++. The >> operator combined with an ifstream object can be used to read from a file?
a. true
b. false
a. true
b. false
Chapter 5 Quiz Starting Out With C++ 038
Writing and Reading files in C++. Given that outFile has been defined with ofstream, which statement will write the data to a file?
a. cout(outFile) << " Hello Student";
b. cout << outFile << "Hello Student";
c. outFile << "Hello Student";
d. outFile -> "Hello Student";
a. cout(outFile) << " Hello Student";
b. cout << outFile << "Hello Student";
c. outFile << "Hello Student";
d. outFile -> "Hello Student";
Chapter 5 Quiz Starting Out With C++ 037
Writing and Reading a file in C++. How do you close a file in C++?
a. ifstream inFile.close();
b. inFile.Close();
c. inFile.close();
d. close(inFile);
a. ifstream inFile.close();
b. inFile.Close();
c. inFile.close();
d. close(inFile);
Chapter 5 Quiz Starting Out With C++ 036
Reading and Writing files in C++. What does the following statement do?
ifstream inFile("NewHires.txt");
a. defines a input file stream named inFile and opens the file NewHires.txt.
b. defines the input stream but does not open it.
c. checks to see if the file NewHires.txt exists
d. none of the above. You can't do all that in one statement
ifstream inFile("NewHires.txt");
a. defines a input file stream named inFile and opens the file NewHires.txt.
b. defines the input stream but does not open it.
c. checks to see if the file NewHires.txt exists
d. none of the above. You can't do all that in one statement
Chapter 5 Quiz Starting Out With C++ 035
_____ backslashes are required to represent one blackslash when setting the path of a file in a string.
a. two
b. three
c. one
a. two
b. three
c. one
Chapter 5 Quiz Starting Out With C++ 034
Reading and Writing files in C++. Is this how you set up a file for output in C++?
ofstream outFile;
outFile.open("Sales.txt");
a. true
b. false
ofstream outFile;
outFile.open("Sales.txt");
a. true
b. false
Chapter 5 Quiz Starting Out With C++ 033
Writing and Reading files in C++. The following is the correct way to set up a file for reading?
ifstream inFile;
inFile.open("Employees.txt");
a. true
b. false
ifstream inFile;
inFile.open("Employees.txt");
a. true
b. false
Chapter 5 Quiz Starting Out With C++ 032
Reading and Writing files in C++. _____ is used for output, _____ is used for input and _____ is used for reading or writing.
a. fstream, ofstream, ifstream
b. ifstream, ofstream, fstream
c. ifstream, fstream, ofstream
d. fstream, fstream, fstream
a. fstream, ofstream, ifstream
b. ifstream, ofstream, fstream
c. ifstream, fstream, ofstream
d. fstream, fstream, fstream
Chapter 5 Quiz Starting Out With C++ 031
Reading and Writing files in C++. _____ contains all the declarations necessary for file operations.
a. fileIOstream
b. file.h
c. fstream
d. fileReadWrite
a. fileIOstream
b. file.h
c. fstream
d. fileReadWrite
Chapter 5 Quiz Starting Out With C++ 030
Writing and Reading files in C++. What must be created in order to be able to work with files/
a. filesys link
b. file stream object
c. binary stream
d. random access link
a. filesys link
b. file stream object
c. binary stream
d. random access link
Chapter 5 Quiz Starting Out With C++ 029
Writing and Reading files in C++. Random access files or direct access files are considered the same thing?
a. true
b. false
a. true
b. false
Chapter 5 Quiz Starting Out With C++ 028
Reading and Writing files in C++. Sequential access files can be accessed at any location in the file. This may include forward and backwards?
a. true
b. false
a. true
b. false
Chapter 5 Quiz Starting Out With C++ 027
Reading a writing files in C++. A _____ file can be easy read by human eyes, whereas a _____ file is more difficult.
a. binary, ASCII
b. ASCII, binary
c. text, ASCII
d. ASCII, text
a. binary, ASCII
b. ASCII, binary
c. text, ASCII
d. ASCII, text
Chapter 5 Quiz Starting Out With C++ 026
Using data files in C++. What are the steps required for using a file in a program in C++?
a. Process the file, Open the file, Close the file
b. Open the file, Process the file, Close the file
c. Close the file, Process the file, Open the file
Chapter 5 Quiz Starting Out With C++ 025
A loop that is inside another loop is called a _____?
a. internal loop
b. indented loop
c. blocked loop
d. nested loop
a. internal loop
b. indented loop
c. blocked loop
d. nested loop
Chapter 5 Quiz Starting Out With C++ 024
The file temp.txt has the following values. What is probably the sentinel value?
98, 101, 95, 93, 85, 73, 73, 75, 0
a. 98
b. 0
c. 85
d. \n
98, 101, 95, 93, 85, 73, 73, 75, 0
a. 98
b. 0
c. 85
d. \n
Chapter 5 Quiz Starting Out With C++ 023
What is a sentinel in C++? (mark the best answer)
a. a sentinel is a special value that marks the end of a list of values.
b. a routine that makes performs validation on the values
c. a sentinel is always -1 and terminates a list of values
d. a sentinel is a special value that is defined by the user.
a. a sentinel is a special value that marks the end of a list of values.
b. a routine that makes performs validation on the values
c. a sentinel is always -1 and terminates a list of values
d. a sentinel is a special value that is defined by the user.
Chapter 5 Quiz Starting Out With C++ 022
A _____ is a sum of numbers that accumulates with each iteration of a loop. The variable used to keep the running total is called an _____.
a. accumulator, running total
b. running total, accumulator
a. accumulator, running total
b. running total, accumulator
Chapter 5 Quiz Starting Out With C++ 021
Can you omit or leave out the initialization expression from a for-loop?
int i= 1;
int maxVal=10;
for ( ; i<= maxVal; i++)
cout << i << "\t\t" << (i * i) << "\n";
a. yes, if you have already initialized the test variable
b. yes, the for loop will automatically create the variable i and set it to 0
c. no, the compiler will generate an error
d. no, the program will run and then give a syntax error once you hit the loop
int i= 1;
int maxVal=10;
for ( ; i<= maxVal; i++)
cout << i << "\t\t" << (i * i) << "\n";
a. yes, if you have already initialized the test variable
b. yes, the for loop will automatically create the variable i and set it to 0
c. no, the compiler will generate an error
d. no, the program will run and then give a syntax error once you hit the loop
Exericse Number
Chapter 05,
Quiz
Chapter 5 Quiz Starting Out With C++ 020
Which of the following is the best answer. In a for loop, the counter can only be incremented or decremented by 1.
a. the counter can only be counter++ or counter--
b. no, you can do increment/decrement other than by 1. counter+=2
c. yes
a. the counter can only be counter++ or counter--
b. no, you can do increment/decrement other than by 1. counter+=2
c. yes
Exericse Number
Chapter 05,
Quiz
Chapter 5 Quiz Starting Out With C++ 019
Which of the following loop mechanisms are pretest loops in C++?
a. for loops
b. while loops
c. do while loops
d. a and c
e. a and b
a. for loops
b. while loops
c. do while loops
d. a and c
e. a and b
Exericse Number
Chapter 05,
Quiz
Chapter 5 Quiz Starting Out With C++ 018
Can you use for-loop, do-while and while looping to perform identically?
a. true
b. false
a. true
b. false
Exericse Number
Chapter 05,
Quiz
Chapter 5 Quiz Starting Out With C++ 017
Can you declare and initialize in a variable that will be used in the test expression?
for (int i=0; i<100; i++)
{
//display the square of the numbers from 0 to 99
cout << i*i << "\n";
}
a. true
b. false
for (int i=0; i<100; i++)
{
//display the square of the numbers from 0 to 99
cout << i*i << "\n";
}
a. true
b. false
Exericse Number
Chapter 05,
Quiz
Chapter 5 Quiz Starting Out With C++ 016
Is the following a correct format for the for-loop?
for (initialization; test expression; update)
{
statement;
statement;
.
.
}
a. true
b. false
for (initialization; test expression; update)
{
statement;
statement;
.
.
}
a. true
b. false
Exericse Number
Chapter 05,
Quiz
Chapter 5 Quiz Starting Out With C++ 015
What are the steps involved in a for-loop in C++?
a. initialize, perform update expression, test expression, and finally execute body
b. execute body, initialize, perform update expression, test expression
c. initialize, execute body, test expression, perform update expression
d. initialize, test expression, execute body, perform update expression
(remember the slide from 9/30/13)
a. initialize, perform update expression, test expression, and finally execute body
b. execute body, initialize, perform update expression, test expression
c. initialize, execute body, test expression, perform update expression
d. initialize, test expression, execute body, perform update expression
(remember the slide from 9/30/13)
Exericse Number
Chapter 05,
Quiz
Chapter 5 Quiz Starting Out With C++ 014
If you can determine ahead of time how many times a loop will be performed then a for-loop is commonly used.
a. true
b. false
a. true
b. false
Exericse Number
Chapter 05,
Quiz
Chapter 5 Quiz Starting Out With C++ 013
How do you prevent infinite loops?
a. make sure you test at the beginning of the loop
b. make sure something inside the loop changes the test expression to false
c. make sure you have plenty of RAM
d. it is impossible to prevent infinite loops.
e. make sure something inside the loop changes the test expression to true
a. make sure you test at the beginning of the loop
b. make sure something inside the loop changes the test expression to false
c. make sure you have plenty of RAM
d. it is impossible to prevent infinite loops.
e. make sure something inside the loop changes the test expression to true
Exericse Number
Chapter 05,
Quiz
Chapter 5 Quiz Starting Out With C++ 012
Which of the following is an example of an infinite loop
a.
x=1;
while (x>=1)
cout << "I'm in a loop";
b.
while infinite ()
cout << "I'm in a loop";
c.
while ()
{
cout << "I'm in a loop";
}
d.
x=10;
while (x >0)
{
x--;
cout << "I'm in a loop";
}
a.
x=1;
while (x>=1)
cout << "I'm in a loop";
b.
while infinite ()
cout << "I'm in a loop";
c.
while ()
{
cout << "I'm in a loop";
}
d.
x=10;
while (x >0)
{
x--;
cout << "I'm in a loop";
}
Exericse Number
Chapter 05,
Quiz
Chapter 5 Quiz Starting Out With C++ 011
The _____ is pretest loop and the _____ is a posttest loop
a. do-while loop, while loop
b. while loop, do-while loop
c. repeat loop, while loop
d. while loop, repeat loop
a. do-while loop, while loop
b. while loop, do-while loop
c. repeat loop, while loop
d. while loop, repeat loop
Exericse Number
Chapter 05,
Quiz
Chapter 5 Quiz Starting Out With C++ 010
The while loop is usually used when you know the exact number of times a loop will repeat
a. true
b. false
a. true
b. false
Exericse Number
Chapter 05,
Quiz
Chapter 5 Quiz Starting Out With C++ 009
What is the format of the while loop in C++?
a.
while ( x >5)
do {
y++;
}
b.
perform
{
y++;
} while (x >5)
c.
while (x >5)
{
y++;
}
a.
while ( x >5)
do {
y++;
}
b.
perform
{
y++;
} while (x >5)
c.
while (x >5)
{
y++;
}
Chapter 5 Quiz Starting Out With C++ 008
A _____ is a part of a program that repeats
a. function
b. loop
c. repeat
d. branch statement
a. function
b. loop
c. repeat
d. branch statement
Chapter 5 Quiz Starting Out With C++ 007
Can you use increment or decrement in relationship expressions?
if (x++ > 10)
cout << "Thanks for playing!";
a. true
b. false
if (x++ > 10)
cout << "Thanks for playing!";
a. true
b. false
Exericse Number
Chapter 05,
Quiz
Chapter 5 Quiz Starting Out With C++ 006
Given that x is 5 and y is 4 what will this code segment produce
z = ++(x + y);
a. 11
b. 10
c. a syntax error
d. a compilation error
z = ++(x + y);
a. 11
b. 10
c. a syntax error
d. a compilation error
Subscribe to:
Posts (Atom)