CSIS 111 Test 2

Ace your homework & exams now with Quizwiz!

e

A value can be stored into a variable by execution of: A. an input statement B. an output statement C. an assignment statement D. a and b above E. a and c above

25

After execution of the following code, what will be the value of angle if the input value is 0? cin >> angle; if (angle > 5) angle = angle + 5; else if (angle > 2) angle = angle + 10;

15

After execution of the following code, what will be the value of angle if the input value is 0? cin >> angle; if (angle > 5) angle = angle + 5; else if (angle > 2) angle = angle + 10; else angle = angle + 15;

no output

Assuming alpha and beta are int variables, what is the output of the following code (which is indented poorly)? alpha = 3; beta = 2; if (alpha < 2) if (beta == 3) cout << "Hello"; else cout << "There";

none of above

Consider the following If statement, which is syntactically correct but uses poor style and indentation: if (x >= y) if (y > 0) x = x * y; else if (y < 4) x = x - y; Assume that x and y are int variables containing the values 3 and 9, respectively, before execution of the above statement. After execution of the statement, what value will x contain?

e

Given the constant declaration const int FACTOR = 95; which of the following is not a valid use of FACTOR A. cout << FACTOR * 3; B. FACTOR = 24; C. cin >> FACTOR; D. a and c above E. b and c above

c

Given the two lines of input data A B CDE what value is read into ch3 by the following code? (All variables are of type char.) cin >> ch1 >> ch2 >> ch3;

b

Given the two lines of input data ABC DEF what value is read into ch by the following code? (str is of type string, and ch is of type char.) cin >> str; cin.get(ch); A. 'B' B. ' ' (blank) C. 'C' D. 'D' E. none of the above

d

Given the two lines of input data ABC DEF what value is read into ch by the following code? (str is of type string, and ch is of type char.) getline(cin, str); cin.get(ch);

a

If DeMorgan's Law is used to negate the expression (i < j) && (k == l) then the result is A. (i >= j) || (k != l) B. (i < j) || (k == l) C. (i >= j) && (k != l) D. (i > j) && (k != l) E. (i > j) || (k != l)

c

If p is a Boolean variable, which of the following logical expressions always has the value false? A. p && p B. p || p C. p && !p D. p || !p E. b and d above

c

If we want a program to use file I/O for reading or writing, the following four things must be done EXCEPT A. Request the preprocessor to include the header file fstream. B. Specify the name of the file stream in each input or output statement C. Ensure that each individual file to be read or written contains a strictly limited amount of data. D. Prepare each file for reading or writing by using a function named open. E. Use declaration statements to declare the file streams we will use

a

Indicate where (if at all) the following loop needs a priming read. count = 1; // Line 1 while (count <= 10) // Line 2 { // Line 3 cin >> number; // Line 4 cout << number * 2; // Line 5 count++; // Line 6 } // Line 7 A. No priming read is necessary. B. between lines 5 and 6 C. between lines 1 and 2 D. between lines 3 and 4 E. between lines 6 and

between lines 1 and 2

Indicate where (if at all) the following loop needs a priming read. sum = 0; // Line 1 while (inFile) // Line 2 { // Line 3 sum = sum + number; // Line 4 inFile >> number; // Line 5 } // Line 6

c

This question is about short-circuit evaluation of logical expressions. Consider the following expression in some imaginary programming language (not C++): (N > 5) AND (K / N < 12) If N equals 0 when this expression is evaluated, which of the following statements about the expression is true? A. It causes a divide-by-zero error whether or not the language uses short-circuit evaluation. B. It never causes a divide-by-zero error. C. It causes a divide-by-zero error only if the language does not use short-circuit evaluation. D. It causes a divide-by-zero error only if the language uses short-circuit evaluation

true

True or False? A hierarchical implementation of a functional decomposition is one in which some or all of the modules are implemented as separate C++ functions.

true

