Font size
WorksheetsQuiz 3: File Operations
Total questions: 10
Worksheet time: 6mins
Write a valid statement to write the value of the variable index to a file given the following declarations.
int index;
ofstream myOut; //declare output file variable
index = 113;
myOut.open("datafile.dat");
myOut << index;
myOut >> index;
myOut < index;
myOut > index;
To access a datafile, the program must include the header file ___________________________
ifstream
ofstream
fstream
file
Write a valid statement to read the value of the variable number from a file given the following declarations:
float number;
ifstream inFile; //declare output file stream variable
inFile.open("datafile.dat"); //prepare file for writing
inFile << number;
inFile >> number;
inFile < number;
inFile > number;
Suppose k is an integer variable, x is a floating point variable, and ch1 is a character variable.
If input data are entered as following:
4.92 F9.4 F0 9 F
What is the value assigned to ch1 after the following statement executes?
cin >> k >> ch1 >> x;
(a)
Assuming aLine is a string variable, which of the following statements shows the correct syntax for using the getline function?
getLine(cin, aLine);
getline(cin, aLine);
cin.getline(aLine);
getline(aLine, cin);
Given the input data
February 14, 2007
Happy Valentine's day!
and the input statement
getline(cin, aString);
Where is the reading marker after the statement is executed?
The reading marker will point to 7
The reading marker will point to the new line character after 7.
The reading marker will point to the 'H' in the second line.
The reading marker will point to the blank after the word "February".
Given the following declarations
string line1;
ifstream inFile;
Write a statement that reads an entire line from the input file stream inFile.
getline(cin,line1);
getline(inFile,line1);
inFile.getline(line1)
line1.getline(inFile);
Convert the English expression "average is greater than 79 but less than 90" to a C++ expression.
average > 79 && < 90
average>79 && average < 90
90 > average >79
79 < average < 90
Given the executable file named "prog2". Which of the following commands tells the operating system to send output to the file "output.dat"?
prog2 << output.dat
prog2 < output.dat
prog2 > output.dat
Given the executable file named "cla5c", write the command
that redirects the output to the file called "cla5cOut.txt".
cla5c > cla5cOut.txt
cla5c < cla5cOut.txt
cla5c << cla5cOut.txt
