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
Chapter 5 Quiz Starting Out With C++ 005
Given the following code. Will anything be displayed?
z = 130;
if (x++ > 130)
cout << "z is greater than 130.\n";
a. true
b. false
z = 130;
if (x++ > 130)
cout << "z is greater than 130.\n";
a. true
b. false
Chapter 5 Quiz Starting Out With C++ 004
What is the difference between prefix and postfix when dealing with statements that do more than incrementing or decrementing?
a. nothing.
b. prefix will increment/decrement BEFORE the variable is used.
c. postfix will increment/decrement BEFORE the variable is used.
d. both will preform the increment/decrement AFTER the variable is used
a. nothing.
b. prefix will increment/decrement BEFORE the variable is used.
c. postfix will increment/decrement BEFORE the variable is used.
d. both will preform the increment/decrement AFTER the variable is used
Chapter 5 Quiz Starting Out With C++ 003
Given that x is 5 in the snippet below. What will be displayed by the cout statement?
x = 5;
cout << x++;
a. 6
b. 7
c. 5
d. 4
x = 5;
cout << x++;
a. 6
b. 7
c. 5
d. 4
Chapter 5 Quiz Starting Out With C++ 002
The first example is _____ mode and the second is _____ mode?
i++, ++j
a. prefix, postfix
b. postfix, prefix
c. post inc, pre inc
d. pre inc, post inc
i++, ++j
a. prefix, postfix
b. postfix, prefix
c. post inc, pre inc
d. pre inc, post inc
Exericse Number
Chapter 05,
Quiz
Chapter 5 Quiz Starting Out With C++ 001
How do you use the increment and decrement operators in C++?
a. x++, x--
b. x = x + 1, x = x -1
c. inc x, dec x
d. both a and b are acceptable
e. answer a, c. One is C language and the other is C++
a. x++, x--
b. x = x + 1, x = x -1
c. inc x, dec x
d. both a and b are acceptable
e. answer a, c. One is C language and the other is C++
Chapter 4 Quiz Starting Out With C++ 047
Can you have two variables with the same name in C++?
a. only if they are in the same scope
b. only if they are in different blocks
c. if one of the variables is in a function
d. heck, I wasn't listening when we went over this. idk
a. only if they are in the same scope
b. only if they are in different blocks
c. if one of the variables is in a function
d. heck, I wasn't listening when we went over this. idk
Chapter 4 Quiz Starting Out With C++ 046
The switch statement lets the value of a variable or expression determine where the program will branch in an if/else statement
a. true
b. false
a. true
b. false
Chapter 4 Quiz Starting Out With C++ 045
Since it takes three operands, the conditional operator is considered a
ternary operator.
a. true
b. false
ternary operator.
a. true
b. false
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 044
Which of the following is an example of a conditional operator?
a.
x > y ? z=1 : z=0;
b.
if (x>y)
z=1
else
z=0;
c.
if x>y then z=1 else z=0
d.
? (x>y) : z=1 : z=0;
a.
x > y ? z=1 : z=0;
b.
if (x>y)
z=1
else
z=0;
c.
if x>y then z=1 else z=0
d.
? (x>y) : z=1 : z=0;
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 043
The conditional operator works like an if/else statement
a. true
b. false
a. true
b. false
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 042
What do the ASCII values 65 through 90 represent?
a. the numbers from 65 through 90 as integers.
b. the characters 'a' through 'z'
c. the characters 'A' through 'Z'
d. the characters '0' through '9'
e. none. ASCII is obsolete and no longer used.
a. the numbers from 65 through 90 as integers.
b. the characters 'a' through 'z'
c. the characters 'A' through 'Z'
d. the characters '0' through '9'
e. none. ASCII is obsolete and no longer used.
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 041
The highest or of precedence in C++ is
a. ||
b. !
c. &&
d. they are all the same. Left to right
a. ||
b. !
c. &&
d. they are all the same. Left to right
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 040
Precedence is not important in C++
a. true
b. false
a. true
b. false
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 039
What does || mean in C++?
a. OR
b. NOT
c. EITHER
a. OR
b. NOT
c. EITHER
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 038
What is the value of the following expression?
true && false
a. true
b. false
c. can't tell
d. the expression makes no sense in C++
true && false
a. true
b. false
c. can't tell
d. the expression makes no sense in C++
Chapter 4 Quiz Starting Out With C++ 037
In C++, the ______ operator reverses the "truth" of an expression. It makes a true expression false and a false expression true.
a. &&
b. !
c. ||
d. reverse()
e. none of the above
a. &&
b. !
c. ||
d. reverse()
e. none of the above
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 036
_____ operators connect two or more relational expressions into one or reverse the logic of an expression?
a. syntax
b. binary
c. logical
d. combinatory
e. answer b and c
a. syntax
b. binary
c. logical
d. combinatory
e. answer b and c
Chapter 4 Quiz Starting Out With C++ 035
What is typically used as a flag in C++
a. a float
b. an integer
c. a bool
d. a register
e. b and c
ab. answer c is typical but answer b is also used by some
ae. none of the above. C++ does not have access to the AX or BX flags of the CPU
a. a float
b. an integer
c. a bool
d. a register
e. b and c
ab. answer c is typical but answer b is also used by some
ae. none of the above. C++ does not have access to the AX or BX flags of the CPU
Chapter 4 Quiz Starting Out With C++ 034
The potential round-off errors are common if the user is not careful when the user uses the equality operator to compare floating point values.
a. true
b. false
a. true
b. false
Chapter 4 Quiz Starting Out With C++ 033
What is the operator that can be used for the logical AND ?
a. &&
b. ++
c. ||
d. @
e. AND
a. &&
b. ++
c. ||
d. @
e. AND
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 032
What is the value for a relational operation when it is not true?
a. one
b. zero
c. zero, one, or minus one
d. less than zero
a. one
b. zero
c. zero, one, or minus one
d. less than zero
Chapter 4 Quiz Starting Out With C++ 031
The following C++ statement will let the variable decide where the program will go to.
a. select
b. associative
c. scope
d. switch
e. none of the above
a. select
b. associative
c. scope
d. switch
e. none of the above
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 030
When you use input values, the user should check for the following:
a. Appropriate range
b. Reasonableness
c. Division by zero, if division is taking place
d. All of these
e. None of the above
a. Appropriate range
b. Reasonableness
c. Division by zero, if division is taking place
d. All of these
e. None of the above
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 029
An if statement considers true any value that is NOT 0 (ZERO)
a. true
b. false
a. true
b. false
Chapter 4 Quiz Starting Out With C++ 028
When a user writes an if statement, the user should indent the statements that get executed conditionally based on programming style.
a. true
b. false
a. true
b. false
Chapter 4 Quiz Starting Out With C++ 027
The switch statement does not require the default section.
a. true
b. false
a. true
b. false
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 026
If a conditionally-executed code of another if statement contains an if statement, this is called:
a. complexity
b. overloading
c. nesting
d. validation
a. complexity
b. overloading
c. nesting
d. validation
Chapter 4 Quiz Starting Out With C++ 025
You can ____________ numbers with relational operators.
a. average
b. add
c. multiply
d. compare
a. average
b. add
c. multiply
d. compare
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 024
What operators can you choose to subtract 1 from their operands.
a. unary
b. minus
c. --
d. relational
a. unary
b. minus
c. --
d. relational
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 023
You may nest for loops like the while and do-while loops.
a. true
b. false
a. true
b. false
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 022
An initialization expression may be omitted from the for loop if initialization is required.
a. true
b. false
a. true
b. false
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 021
The condition that is tested by a while loop must be enclosed in parentheses and terminated with a semicolon.
a. True
b. False
a. True
b. False
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 020
Using the following word, we mean that we add 1 to the value.
a. modulus
b. decrement
c. increment
d. parse
a. modulus
b. decrement
c. increment
d. parse
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 019
What is the name of a loop that is inside another one?
a. an infinite loop
b. a pre-test loop
c. a nested loop
d. a post-test loop
a. an infinite loop
b. a pre-test loop
c. a nested loop
d. a post-test loop
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 018
Which of the following is an important part of a while loop:
a. a statement or block that is repeated as long as the expression is true
b. a statement or block that is repeated only if the expression is false
c. one line of code that is repeated once, if the expression is true
d. a statement or block that is repeated once, if the expression is true
a. a statement or block that is repeated as long as the expression is true
b. a statement or block that is repeated only if the expression is false
c. one line of code that is repeated once, if the expression is true
d. a statement or block that is repeated once, if the expression is true
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 017
You can include multiple statements in the body of a while loop, if you enclose them in braces.
a. true
b. false
a. true
b. false
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 016
The test condition of a for loop cannot include multiple relational expressions.
a. true
b. false
a. true
b. false
Chapter 4 Quiz Starting Out With C++ 015
What will be displayed after the following is executed given that grade is 90
if ( grade > 90 )
cout << "Congrats on getting an 'A'";
else
cout << "You almost got an 'A' better luck next time.";
cout << "Try harder next time.";
a. Congrats on getting an 'A'
b. You almost got an 'A' better luck next time.
c. You almost got an 'A' better luck next time.
Try harder next time.
d. You almost got an 'A' better luck next time.Try harder next time.
e. None of the above
if ( grade > 90 )
cout << "Congrats on getting an 'A'";
else
cout << "You almost got an 'A' better luck next time.";
cout << "Try harder next time.";
a. Congrats on getting an 'A'
b. You almost got an 'A' better luck next time.
c. You almost got an 'A' better luck next time.
Try harder next time.
d. You almost got an 'A' better luck next time.Try harder next time.
e. None of the above
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 014
What is the value of x after the following snippet of code is executed given that x is 3
if (x == 3)
x++;
x++;
a. 4
b. 1
c. 5
d. 7
if (x == 3)
x++;
x++;
a. 4
b. 1
c. 5
d. 7
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 013
Let's analyze the following statement assuming that y is 6.
if ( y = 7 )
cout << " y is 7. How lucky of you. ";
else
cout << "y is not 7. Sorry about that.";
What will be the result of this section of code.
a. cout << "y is not 7. Sorry about that.";
b. cout << " y is 7. How lucky of you. "; //will always execute regardless of the value of y
c. y=7 is an assignment and not a comparison will not compile
d. I was texting in class and have no absolutely no idea.
e. This will compile but completely skip both statements.
if ( y = 7 )
cout << " y is 7. How lucky of you. ";
else
cout << "y is not 7. Sorry about that.";
What will be the result of this section of code.
a. cout << "y is not 7. Sorry about that.";
b. cout << " y is 7. How lucky of you. "; //will always execute regardless of the value of y
c. y=7 is an assignment and not a comparison will not compile
d. I was texting in class and have no absolutely no idea.
e. This will compile but completely skip both statements.
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 012
Putting a semicolon after the if (expression) is a common mistake and will lead to a compiler error
if (x>y);
temp++;
a. false
b. today's compilers are smart enough and will remove the semi-colon
c. you'll get a warning message but the compiler knows what you mean
d. true
if (x>y);
temp++;
a. false
b. today's compilers are smart enough and will remove the semi-colon
c. you'll get a warning message but the compiler knows what you mean
d. true
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 011
In C++, you can only have one statement following a relational test?
a. true
b. false
a. true
b. false
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 010
if (expression)
statement;
else
statement;
Does the above work in C++?
a. true
b. false
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 009
How do you write an "if" statement in C++? Which sample below is the best
a.
if (x >y) then
{
tmp++;
}
b.
if ( x >y )
tmp++;
c.
if x>y
tmp++
else
tmp--;
d.
None of the above. They won't compile
a.
if (x >y) then
{
tmp++;
}
b.
if ( x >y )
tmp++;
c.
if x>y
tmp++
else
tmp--;
d.
None of the above. They won't compile
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 008
What is the value of the relation expression below, given that x is 5 and y is 1. z is a bool.
z = x < y;
a. true
b. false
c. 1
d. 0
e. None of the above, you can't assign result of expression, only test it
z = x < y;
a. true
b. false
c. 1
d. 0
e. None of the above, you can't assign result of expression, only test it
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 007
(bonus question) How does C++ handle true or false with regards to storing these values. Mark all that apply, if any
a. only a 1 is equal to true.
b. only 0 is considered true.
c. a 0 is considered false.
d. anything other than 0 is considered true.
e. None of the above, they are stored as T or F.
Remember the lecture from Monday on making decisions and you'll do fine.
a. only a 1 is equal to true.
b. only 0 is considered true.
c. a 0 is considered false.
d. anything other than 0 is considered true.
e. None of the above, they are stored as T or F.
Remember the lecture from Monday on making decisions and you'll do fine.
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 006
In the following, what is the value of the expression given that the value of x is 5?
x == 5
a. x
b. 5
c. false
d. true
x == 5
a. x
b. 5
c. false
d. true
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 005
What does the ! (exclamation symbol) mean in c++?
a. It tells the compiler to check this condition first
b. It means not or the opposite of what the comparison is.
c. It is a shortcut so you don't have to enter 'true' or a relational comparison operator
d. None of the above
a. It tells the compiler to check this condition first
b. It means not or the opposite of what the comparison is.
c. It is a shortcut so you don't have to enter 'true' or a relational comparison operator
d. None of the above
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 004
What is the difference between = and == in C++?
a. They are the same but the == makes it more visible to the programmer
b. == is used to assign a value to a variable and = is used to compare.
c. = is used to assign a value to a variable.
d. == is used for comparison and = is used to assign
a. They are the same but the == makes it more visible to the programmer
b. == is used to assign a value to a variable and = is used to compare.
c. = is used to assign a value to a variable.
d. == is used for comparison and = is used to assign
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 003
How do you write "greater than or equal to" test in c++?
a. gte
b. > or =
c. >=
d. > && =
a. gte
b. > or =
c. >=
d. > && =
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 002
What does x <= y mean?
a. x is less than y
b. x is less than or equal to y
c. assign the value of y to x if x less than
d. none of the above
a. x is less than y
b. x is less than or equal to y
c. assign the value of y to x if x less than
d. none of the above
Exericse Number
Chapter 04,
Quiz
Chapter 4 Quiz Starting Out With C++ 001
Which of the following is not a relational operator?
a. ==
b. >
c. <
d. =
a. ==
b. >
c. <
d. =
Exericse Number
Chapter 04,
Quiz
Chapter 3 Quiz Starting Out With C++ 040
What is the purpose of flowcharting?
a. plan out the program before coding
b. Mr. Daniels likes pretty symbols
c. visual display of the program
d. all of the above
a. plan out the program before coding
b. Mr. Daniels likes pretty symbols
c. visual display of the program
d. all of the above
Chapter 3 Quiz Starting Out With C++ 039
How to you get a random number in C++?
a. x=rnd();
b. x=random();
c. x=rand();
d. x=randomNum();
a. x=rnd();
b. x=random();
c. x=rand();
d. x=randomNum();
Chapter 3 Quiz Starting Out With C++ 038
C++ has a runtime library for performing math?
a. True
b. False
a. True
b. False
Chapter 3 Quiz Starting Out With C++ 037
The cin.ignore function tells the cin object to skip one or more characters in the keyboard buffer.
a. True
b. False
a. True
b. False
Chapter 3 Quiz Starting Out With C++ 035
What does getline do?
a. reads an entire line including whitespaces
b. reads an entire line except whitespaces
c. a whole word
d. none of the above
a. reads an entire line including whitespaces
b. reads an entire line except whitespaces
c. a whole word
d. none of the above
Chapter 3 Quiz Starting Out With C++ 034
What are whitespace characters?
a. spaces
b. spaces and tabs only
c. spaces, tabs, or line breaks
d. none of the above
a. spaces
b. spaces and tabs only
c. spaces, tabs, or line breaks
d. none of the above
Chapter 3 Quiz Starting Out With C++ 033
Which of the following statements will display the following result if x is 123.4?
123.400
a. cout << setprecision(6) << showpoint << x << endl;
b. cout << setw(6) << x << endl;
c. cout << showpoint << x << endl;
d. cout << showpoint(3) << x << endl;
123.400
a. cout << setprecision(6) << showpoint << x << endl;
b. cout << setw(6) << x << endl;
c. cout << showpoint << x << endl;
d. cout << showpoint(3) << x << endl;
Chapter 3 Quiz Starting Out With C++ 032
What do you use to print digits in fixed-point notation or decimal?
a. setprecision
b. setw
c. fixedpoint
d. fixed
a. setprecision
b. setw
c. fixedpoint
d. fixed
Chapter 3 Quiz Starting Out With C++ 031
You can control the number of significant digits with which floating-point values are displayed by using the
a. setw
b. significant
c. setprecision
d. cast
a. setw
b. significant
c. setprecision
d. cast
Chapter 3 Quiz Starting Out With C++ 030
setw
a. sets the width of the screen
b. establishes print fields of a specified width
c. sets the precision of the variable
d. None of the above
a. sets the width of the screen
b. establishes print fields of a specified width
c. sets the precision of the variable
d. None of the above
Chapter 3 Quiz Starting Out With C++ 029
_____ provides a way to output data and _____ allows for input of data
a. cin, cout
b. input, output
c. cout, cin
d. output, input
a. cin, cout
b. input, output
c. cout, cin
d. output, input
Chapter 3 Quiz Starting Out With C++ 028
Will the following produce the same result?
x *= 5 x = x * 5
a. True
b. False
x *= 5 x = x * 5
a. True
b. False
Chapter 3 Quiz Starting Out With C++ 027
What does the value of x in the code fragment below?
c = 5;
x = 5 * (c++);
a. 6
b. 25
c. 30
d. 0 (since c++ has not been defined
c = 5;
x = 5 * (c++);
a. 6
b. 25
c. 30
d. 0 (since c++ has not been defined
Chapter 3 Quiz Starting Out With C++ 026
Is the following a valid assignment?
x = y = z = 10;
a. True
b. False
x = y = z = 10;
a. True
b. False
Chapter 3 Quiz Starting Out With C++ 024
What is type casting in C++
a. manually promoting or demoting a value
b. forcing an integer to hold a double or float
c. making it possible to add two different type variables to be added
d. None of the above
a. manually promoting or demoting a value
b. forcing an integer to hold a double or float
c. making it possible to add two different type variables to be added
d. None of the above
Chapter 3 Quiz Starting Out With C++ 023
What is an Overflow
a. When you try to use a value larger the the data type of the variable
b. When the computer runs out of memory
c. When a variable is uninitialized
d. None of the above
a. When you try to use a value larger the the data type of the variable
b. When the computer runs out of memory
c. When a variable is uninitialized
d. None of the above
Chapter 3 Quiz Starting Out With C++ 022
In C++, if you divide the integers 7 by 2 the answer will be
a. 3.5
b. 3
c. 2
d. undefined since the answer is a float
a. 3.5
b. 3
c. 2
d. undefined since the answer is a float
Chapter 3 Quiz Starting Out With C++ 021
When the final value of an expression is assigned to a variable, it will be converted
to the data type of that variable.
a. True
b. False
to the data type of that variable.
a. True
b. False
Chapter 3 Quiz Starting Out With C++ 020
When an operator works with two values of different data types, the lower-ranking
value is promoted to the type of the higher-ranking value.
a. True
b. False
value is promoted to the type of the higher-ranking value.
a. True
b. False
Chapter 3 Quiz Starting Out With C++ 019
chars, shorts, and unsigned shorts are automatically promoted to type int.
a. True
b. False
a. True
b. False
Chapter 3 Quiz Starting Out With C++ 018
What happens in C++ when operator's operands are of different types?
a. Nothing
b. C++ will convert to the same data type
c. C++ will convert to the largest data type
d. C++ will convert to the lowest data type
a. Nothing
b. C++ will convert to the same data type
c. C++ will convert to the largest data type
d. C++ will convert to the lowest data type
Chapter 3 Quiz Starting Out With C++ 017
To calculate the average of two numbers in C++
a. x + y/2
b. (x + y)/2
c. x/2 + y
d. All of the above
a. x + y/2
b. (x + y)/2
c. x/2 + y
d. All of the above
Chapter 3 Quiz Starting Out With C++ 016
How do you do exponents in C++ for 2.0 raised to 4.0
a. 2.0^4.0
b. pow(2.0, 4.0)
c. 2.0*4.0
d. None of the above
a. 2.0^4.0
b. pow(2.0, 4.0)
c. 2.0*4.0
d. None of the above
Chapter 3 Quiz Starting Out With C++ 015
How do you write the sum of X plus Y divided by Z in C++
a. x + y/z
b. (x +y)/z
c. X + Y/Z
d. (X + Y)/Z
a. x + y/z
b. (x +y)/z
c. X + Y/Z
d. (X + Y)/Z
Chapter 3 Quiz Starting Out With C++ 014
In the following expression what is the answer
6 * (2 + 4) - 5
a. 11
b. 31
c. 6
d. None of the above
6 * (2 + 4) - 5
a. 11
b. 31
c. 6
d. None of the above
Chapter 3 Quiz Starting Out With C++ 013
What has the lowest precedence?
a. * (asterick)
b. / (division)
c. + (plus)
d. - (unary negation)
a. * (asterick)
b. / (division)
c. + (plus)
d. - (unary negation)
Chapter 3 Quiz Starting Out With C++ 012
What is operator precedence?
a. What numbers will be processed first.
b. What expressions are stored before others
c. Some types are stored higher in memory
d. Some operators are evaluated before others
a. What numbers will be processed first.
b. What expressions are stored before others
c. Some types are stored higher in memory
d. Some operators are evaluated before others
Subscribe to:
Posts (Atom)