Assignment #10: String and I/O

Given a class Student as follows;

class Student {

      char             name[20];

      unsigned int     age;

      char             dept[20];

      float            score;

public:

// add any member functions if necessary

};

 

Then write four functions as below;

 

(1) int readFromTextFile(char* fileName, Student **students) that reads student records from a text file into a student array pointed by students and returns the number of students, where the format of the file is given as follows;

N // number of student records

Record_1

Record_2

¡¦

Record_N

where each record is given in a line as the figure below

Note that the text of each field is left-aligned.

 

(2) void writeToBinaryFile(char* fileName, int n, Student *students) that writes n elements of student array read by (1) into a binary file. The binary file format should be identical with n repetitions of Student class type except the head of the file. The head contains the number of students as a 4-bytes integer value.

 

(3) int readFromBinaryFile(char* fileName, Student **students) that reads student records from the binary file made by (2) into a student array pointed by students and returns the number of students read from the binary file.

 

(4) void writeToTextFile(char* fileName, int n, Student *students) that writes n elements of students array read by (3) into a text file. The file format should be identical with input file format given at (1).

 

Oral test at the lab on May 17th.

 

Notice 1. The test data format will be same as sample data(sample).

Notice 2. ¸ñ¿äÀÏ ½Ç½À½Ã°£¿¡´Â Á¶±³°¡ ¸¸µç main¹®À» ÁÖ°í Á¦´ë·Î ÀÛµ¿ÇÏ´ÂÁö °Ë»çÇÒ °ÍÀÔ´Ï´Ù. We will give main code and check it works well.

[Download lab_data.zip]