True or False? A program is said to be robust if it can recover from erroneous input and keep running

true

True or False? An example of a logical (Boolean) expression is an arithmetic expression followed by a relational operator followed by an arithmetic expression.

false

True or False? An infinite loop is one in which the While expression always has the value false

true

True or False? Assuming no input errors, an execution of the >> operator leaves the reading marker at the character immediately following the last data item read

false

True or False? Boolean variables cannot store the result of a comparison of two variables

false

True or False? Boolean variables cannot store the result of a comparison of two variables.

true

True or False? Functional decomposition focuses on actions and algorithms, whereas object-oriented design focuses on entities (objects) and their associated operations

true

True or False? Given the module description PRINT AVERAGE (Level 1) Print a heading Print sumOfValues / countOfValues the following is an appropriate module precondition: "sumOfValues is assigned AND countOfValues does not equal 0."

true

True or False? If P and Q are logical expressions, the expression P AND Q is TRUE if either P or Q is TRUE or both are TRUE

true

True or False? If a C++ If statement begins with if (age = 30) the If condition is an assignment expression, not a relational expression

false

True or False? If a C++ program attempts to input invalid data, the computer system immediately terminates the program and displays an error message

false

True or False? If a C++ program attempts to input invalid data, the computer system immediately terminates the program and displays an error message.

false

True or False? If a While loop's termination condition becomes true in the middle of the loop body, the loop is exited immediately

true

True or False? If ch1 contains the value 'C' and ch2 contains the value 'K', the value of the C++ expression ch1 <= ch2 is true.

true

True or False? If you examine a problem and find that it is natural to think about it in terms of a collection component parts, the you should use object-oriented design (OOD), rather than functional decomposition to solve it

false

True or False? Implementing a test plan guarantees that a program is completely correct

false

True or False? In a functional decomposition, a concrete step is one in which some of the implementation details remain unspecified.

true

True or False? In testing a loop, one tries to devise data sets that leave the files in improper states that violate either the loop postcondition (an assertion that must be true immediately after the loop exit) or the postcondition of the module containing the loop.

truep

True or False? In testing a loop, one tries to devise data sets that leave the files in improper states that violate either the loop postcondition (an assertion that must be true immediately after the loop exit) or the postcondition of the module containing the loop.

false

True or False? In testing a loop, one tries to devise data sets that would never cause the variables to go out of range

true

True or False? In the design of a flag-controlled loop, the loop condition is initialized by giving the flag variable an initial value of true or false, whichever is appropriate

true

True or False? In the function call cin.get(XXXXX); the XXXXX must be a variable name, not a constant or arbitrary expression

true

True or False? In the statement cin >> XXXXX; the XXXXX must be a variable name, not a constant or arbitrary expression

true

True or False? It is possible for the body of a While statement never to be executed

false

True or False? Most C++ programs are written for noninteractive I/O (input/Output) use

true

True or False? Nested loops themselves can contain nest loops, which also can contain nested loops and so on.

false

True or False? Reading input from a file is considered interactive I/O because the CPU is required to interact with a disk drive or other device

true

True or False? Syntactically, the only expressions that can be assigned to Boolean variables are the literal values true and false

false

True or False? Testing is performed only in the implementation phase of a program's life cycle

true

True or False? The code segment if (speed <= 40) cout << "Too slow"; if (speed > 40 && speed <= 55) cout << "Good speed"; if (speed > 55) cout << "Too fast"; could be written equivalently as if (speed <= 40) cout << "Too slow"; else if (speed <= 55) cout << "Good speed"; else cout << "Too fast";

false

True or False? The expression !(n < 5) is equivalent to the expression n > 5

true

True or False? The following represents a list showing the correct order of precedence (from highest to lowest) for the arithmetic, relational, and logical operators with the assignment operator included as well. ! Unary + Unary - ∗ / % + - < <= > >= == != && || =

true

True or False? The logical order of statements in a program may be different from their physical order

