Tue/False
1
. Using the >> operator, a floating point data value may be read into an int variable.
2. The single statement
cin >> alpha >> beta;
may be used in place of the two statements
cin >> alpha;
cin >> beta;
3. The input statement
cin >> someInt;
could also be written as
someInt << cin;
4. In the statement
cin >> XXXXX;
the XXXXX must be a variable name, not a constant or arbitrary expression.
5. In the function call
cin.get(XXXXX);
the XXXXX must be a variable name, not a constant or arbitrary expression.
6. Assuming no input errors, an execution of the
>> operator leaves the reading marker at the character immediately following the last data item read.
7. When working at the keyboard, the user generates a newline character by pressing the Enter or Return key.
8. If the reading marker is in the middle of an input line of 25 characters, execution of the statement
cin.ignore(500, '\n');
leaves the reading marker at the character following the next newline character.
9. The
>> operator skips leading whitespace characters when looking for the next data value in the input stream.
10. If a C++ program attempts to input invalid data, the computer system immediately terminates the program and displays an error message.
11. Reading input from a file is considered interactive I/O because the CPU is required to interact with a disk drive or other device.
12. Reading input from a keyboard is considered interactive I/O because the user is communicating directly with the computer.
13. Using an editor program to edit a file requires interactive I/O.
14. The problem-solving phase of programming includes both analysis and design.
15. Top-down design focuses on actions and algorithms, whereas object-oriented design focuses on entities (objects) and their associated operations.
Multiple Choice
16. 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
17. 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
18. Which of the following is a valid input statement?
a. cin >> studentAge;
b. cin << studentAge;
c.
studentAge >> cin;
d. studentAge << cin;
e. a and c above
19. Which of the following statements sends a newline character to the standard output device?
a. cout << endl;
b.
cout << '\n';
c.
cout << \n;
d. a and b above
e. a, b, and c above
20. 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
21. An input line consists of a person's first and last initials, separated by a blank:
M H
Which of the following correctly inputs the person's initials into the
char variables firstInit and lastInit?
a. cin >> firstInit >> lastInit;
b. cin >> firstInit >> ' ' >> lastInit;
c.
cin >> firstInit;
cin.ignore(1, '\n');
cin >> lastInit;
d. b and c above
e. a and c above
22. 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
23. Given the three lines of input data
111 222 333
444 555 666
777 888 999
what value is read into
gamma by the following code? (All variables are of type int.)
cin >> alpha;
cin.ignore(500, '\n');
cin >> beta >> gamma;
a. 333
b. 444
c. 555
d. 777
e. none of the above
24. 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;
a. 'B'
b. '\n'
c. 'C'
d. 'D'
e. none of the above
25. 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.get(ch1);
cin.get(ch2);
cin.get(ch3);
a. 'B'
b. '\n'
c. 'C'
d. 'D'
e. none of the above
26. Given the line of input data
123.456 A 789
what value is read into
inputChar by the following code? (alpha and beta are of type int, and inputChar is of type char.)
cin >> alpha >> in Ù
Ù
Ù
Document Error Ù
Ù
Ù
utChar >> beta;
‘ ‘ (blank)
‘A’
‘.’ (period)
‘4’
none of the above
- Which of the following is considered interactive I/O?
- Scanning a file of employee records and printing the names of salaried employees.
- Entering sales records into a file in response to prompts from the computer program.
- Reading a file of numbers and printing their average.
- A, b, and c above.
- Which of the following is not a reason for using batch I/O?
- A large amount of input data is expected.
- The input data can be prepared ahead of time.
- Input prompts can be tailored to the experience level of the user.
- The output data can be examined at the user’s leisure.
- The output from one program can be used as the input to another.
- Which of the following is not one of the things a programmer must do in order to use files in a C++ program?
- Use a preprocessor directive to include the header file
fstream.h.
Declare each file stream in a variable declaration.
Prepare each file for reading or writing by calling the open function.
Specify the name of the file stream in each input or output statement that uses it.
Erase the contents of each output file before running the program.
- When used with an input file stream, which of the following statements about the
open function is false?
- It associates the name of a stream variable with the name of a physical disk file.
- It puts the stream into the fail state if the file does not already exist.
- It sets the reading marker at the first character in the file.
- It creates a new, empty file if the file does not already exist.
- None of the above.
- When used with an output file stream, which of the following statements about the
open function is false?
- It associates the name of a stream variable with the name of a physical disk file.
- It erases the old contents of the file if the file already exists.
- It sets the writing marker at the beginning of the file.
- It creates a new, empty file if the file does not already exist.
- None of the above.
- What happens when a C++ input stream enters the fail state?
- The system displays an error message, and program execution is terminated.
- The system displays an error message, the program continues running, and further input operations with that stream are ignored.
- The system does not display an error message, and program execution is terminated.
- The system does not display an error message, the program continues running, and further input operations with that stream are ignored.
- None of the above.
- Which of the following statements about object-oriented design (OOD) is false?
- OOD focuses on entities (objects) nad operations on those objects.
- The first step in OOD is to identify the major objects in the problem, together with their associated operations.
- In OOD, data plays a secondary role in support of actions to be performed.
- Object-oriented programming languages have been developed specifically to support OOD.
- OOD and top-down design can be used in combination with each other to solve problems.
Fill-In
- In a C++ input statement, the extraction operator is written as the pair of symbols_____________________.
- Blanks and newline characters in an input stream are examples of ____________________ characters.
- In a C++ program, the newline character is denoted by the pair of symbols_____________________.
- The C++ standard library defines a data type named _____________________
that represents a stream of characters coming from an input file.
- The C++ standard library defines a data type named______________________
that represents a stream of characters going to an output file.
- Once a C++ I/O stream has entered the _________________________ state, any
further operations using that stream are considered to be null operations.
- A(n) ______________________ is a printed message that explains what the user should enter as input.
- __________________________ is the act of printing out all of the input values so that the user can verify that they were entered correctly.
- __________________________ is a technique for developing a program in which the problem is divided into more easily handled subproblems, the solutions of which create a solution to the overall problem.
- Implementing a design is easier if you write the steps in _____________________, which is a mixture of English statements and C++ like control structures.
- In the problem-solving phase of programming, a(n) _________________________ is a self-contained collection of steps that solves a problem or subproblem.
- __________________________ is a property of a module that performs exactly the same operation as the higher-level abstract step it defines.
- In essence, the concept of _________________________ means that a module should do just one thing and do it well.
- When a top-down design is implemented as one long sequence of steps, it is called a(n) _________________________ implementation.
- In top-down design, a(n) ___________________________ is a diagram of the hierarchical structure of the solution.
- __________________________ is a technique for developing a program in which the solution is expressed in terms of objects—self-contained entities composed of data and operations on the data.
- In an object-oriented programming language, a(n) __________________________
is a programmer-defined data type from which objects are created.
- Program code is said to be ____________________________ if it contains meaningful identifiers and judiciously used clarifying comments.