最近在看《Accelarate C++》这本书,然后抛开书本自己码一遍书上的程序,如果你也准备看这本书,希望可以对你有点帮助,以上。
c文件和h文件、程序包含头文件的定义
主程序 main.c
#include <iostream.h>
#include <ios>
#include <vector.h>
#include <iomanip.h>
#include <string.h>
#include <algorithm>
#include <stdexcept>
#include "grade.h"
#include "Student_info.h"
using std::cin; using std::cout;
using std::string; using std::vector;
using std::endl; using std::sort;
using std::domain_error; using std::max;
using std::setprecision; using std::streamsize;
int main(){
vector<Student_info> students;
Student_info record;
string::size_type maxlen = 0;
//读入数据
while(read(cin, record)){
maxlen = max(maxlen, record.name.size());
students.push_back(record);
}
//按字母顺序排列学生成绩记录
sort(students.begin(), students.end(), compare);
//输出
for(vector<Student_info>::size_type i = 0; i!=students.size(); ++i){
cout<<students[i].name<<string(maxlen+