Deck 14: File Processing
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/19
Play
Full screen (f)
Deck 14: File Processing
1
To write fixed-length records, use file open mode:
A) ios::app
B) ios::ate
C) ios::trunc
D) ios::binary
A) ios::app
B) ios::ate
C) ios::trunc
D) ios::binary
D
2
Which of the following is not true about files?
A) C++ views each file as a sequential stream of bytes.
B) Files are opened by creating objects of stream classes.
C) Member functions of stream objects can be applied to file streams.
D) istream, ostream and iostream are derived from ifstream, ofstream and fstream, respectively.
A) C++ views each file as a sequential stream of bytes.
B) Files are opened by creating objects of stream classes.
C) Member functions of stream objects can be applied to file streams.
D) istream, ostream and iostream are derived from ifstream, ofstream and fstream, respectively.
D
3
Which of the following does not have a stream associated with it?
A) cerr.
B) cin.
C) cout.
D) All of the above have streams associated with them.
A) cerr.
B) cin.
C) cout.
D) All of the above have streams associated with them.
C
4
Which of the following will not change the file-position pointer to the same position as the others? Assume a 10-byte file size and a current position at byte # 1.
A) fileObject.seekg(2);
B) fileObject.seekg(1, ios::cur);
C) fileObject.seekg(2, ios::beg);
D) fileObject.seekg(8, ios::end);
A) fileObject.seekg(2);
B) fileObject.seekg(1, ios::cur);
C) fileObject.seekg(2, ios::beg);
D) fileObject.seekg(8, ios::end);
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
5
Random access files are more effective than sequential files for:
A) Instant access to data.
B) Updating data easily.
C) Inserting data into the file without destroying other data.
D) All of the above.
A) Instant access to data.
B) Updating data easily.
C) Inserting data into the file without destroying other data.
D) All of the above.
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
6
What is not true about this code segment? location = fileObject.tellg();
A) tellg is a member function of fileObject.
B) location is a pointer.
C) The value of location after the segment executes must be less than or equal to the number of bytes in the file attached to fileObject.
D) fileObject is an istream object.
A) tellg is a member function of fileObject.
B) location is a pointer.
C) The value of location after the segment executes must be less than or equal to the number of bytes in the file attached to fileObject.
D) fileObject is an istream object.
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
7
Which of the following functions would not be used to write data randomly to a random access file?
A) tellg
B) seekp
C) write
D) All of the above would be used.
A) tellg
B) seekp
C) write
D) All of the above would be used.
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
8
Which file open mode would be used to write data only at the end of an existing file?
A) ios::app
B) ios::in
C) ios::out
D) ios::trunc
A) ios::app
B) ios::in
C) ios::out
D) ios::trunc
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
9
Select the false statement.
A) C++ imposes no structure on a file.
B) C++ files include information about their structure.
C) The programmer must impose a structure on a file.
D) C++ files do not understand notions such as "records" and "fields."
A) C++ imposes no structure on a file.
B) C++ files include information about their structure.
C) The programmer must impose a structure on a file.
D) C++ files do not understand notions such as "records" and "fields."
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
10
The new C++14 stream manipulator ________ enables a program to read quoted text from a stream, including any white space characters in the quoted text, and discards the double quote delimiters. For example, if we read 100 "Janie Jones" 24.98
Using
InClientFile>> account>> quoted(name)>> balance;
The first stream extraction reads 100 into the int variable account, the second reads Janie Jones as one string and stores it in the string variable name without the double-quote delimiters, and the third stream extraction reads 24.98 into the double variable balance.
A) discard
B) quoted
C) hide
D) literal
Using
InClientFile>> account>> quoted(name)>> balance;
The first stream extraction reads 100 into the int variable account, the second reads Janie Jones as one string and stores it in the string variable name without the double-quote delimiters, and the third stream extraction reads 24.98 into the double variable balance.
A) discard
B) quoted
C) hide
D) literal
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
11
Select the false statement. The write function:
A) Creates unformatted data.
B) Expects data type const char* as its first argument.
C) Writes to files in hexadecimal format.
D) Takes an argument of type size_t.
A) Creates unformatted data.
B) Expects data type const char* as its first argument.
C) Writes to files in hexadecimal format.
D) Takes an argument of type size_t.
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
12
Select the proper object type. __________ file("file.dat", ios::in | ios::out);
A) iostream
B) fstream
C) ofstream
D) ifstream
A) iostream
B) fstream
C) ofstream
D) ifstream
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
13
A random access file is organized most like a(n):
A) Array.
B) Object.
C) Class.
D) Pointer.
A) Array.
B) Object.
C) Class.
D) Pointer.
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
14
In order to perform file processing in C++, which header files must be included?
A) , and .
B) and .
C) and .
D) and .
A)
B)
C)
D)
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
15
For an ifstream object A, a class type B and a local variable of type B called C, the proper way to read in one B object from A into C is:
A) A.read(&C, sizeof(B));
B) A.read(reinterpret_cast(&C), sizeof(B));
C) A.read(reinterpret_cast(&C), B);
D) A.read(char* (&C), sizeof(B));
A) A.read(&C, sizeof(B));
B) A.read(reinterpret_cast
C) A.read(reinterpret_cast
D) A.read(char* (&C), sizeof(B));
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
16
Select the false statement. The reinterpret_cast operator:
A) Changes the value of the object to which its operand points.
B) Performs its operation at compile time.
C) Is compiler-dependent and can cause programs to behave differently on different platforms.
D) Is easy to use to perform dangerous manipulations that could lead to serious execution-time errors.
A) Changes the value of the object to which its operand points.
B) Performs its operation at compile time.
C) Is compiler-dependent and can cause programs to behave differently on different platforms.
D) Is easy to use to perform dangerous manipulations that could lead to serious execution-time errors.
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
17
When used with ofstream objects, operator! is not:
A) Overloaded.
B) Used to determine if the open operation succeeded.
C) Used to close a file explicitly.
D) Used to return a nonzero value if an error occurs.
A) Overloaded.
B) Used to determine if the open operation succeeded.
C) Used to close a file explicitly.
D) Used to return a nonzero value if an error occurs.
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
18
Which of the following statements is true?
A) When opening a file, you can specify the name of the file only as a pointer-based string.
B) When opening a file, you can specify the name of the file only as a string object.
C) When opening a file, you can specify the name of the file as either a pointer-based string or a string object.
D) None of the above.
A) When opening a file, you can specify the name of the file only as a pointer-based string.
B) When opening a file, you can specify the name of the file only as a string object.
C) When opening a file, you can specify the name of the file as either a pointer-based string or a string object.
D) None of the above.
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
19
Which of the following is not a disadvantage of trying to modify a sequential access file?
A) Modifying data can potentially destroy other data.
B) It may be necessary to rewrite every record in the file to make a slight change.
C) Things that are stored in the same number of "raw data" bytes internally may not take up the same amount of space in a file.
D) Overwriting a record with another record of the same size is very difficult.
A) Modifying data can potentially destroy other data.
B) It may be necessary to rewrite every record in the file to make a slight change.
C) Things that are stored in the same number of "raw data" bytes internally may not take up the same amount of space in a file.
D) Overwriting a record with another record of the same size is very difficult.
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck