| 查看: 749 | 回复: 3 | |||
[交流]
【求助】C++ 作业题求助 已有3人参与
|
|
我不是计算机专业的,现在在修计算机系的一门课。现在要写一段程序,要求是打开并读取一个文件,文件有四行五列(有点像excel表格),第一列是人名,后四列是每个人的四次考试成绩。现在要求我们在输出文件中另加入两列,一列是每个人的总成绩,另一列式把这个数字成绩换成字母(A,B,C,D). 我现在的问题是我不知道该怎么对原问价进行修改,获取四次成绩,计算综合,再在输出文件中加入这两列。 输入文件: 王 25 25 23 25 李 15 8 6 0 张 24 21 19 23 赵 17 16 21 22 输出文件: 王 25.0 25.0 23.5 25.0 98.5 A 李 15.0 8.5 6.5 0.0 30.0 F 张 24.5 21.0 19.5 23.5 88.5 B+ 赵 17.9 16.6 21.3 22.0 77.8 B- 希望能得到大侠的帮助,谢谢!! |
» 猜你喜欢
生命口C13面上会评时间
已经有11人回复
内心匮乏
已经有16人回复
生命口面上会评结束了吗大家有知道结果吗?现在还没有结果正常不?
已经有9人回复
有机物中金属离子降到1ppm以下,有什么好的方法吗?用过有机溶剂重结晶还是降不下来
已经有4人回复
投英文期刊如何查重
已经有6人回复
不要再数国自然申请书的 filecode 的分隔符个数了
已经有21人回复
伯胺上甲基求助
已经有7人回复
跨出版社商投稿
已经有5人回复
5个%2F,非固定段22个字母
已经有7人回复
生生命学部会评
已经有4人回复
jason.masc
铜虫 (初入文坛)
- 应助: 0 (幼儿园)
- 金币: 63.6
- 帖子: 44
- 在线: 17.8小时
- 虫号: 1098825
- 注册: 2010-09-14
- 性别: GG
- 专业: 制冷及低温工程

2楼2011-02-18 08:37:31
|
下面的code编译好像没问题了,可运行的时候说“segmentation fault"。能不能麻烦帮我看看哪出问题了。 #include #include #include #include #include #include #include #include #include #include using namespace std; int main(){ ifstream fin; ofstream fout; string filename; string temp; cout << "Enter input file: "; cin >> filename; fin.open(filename.c_str()); if(!fin){ cerr << "Input file can not be opened!" << endl; exit (-1); } fout.open ("output_file.txt" ;fout << "Name Score1 Score2 Score3 Score4 Total Grade"<< endl; int lineCount = 0; while (!fin.eof()){ getline(fin,temp); ++lineCount; string buf; stringstream ss(temp); vector while (ss >> buf) tokens.push_back(buf); double score[4]; double total; string grade; int Total; for (int i=0; i<4; i++){ score = atof (tokens[i+1].c_str()); total += score; } Total = int (total); if(Total>=95 && Total<=100){ grade = "A"; } else if(Total>=90 && Total<95){ grade = "A-"; } else if(Total>=85 && Total<90){ grade = "B+"; } else if(Total>=80 && Total<85){ grade = "B"; } else if(Total>=75 && Total<80){ grade = "B-"; } else if(Total>=70 && Total<75){ grade = "C+"; } else if(Total>=65 && Total<70){ grade = "C"; } else if(Total>=60 && Total<65){ grade = "C-"; } else if(Total>=50 && Total<60){ grade = "D"; } else if(Total>=0 && Total<50){ grade = "F"; } fout << tokens[0] << "\t" << score[0] << "\t" << score[1] << "\t" << score[2] << "\t" << score[3] << "\t" << total << "\t" << grade << endl; } return 0; } |
3楼2011-02-19 01:20:29
★ ★ ★ ★
小木虫(金币+0.5):给个红包,谢谢回帖交流
余泽成(金币+3): 谢谢参与应助,欢迎常来程序语言版! 2011-02-20 18:48:42
小木虫(金币+0.5):给个红包,谢谢回帖交流
余泽成(金币+3): 谢谢参与应助,欢迎常来程序语言版! 2011-02-20 18:48:42
|
本帖内容被屏蔽 |
4楼2011-02-19 10:38:41











回复此楼
;