找回密码
 立即注册
搜索
查看: 1306|回复: 3

C++..作业求助..

[复制链接]
发表于 2009-3-13 00:58 | 显示全部楼层 |阅读模式
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
回复

使用道具 举报

 楼主| 发表于 2009-3-13 01:11 | 显示全部楼层
不是很明白
int ReadData(/* in */ifstream& fin,/*out*/StudentInfo S[])

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

使用道具 举报

 楼主| 发表于 2009-3-13 01:20 | 显示全部楼层
救急啊........堂上作业..要交了.T   T
回复

使用道具 举报

     
发表于 2009-3-13 07:53 | 显示全部楼层
课堂作业还发帖来求。。。不如直接去偷看啊。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|上海互联网违法和不良信息举报中心|网上有害信息举报专区|962110 反电信诈骗|举报电话 021-62035905|stage1st 沪ICP备13020230号-1 沪公网安备 31010702007642号

GMT+8, 2024-5-19 22:10 , Processed in 0.027311 second(s), 7 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表