C++ SOS 二维数组问题 马上求答案100分 有图

use of strtok
The problem is to read the .csv file into a two dimensional array using strtok and atoi built-in C string functions.

Then use a for loop to compute the average of each student for the three quizzes.

请大家帮一下忙,我英文不好,请大家翻译一下,然后发一个完整的程序给我,谢谢了。
关键词,二维数组,strtok, C string function ,用for loop 计算每个考生的平均分

#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <cstdlib>
const int STUDENTS = 100;
const int SUBJECTS = 3;
const int LINE_LEN = 1024;
int main()
{
int grades[STUDENTS][SUBJECTS] = {0};
char line[LINE_LEN];
const char seps[] = " ,\t\n";
std::ifstream fin( "book1.csv");
fin.getline( line, LINE_LEN );
int studentIndex = 0;
while ( fin.good() && studentIndex < STUDENTS )
{
fin.getline( line, LINE_LEN );
if ( fin.eof() )
break;
int j = 0;
char* token = strtok( line, seps );
while( token != NULL && j < SUBJECTS )
{
grades[studentIndex][j++] = atoi( token );
token = strtok( NULL, seps );
}
++studentIndex;
}
for ( int i = 0; i < studentIndex; ++i )
{
std::cout << i+1 << ": ";
int sum = 0;
for ( int j = 0; j < SUBJECTS; ++j )
{
std::cout << std::setw(3) << grades[i][j] << ", ";
sum += grades[i][j];
}
std::cout << " sum=" << sum << " average=" << (double)sum / SUBJECTS << std::endl;
}
}追问

能留个QQ吗? [email protected]

温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-11-16
来迟了一步……程序已经被上面的仁兄写了。粗略看了一下程序应该是对的。
我来解释一下题意好了:
use of strtok
The problem is to read the .csv file into a two dimensional array using strtok and atoi built-in C string functions.
Then use a for loop to compute the average of each student for the three quizzes.

strtok()函数的使用
这个问题的要求 是 通过使用strtok()和atoi()这两个C语言库中的字符串处理函数 把一个.csv文件读入到二维数组中,然后用一个for循环来计算每个学生的三项测试的平均分。追问

能留下个QQ吗?

本回答被网友采纳
第2个回答  2012-11-19
我保存过这种格式的