| 查看: 631 | 回复: 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- 希望能得到大侠的帮助,谢谢!! |
» 猜你喜欢
A期刊撤稿
已经有5人回复
临港实验室与上科大联培博士招生1名
已经有8人回复
26申博自荐
已经有7人回复
想换工作。大多数高校都是 评职称时 认可5年内在原单位取得的成果吗?
已经有4人回复
带资进组求博导收留
已经有9人回复
求助大佬们,伤口沾上了乙腈
已经有6人回复
最近几年招的学生写论文不引自己组发的文章
已经有9人回复
★ ★ ★ ★
小木虫(金币+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
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













回复此楼
;