大贤者
精华
|
战斗力 鹅
|
回帖 0
注册时间 2007-12-6
|
Create a “Marks.txt” and put it in the local directory where your executable will be run. The file “Marks.txt” could contain the following student information. Add your own name and fake student ID (and give yourself a high mark).
72191 Alice Burke A 59.5
72198 Annie Chan W 10.0
72202 Michael James A 53.2
82221 Sushil Singh A 89.5
92221 John Smith X 89.4
92228 John Wallace A 66.3
92239 Jason Wong A 73.4
The first number, an integer, is the student ID number. Next come the student’s first name followed by the student’s surname. Following is the student’s status which is a single letter where A means “active”, C means “completed”, and W means “withdrawn”, and finally, a mark.
Define a C++ struct called StudentInfo for storing the student information. Use the char type for the student status. Write a C++ function
int ReadData(/* in */ifstream& fin,/*out*/StudentInfo S[] );
that reads the information about each student from the input file stream into the student info array S and which returns the number of students n that were found in the file. In the example, 7 would be returned.
Now write a C++ main program that reads the name of a file (like “Marks.txt”) opens the input stream with the file name, calls the ReadData function and then calls a function to print all the information about all the students (so that the output looks like the Marks.txt file) to verify that the data has been read in correctly.
After this is working, write a C++ function
int GetTopMark(/* in */ StudentInfo S[], /* in */ int n );
that goes through the n students in the array S and returns the index m of the student who got the maximum mark. In the example, Singh got the maximum mark so 3 would be returned (not 4, remember, arrays are indexed from 0 not 1). Now, modify your main program to print out the following line (do not print this line in the GetTopMark function)
Sushil Singh with ID 82221 got the top mark of 89.5
So your main program should be rather short. Assume (for this assignment which is not the case in general) that only one student has the top mark.
At this point, your program is basically working. And yes, you should use your solution to the last assignment as a starting point. The final thing to do is to make the student status an enumerated type. Define
enum StudentStatus { ACTIVE, COMPLETED, WITHDRAWN } ;
Modify your StudentInfo struct to use StudentStatus instead of the char type. You need to read the status character from the file as a character type, test if it is an ‘A’, ‘C’, or ‘W’ to set the student status in the struct to ACTIVE,COMPLETED, or WITHDRAWN. If the status is not ‘A’, ‘C’, or ‘W’, then a suitable error message should be printed onto standard output and that student and all his/her information is skipped (i.e. that student is not entered into the "database" kept in the array)
.....
冰天雪地跪求好人放答案..T T |
|