4-0.cpp
来自「Accelerated C++ 课后练习题 本人自己完成、可供参考」· C++ 代码 · 共 54 行
CPP
54 行
#include<algorithm>
#include<iomanip>
#include<ios>
#include<iostream>
#include<stdexcept>
#include<string>
#include<vector>
#include"grade.h"
#include"Student_info.h"
using namespace std;
string::size_type max(const string::size_type a,const string::size_type b)
{
return a>b?a:b;
}
int main()
{
vector<Student_info> students;
Student_info record;
string::size_type maxlen=0; //the length of the longest name
//read and store all the stuedent data.
//Invariant: student contains all the strdent records read so far
//maxlen contains the length of the longest name in students
for(vector<Student_info>::size_type i=0;i!=students.size();++i)
{
while(read(cin,record))
{
//find length of longest name
maxlen = max(maxlen, record.name.size());
students.push_back(record);
}
//alphabetize the student records
sort(students.begin(),students.end(),compare);
//write the name and grade
try
{
double final_grade=grade(students[i]);
streamsize prec=cout.precision();
cout<<setprecision(3)<<final_grade<<setprecision(prec);
}
catch(domain_error e)
{
cout<<e.what();
}
cout<<endl;
}
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?