Name:
Class:
Date:
Page 1
Indicate whether the statement is true or false.
1. The mode argument is optional for the creation of input and output objects.
a.
True
b.
False
2. The name of the class from which all input file objects are created is ofstream.
a.
True
b.
False
3. You use a program’s input and output file objects, along with the C++ open function, to open actual files on your
computer’s disk.
a.
True
b.
False
4. The open function is defined in the ifstream and ofstream classes and is referred to as a class member function.
a.
True
b.
False
5. Objects are used to perform file input and output operations in C++.
a.
True
b.
False
6. Since sequential files store text, they are sometimes referred to as text files.
a.
True
b.
False
7. Files that are read or written in consecutive order are called random access files.
a.
True
b.
False
8. The ios::app mode is used with an ifstream file object.
a.
True
b.
False
9. Data in random access files can be accessed in consecutive or random order.
a.
True
b.
False
10. The name of the class from which all output file objects are created is fstream.
a.
True
b.
False
Indicate the answer choice that best completes the statement or answers the question.
11. What is the syntax of the C++ open function?
Name:
Class:
Date:
Page 2
a.
fileObject.open(fileName[, mode]);
b.
open(fileObject, fileName, mode);
c.
fileObject(open, fileName, mode);
d.
fileObject.open([fileName], [mode]);
12. Which mode argument, used with an ofstream object, is used to open a file for appending purposes?
a.
open::add
b.
ios::add
c.
ios::app
d.
open::append
13. Which mode argument, used with an ofstream object, is used to open a file for output purposes (an empty file to which
data can be written)?
a.
open::output
b.
ios::out
c.
ios::app
d.
open::out
14. Data can be accessed by its byte location using which file type?
a.
random access
b.
binary
c.
sequential access
d.
text
15. With respect to a sequential access file, which of the following terms best describe a single item of information about
a person, place, or thing?
a.
field
b.
record
c.
file
d.
database
16. Which of the following shows the proper syntax for reading numeric and character data from a sequential access file?
a.
fileObject >> variableName;
b.
fileObject << variableName;
c.
fileObject >> data;
d.
fileObject << data;
17. What type of files are read and written in consecutive order?
a.
binary access
b.
random access
c.
sequential access
d.
ternary access
18. Which of the following statements will create an input file object called inFile?
a.
fstream inFile;
b.
ifstream inFile;
c.
cin inFile;
d.
ifcreate inFile;
19. Which mode argument, used with an ifstream object, is used to open a file for input purposes?
a.
ios::in
b.
open::input
c.
ios::app
d.
open::in
20. Which example shows the proper syntax of the close function?
a.
close.fileObject();
b.
fileObject.close();
c.
fileType.close();
d.
close.file();
21. A collection of one or more related fields that contain all of the necessary data about a specific person, place, or thing
is known as which of the following?
a.
item
b.
record
c.
file
d.
database
Name:
Class:
Date:
Page 3
22. What symbol is used as the Not logical operator in C++?
a.
<>
b.
x
c.
!
d.
?
23. The is_open function returns a value of which of the following data types?
a.
int
b.
short
c.
Boolean
d.
char
24. What is the proper syntax that should be used for writing data to a sequential access file?
a.
fileObject >> data;
b.
fileObject << data;
c.
cin >> data;
d.
cout >> data;
25. Which must be included in a program in order to create a file object in that program?
a.
a #include <string> directive
b.
a using <iostream> statement
c.
a #include <fstream> directive
d.
a using <files> statement
26. Which of the following is a correct C++ statement that checks to see if the file named Addresses.txt is currently open
given the following C++ code?
ifstream addressFile;
addressFile.open(“Addresses.txt”);
a.
if(is_open(“Addresses.txt”))
b.
if (addressFile.is_open())
c.
if(addressFile.open())
d.
if(open(“Addresses.txt”))
27. Which of the following statement will create an output file object called inFile?
a.
fstream inFile;
b.
ifstream inFile;
c.
ofstream inFile;
d.
none of the above
28. What term is used to describe the two colons (::) in each mode?
a.
separator
b.
scope resolution operator
c.
class definer
d.
primer
29. To read string data from a sequential access file, what function is used?
a.
getline
b.
input
c.
retrieve
d.
getstr
30. Which term best describes files that are read by the computer?
a.
input files
b.
output files
c.
text files
d.
binary files
31. What function is used to determine whether the last character in a file has been read?
a.
end_of_file
b.
eof
c.
empty
d.
is_eof
32. Which of the following classes, contained in the fstream file, allows you to create output objects?
a.
ifstream
b.
ofstream
Name:
Class:
Date:
Page 4
c.
fstream
d.
inputstream
33. Given the following C++ code, which statement reads string data from a file object named addressFile and stores it in
a variable named addr1?
ifstream addressFile;
addressFile.open(“Addresses.txt”);
a.
addressFile.read(addr1);
b.
addressFile.getline(addr1);
c.
readfile(addressFile, addr1);
d.
getline(addressFile, addr1);
34. When writing a record that contains more than one field, programmers typically separate each field with which of the
following?
a.
exclamation point
b.
character literal constant
c.
ASCII variable
d.
binary virtual constant
35. Which of the following is the default mode for input files?
a.
ios::in
b.
open::input
c.
ios::app
d.
open::in
36. What is the name of the class from which all input file objects are created?
a.
ifstream
b.
ofstream
c.
fstream
d.
inputstream
37. Write the statement to create an input file object called inFile.
38. Write the statement to create an input file object called salesFile and then open for input a file named
“SalesEmployees.txt” using the salesFile file object.
39. Given the statement below, write your name to the data file. Assume the file has been sucessfully opened.
inFile.open(“datafile.txt”, ios::in);
40. Using the file object declared below, write the statement to open an actual file called datafile.txt for output
purposes.
ifstream outFile;
41. Using the file object declared below, write the statement to open an actual file called datafile.txt for input purposes.
ifstream inFile;
42. Using the file object declared below, write the statement to open an actual file called datafile.txt for append
purposes.
ifstream dataFile;
43. Given the statement below, write the statement to print “yes” on the screen if the data file has been successfully
opened.
Name:
Class:
Date:
Page 5
inFile.open(“datafile.txt”, ios::in);
44. Given the statements below, write the statement to print “yes” on the screen if the last character in the file has been
read.
inFile.open(“datafile.txt”, ios::in);
getline(inFile, datastring);
45. Write the statement to create an output file object called outFile.
Name:
Class:
Date:
Page 6
Name:
Class:
Date:
Page 7
Name:
Class:
Date:
Page 8