不得不说,这一题有点6,主要有精度控制和计算平均数时不能除以0这些细节要注意,然而我是跪在了排名函数上,代码略凌乱,希望大家不要介意,就让这题作为我博客的开始吧.
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
const double EPS=1e-5;
struct point
{
int chi,ma,eng,code,flag,sum,cid;
string s,sid;
point(int a=1):flag(a){}
};
vector<point> total;
bool compare(point a,point b)
{
return a.sum<b.sum;
}
void print()
{
printf("Welcome to Student Performance Management System (SPMS).\n\n");
printf("1 - Add\n2 - Remove\n3 - Query\n4 - Show ranking\n5 - Show Statistics\n0 - Exit\n\n");
}
void add()
{
for(;;)
{
int i,j,k=0;
point l;
printf("Please enter the SID, CID, name and four scores. Enter 0 to finish.\n");
cin>>l.sid;
if(l.sid=="0")break;
cin>>l.cid>>l.s>>l.chi>>l.ma>&g