~cpp
#include <fstream>
#include <vector>
#include <algorithm>
#include <iostream>
#include "class.h"
using namespace std;
const int MAX_SUB = 4;
void getdata(vector<Score>& ban,const char* filename);
double changescore(string score);
bool zcompare(Score& a,Score& b);
int main()
{
vector<Score> ban;
getdata(ban,"input.txt");
sort(ban.begin(),ban.end(),zcompare);
for(vector<Score>::iterator i=ban.begin();i!=ban.begin()+ban.size()/10;++i)
{
cout << i->getname() << "\t" << i->getavg() << endl;
}
cout << endl;
for(i=ban.begin();i!=ban.end();++i)
{
if(i->getavg() < 1.5)
{
cout << i->getname() << "\t" << i->getavg() << endl;
}
}
return 0;
}
void getdata(vector<Score>& ban,const char* filename){
ifstream fin(filename);
string tmp;
string name;
Score temp;
vector<double> scoretmp;
while(fin>>tmp) // 학생
{
fin >> name; // 이름
fin >> tmp; // :
for(int i = 0; i < MAX_SUB; i++)
{
fin >> tmp;
scoretmp.push_back(changescore(tmp));
}
temp = Score(name,scoretmp);
ban.push_back(temp);
scoretmp.clear();
}
}
double changescore(string score)
{
if(!score.compare("A+"))
return 4.5;
else if(!score.compare("A"))
return 4.0;
else if(!score.compare("B+"))
return 3.5;
else if(!score.compare("B"))
return 3.0;
else if(!score.compare("C+"))
return 2.5;
else if(!score.compare("C"))
return 2.0;
else if(!score.compare("D"))
return 1.0;
else if(!score.compare("F"))
return 0.0;
return 0.0;
}
bool zcompare(Score& a,Score& b)
{
return a.getavg() > b.getavg();
}