true

True or False? The number of steps performed by an O(N) algorithm is directly proportional to the number of data values that are processed

true

True or False? The problem-solving phase of programming includes both analysis and design

true

True or False? The term "complexity" is a measure of the effort expended by the computer in performing a computation

false

True or False? The termination condition for the While loop while (loopCount < 9) { cout << loopCount << endl; loopCount++; } is loopCount > 9.

true

True or False? To test whether someInt equals 25 or 30, the C++ expression someInt == 25 || 30 has the correct semantics but produces a syntax (compile-time) error

true

True or False? Using an editor program to edit a file requires interactive I/O.

false

True or False? Using the >> operator, a floating-point data value may be read into an int variable

false

True or False? When a While expression evaluates to false, the loop terminates and control goes back to the statement immediately before the While statement.

d

What does the following statement print? (All variables are of type int.) if (j < k) if (k < j) cout << 1; else cout << 2; else if (j < k) cout << 3; else cout << 4; A. It always prints 4. B. It prints 2 if j equals k and 4 otherwise. C. It prints 2 if j < k and 1 if k <= j. D. It prints 2 if j < k and 4 otherwise. E. It prints nothing unless j equals k

d

What happens when a C++ input stream enters the fail state? A. The system displays an error message, and program execution is terminated. B. The system displays an error message, the program continues running, and further input operations with that stream are ignored. C. The system does not display an error message, and program execution is terminated. D. The system does not display an error message, the program continues running, and further input operations with that stream are ignored. E. none of the above

a

What is the missing If condition in the following code fragment? The program is supposed to halt if the input file does not exist. ifstream inFile; inFile.open("myfile.dat"); if ( ) { cout << "Cannot open input file." << endl; return 1; } A. !inFile B. inFile != myfile.dat C. myfile.dat D. !myfile.dat E. inFile

larry curly

What is the output of the following code fragment if the input value is 20? (Be careful here.) cin >> someInt; if (someInt > 30) cout << "Moe "; cout << "Larry "; cout << "Curly";

1 2 3 4

What is the output of the following code fragment? n = 1; while (n < 5) { cout << n << ' '; n++; }

d

What is the output of the following code fragment? n = 1; while (n <= 5) { cout << n << ' '; n++; } A. 2 3 4 5 B. 1 2 3 4 5 C. 2 3 4 5 6 D. 1 1 1 forever E. 1 2 3

2 3 4 5 6

What is the output of the following code fragment? n = 1; while (n <= 5) { n++; cout << n << ' '; }

10

What is the output of the following code fragment? (All variables are of type int.) sum = 0; outerCount = 1; while (outerCount <= 3) { innerCount = 1; while (innerCount <= outerCount) { sum = sum + innerCount; innerCount++; } outerCount++; } cout << sum << endl;

d

When used with an input file stream, which of the following statements about the open function is false? A. It associates the name of a stream variable with the name of a physical disk file. B. It puts the stream into the fail state if the file does not already exist. C. It sets the reading marker at the first character in the file. D. It creates a new, empty file if the file does not already exist. E. none of the above

e

When used with an output file stream, which of the following statements about the open function is false? A. It associates the name of a stream variable with the name of a physical disk file. B. It erases the old contents of the file if the file already exists. C. It sets the writing marker at the beginning of the file. D. It creates a new, empty file if the file does not already exist. E. none of the above

d

Which C++ logical expression correctly determines whether the value of beta lies between 0 and 100? A. 0 < beta < 100 B. 0 < beta && beta < 100 C. (0 < beta) && (beta < 100) D. b and c above E. a, b, and c above

b

Which of the following code segments could be used to skip the first two characters of an input line (they may or may not be whitespace characters) and input the integer value that comes next? (Variable dummy is of type char, and inputInt is of type int.) A. cin >> dummy >> dummy >> inputInt; B. cin.get(dummy); cin.get(dummy); cin >> inputInt; C. cin >> inputInt; D. cin.get(' '); cin.get(' '); cin >> inputInt; E. a and c above

