player * list = new player[rows];
for (int i = 0; i < rows; i++)
list[i].score = new double[cols];
infile.clear(); //清楚状态标记
infile.close();
infile.open("f1.txt");
if(!infile)
{
cout << "Can't open f1.txt!" <<endl;
exit(0);
}
for (int m = 0; m < rows; m++)
{
infile >> list[m].number;
infile >> list[m].name;
for (int j = 0; j < cols; ++j)
infile >> list[m].score[j];
infile.get();
}
infile.close();
/*整理player成绩,先进行排序,然后计算,最后输出到文件*/
原文请找腾讯752018766优.文-论'文;网http://www.youerw.com Sort(list[k].score, cols);
ofstream outfile;
outfile.open("f2.txt");
if(!outfile)
{
cout << "Can't find f2.txt!";
exit(0);
}
outfile<< " 选手的最终成绩 "<<endl;
outfile<< "-----------------------------------------------------------"<<endl;
outfile<< " 参赛号 姓 名 最低分 最高分 累计分 最后得分"<<endl;
outfile<< "-----------------------------------------------------------"<<endl;
outfile.setf(ios_base::fixed); // 格式控制
for (int h = 0;h < rows; ++h)
{
outfile.precision(1);
outfile.width(4);
outfile<< list[h].number;
outfile.width(12);
outfile<< list[h].name;
outfile.width(8);
outfile<< list[h].score[0];
outfile.width(10);
outfile<< list[h].score[cols - 1];
outfile.width(11);
outfile<< Total(list[h].score, cols);
outfile.width(11);
outfile.precision(2);
outfile << Average(list[h].score, cols);
outfile << endl;
}
outfile<< "-----------------------------------------------------------"<<endl;
outfile<< "f2.txt文件成功建立。\n";
cout<< "--------------现在从f1.txt文件中读取信息------------"<<endl<<endl;
cout<<" 选手的初始成绩如下 "<<endl;
cout<< "----------------------------------------------------"<<endl;
cout<< " 参赛号 姓 名 1 2 3 4 5 6 7 "<<endl;
cout<< "----------------------------------------------------"<<endl;
for(i=0;i<rows;i++)
{
cout<<setw(4)<<list[i].number;
cout<<setw(12)<<list[i].name;
for (int j = 0; j < cols; ++j)
cout<<setw(5)<<list[i].score[j];
cout<<endl;
}
cout<< "----------------------------------------------------"<<endl;
cout<<endl;
cout<< " 选手的最终成绩 "<<endl;
cout<< "-----------------------------------------------------------"<<endl;
cout<< " 参赛号 姓 名 最低分 最高分 累计分 最后得分"<<endl;
cout<< "-----------------------------------------------------------"<<endl;
for (int l= 0;l < rows; l++)
{
cout<<setw(4)<<list[l].number;
cout<<setw(12)<<list[l].name;
cout<<setw(8)<<list[l].score[0];
cout<<setw(10)<<list[l].score[cols - 1];
cout<<setw(11)<<Total(list[l].score, cols);
cout<<setw(11)<<Average(list[l].score, cols);
cout<<endl;
}
cout<< "-----------------------------------------------------------"<<endl<<endl<<endl;
cout<< "--------------------结果已经输出到f2.txt-------------------"<<endl; return 0;
}