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: 3539651 • 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.


There are 4 sections of CIS115 in a community college. We want a program to analyze the dropout rate. The data are stored in the file "dropout115.txt":

35 4

42 4

27 3

36 5

     Each row in this file is the data for one section. The first number is the number of students registered at the beginning of the semester. The second number is the number of students who dropped out before the end of the semester.

Instead of writing a complete program, please write the following statements:


(a) Write a statement to create an ifstream named dropoutData.

(b) Write a statement to assign the sequential access file "droput115.txt" to the ifstream dropoutData. Open it for reading with the ios::in option.

(c) Write a statement to read two values from the ifstream dropoutData. Store the first value in a variable named numStudents and the second value in a variable named numDropouts.

(d) Write a statement to close the ifstream dropoutData.

Explanation / Answer

WR(a) Write a statement to create an ifstream named dropoutData.

ifstream dropoutData;

Wri(b) Write a statement to assign the sequential access file "droput115.txt" to the ifstream dropoutData. Open it for reading with the ios::in option.

dropoutData.open("droput115.txt",ios::in);

(c) Write a statement to read two values from the ifstream dropoutData.
Store the first value in a variable named numStudents and the second value in a variable named numDropouts.

dropoutData >> numStudents >> numDropouts;

Wr(d) Write a statement to close the ifstream dropoutData.

dropoutData.close();