b

Which of the following does not constitute a logical (Boolean) expression? A. an arithmetic expression followed by a relational operator followed by an arithmetic expression B. an arithmetic expression followed by a logical operator followed by an arithmetic expression C. a Boolean variable or constant D. a logical expression followed by a binary logical operator followed by a logical expression E. a unary logical operator followed by a logical expression

a

Which of the following is considered interactive I/O? A. scanning a file of employee records and printing the names of salaried employees B. entering sales records into a file in response to prompts from the computer program C. reading a file of numbers and printing their average D. a, b, and c above

e

Which of the following is not a reason for using batch I/O? A. The output data can be examined at the user's leisure. B. The input data can be prepared ahead of time. C. The output from one program can be used as the input to another. D. A large amount of input data is expected. E. Input prompts can be tailored to the experience level of the user.

b

Which of the following is not one of the things a programmer must do in order to use files in a C++ program? A. Prepare each file for reading or writing by calling the open function. B. Erase the contents of each output file before running the program. C. Declare each file stream in a variable declaration. D. Use a preprocessor directive to include the header file fstream. E. Specify the name of the file stream in each input or output statement that uses it.

a

Which of the following statements about C++ stream input is true? A. When an integer data value is read into a float variable, the value is first converted into floating-point form. B. When an integer data value is read into a float variable, the float variable becomes an int variable. C. It is an error to read an integer data value into a float variable. D. Input of a floating-point data value stops when a decimal point is encountered. E. c and d above

b

Which of the following statements about functional decomposition is false? A. Modules are the basic building blocks of functional decomposition. B. Each level of a solution tree is more abstract (less detailed) than the level above it. C. A module can contain both abstract steps and concrete steps. D. A concrete step is a step that can be translated directly into C++ code. E. none of the above

e

Which of the following would be a poor choice for a sentinel value? A. a value of 999 for voterAge B. a value of 1 for testScore C. a value of 13 for birthdayMonth D. a value of 75 for carSpeed E. b and d above

d

Which type of loop would be most appropriate for solving the problem 'Count the number of positive integers in a data file of unknown length'? A. a count-controlled loop B. a flag-controlled loop C. a sentinel-controlled loop D. an EOF-controlled loop E. either b or c above

a count controlled loop

Which type of loop would be most appropriate for solving the problem 'Input an integer value, then print 'Happy Birthday' that many times'?

e

Which type of loop would be most appropriate for solving the problem 'Print every other input character until the character '@' is encountered'? A. a count-controlled loop B. a flag-controlled loop C. a sentinel-controlled loop D. an EOF-controlled loop E. either b or c above

the initialization of the loop control variable

With respect to the loop in the following main function, what is missing? int main() { int loopCount; while (loopCount <= 8) { cout << "Hi"; loopCount++; } return 0; }

flag controlled loop

a flag is a Boolean variable that is used to control the logical flow of a program. true and false.

count controlled loop

a loop that specifies a specified number of times

sentinel controlled loop

a priming read may be the only initialization necessary

priming read

is the reading of one set of data before the loop to initialize the variables in the expression


Related study sets

Visual Communication Fall 2017 Weber Exam 1

View Set

Paramedic Jb Learning All Chapter Exams

View Set

Chapter 13 Anatomy and Physiology

View Set

9.REF/moratorium/recasting/short sale addendum/ chapter 11/foreclosure by advertisement/entry&possession/write of entry/deficiency judgement/reduction act/recourse clause/depreciation value/notice of default levy/ redemption period/reinstatement

View Set

Nursing Care of the Child With an Alteration in Bowel Elimination/Gastrointestinal Disorder

View Set

Econ 202 Test Review (Quizzes 9-12)

View Set

Ch.11 Making Alliances & Acquisitions

View Set