Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lab 02: SEQUENTIAL ACCESS FILES Write the statement you are asked to write in ea

ID: 3539654 • Letter: L

Question

Lab 02: SEQUENTIAL ACCESS FILES

Write the statement you are asked to write in each part. You do not need to write a complete program.

We want to use a C++ program to create a sequential access file. The data we

want to store in the file are the semester GPAs of some students in their first,

second, third and fourth semester in Wake Tech. Each row in the file is the data

for one student. The first, second, third and fourth number in each row is the

GPA for the first, second, third and fourth semester, respectively. For example,

the first row of the file is shown below:

3.12 3.47 2.89 4.00

Instead of writing a complete program, please write the following

statements:

(a) Write a statement to create an ofstream named gpaData.

(b) Write a statement to assign the sequential access file "gpa.txt" to the ofstream gpaData. Open it for writing with the ios::out option.

(c) Suppose we have the GPAs stored in four variables: gpa1, gpa2, gpa3 and gpa4. Write a statement to write these values to ofstream gpaData. Don't forget to use a space to separate the values and use endl to send the cursor to the next line at the end of the line.

(d) Write a statement to close the ofstream gpaData.


Explanation / Answer

ofstream gpaData;

gpaData.open("gpa.txt",ios::out);

gpaData << gpa1 << " " << gpa2 << " " << gpa3 << " " << gpa4 << endl;

gpaData.close();