6月4日结束学校正规的5门考试,(christmas已经过了3门了)。
6月7日开始,接着上课1个星期,专攻C和C++语言,(因为今年主要学的是java),
接着考试(今天结束的),
但是还有这个coursework这两天就要交,
有问题,究攻不下,往各位不莅赐教。
(只要帮我看看第2题就好了,thanks)
(主要问题怎么从一个文件results.dat里面把资料分类的拿出来,并比较大小,进而得到league table啊?)
这个题目是base在C语言上的。
Background:
The program will support a small sports league table. The league has 8 teams. Each team consists of 6 players. Each team will play a home and away match against each of the other teams. The teams play one fixture per week. Each player will play one match against a player from the opposing team and will either win, draw or lose, resulting in 1, 0.5 or 0 points. A match between to full teams will therefore result in a score adding up to six. It is possible that one or both teams will be short of a player(s), resulting in defaulted games, teams must field sufficient players to at least draw a match. Both teams defaulting a player(s) leads to score that does not add up to 6. For example a match where both teams only field 5 player could finish 32. The teams are awarded 2, 1 or 0 league points depending on the overall result of winning, drawing or losing the match. Should a team default a match, i.e. fail to field enough players on the day they are deduced 1 league point. (This should not happen very often). For the purposes of this assignment you can chose any team names you want. If teams have equal league points, the difference between the total individual games won and lost is used to rank them. Should this result in a draw, the teams are given an equal rank.
题目1:Program 1: This program will generate a season of results.
例子:
[Date]\t[Home Team]\t[Away Team]\t[HT Score]\t[AT Score]\t
1/1/2004 TeamA TeamB 3 3
日期 第一组 第2组 第一组得分 第2组得分
题目2:Program 2: This program will read a results.dat file and generate league tables.
例子:
Rank Name For Against Points
1 Bradford 48 0 28
排名 队名 赢 输 最后得分
(如果这个队赢了就得2分,如果平了就得1分,如果输了就得0分,
得到最后总分Points,然后根据这个排名)
题目大概意思:
第一题,
说有8个小组,每个小组有6个人参见足球比赛。要求,做一个表,将7×8个比赛的情况都记下来格式是:
1/1/2004 小组A 小组B 3(得分) 3(得分)
1/2/2004 小组C 小组B 2(得分) 4(得分)
。。。。。。。。。。。。。。。。。。。
。。。。。。。。。。。。。。。。。。。
这样56行。
这56行记录将用
FILE *fp;
fp = fopen("result.dat", "w");
。。。。。。
。。。。。。
fprintf(fp, "%d %s %s\t %.1f %.1f\n", 2004, team[i], team[j], e, f);
fclose(fp);
这些code写到result.dat这个文件里面。
就是说,最后我们得到一个result.dat文件,里面包含了56条个个小组得比赛情况
“1/1/2004 小组A 小组B 3(得分) 3(得分)
1/2/2004 小组C 小组B 2(得分) 4(得分)
。。。。。。。。。。。。。。。。。。。
。。。。。。。。。。。。。。。。。。。”
这个我已经做好了。现在得主要问题是第2题。
第2题:
说得是,要read a results.dat file and generate league tables.(就是说,写一段code从result.dat这个文件把信息提出来,然后算出每个小组得最后得分情况。如果这个队赢了就得2分,如果平了就得1分,如果输了就得0分,得到最后总分Points,然后根据这个排名)
比如说在results.dat这个table得到,
“1/2/2004 小组C 小组B 2(得分) 4(得分) ”
那样的话,小组B(4分)> 小组A(2分),所以小组B赢了这场比赛。记入league table的话小组B将的2分。
最后得到的结果是这个结构的表格:
Rank Name For Against Points
1 Bradford 48 0 28
排名 队名 赢 输 最后得分
附上我做的第一题的重要部分源代码:
(只要帮我看看第2题就好了,thanks) |
|