叮叮 发表于 2009-3-13 00:58

C++..作业求助..

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).

    72191Alice Burke   A59.5
    72198Annie Chan    W10.0
    72202Michael James A53.2
    82221Sushil SinghA89.5
    92221John Smith    X89.4
    92228John WallaceA66.3
    92239Jason Wong    A73.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++structcalled 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 studentsnthat 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 indexm 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)


.....

冰天雪地跪求好人放答案..TT

叮叮 发表于 2009-3-13 01:11

不是很明白
int ReadData(/* in */ifstream& fin,/*out*/StudentInfo S[])

这个东西怎么弄?他要return n..那这个n 应该return 去那里啊?

叮叮 发表于 2009-3-13 01:20

救急啊........堂上作业..要交了.T   T

skywolfox 发表于 2009-3-13 07:53

课堂作业还发帖来求。。。不如直接去偷看啊。。。
页: [1]
查看完整版本: C++..作业求助..