主题:求助
#include<iostream>
#include<math.h>
#include<string>
#include<fstream>
using namespace std;
static int n=0;
class exam //成绩类
{
public:
float Math;
float English;
float Sport;
float mo;
};
class final:public exam
{
public:
float chengji(float a=0,float b=0,float c=0);
};
float final::chengji(float a,float b,float c)
{
mo=a+b+c;
return a+b+c;
}
class student //学生类
{
public:
float pingding();
public:
string name; //姓名
string number; //学号
char sex[5]; //性别
int money; //奖学金数额
float GPA; //学分绩
final mo; //期末考试成绩
};
float student::pingding()
{
float GPA;
GPA=(mo.Math*4+mo.English*3+mo.Sport*2)/9;
if(GPA>=8)
money=1000;
else if(GPA>=7&&GPA<8)
money=500;
else if(GPA>=6&&GPA<7)
money=300;
else if(GPA<6&&GPA>=5)
money=150;
else
money=0;
return GPA;;
}
class guanli
{
public:
void print();
int gameprint1();
void fun1(student *stu);
void paihang(student *stu);
void find(student *stu);
void chushi(student *stu);
};
void guanli::print()
{
cout<<"┃------------------------------------┃"<<endl;
cout<<"┃********* 奖学金评定 *********┃"<<endl;
cout<<"┃********* 1选择学生信息 *********┃"<<endl;
cout<<"┃********* 2查看奖学金信息 *********┃"<<endl;
cout<<"┃********* 3查询个人奖学金 *********┃"<<endl;
cout<<"┃********* 4退出 *********┃"<<endl;
cout<<"┃------------------------------------┃"<<endl;
}
int guanli::gameprint1()
{
int a;
cout<<"继续操作请按1,退出请按0"<<endl;
cin>>a;
return a;
}
void guanli::chushi(student *stu) //初始化学生信息函数
{
ifstream p;
int i;
if(!p)
{
cout<<"打开失败"<<endl;
exit(0);
}
while(!p.eof())
{
p>>stu[n].name>>stu[n].number>>stu[n].sex>>stu[n].mo.Math>>stu[n].mo.English>>stu[n].mo.Sport;
n++;
}
for(i=0;i<n;i++)
stu[i].pingding();
p.close();
}
void guanli::fun1(student *stu) //录入学生信息函数
{
float a,b,c;
cout<<"输入学生姓名,学号,性别"<<endl;
cin>>stu[n].name>>stu[n].number>>stu[n].sex;
cout<<"请选择输入"<<stu[n].name<<"的成绩"<<endl;
cout<<"请输入该生期末考试成绩--请按--数学 英语 的顺序输入,否则默认为0"<<endl;
cin>>a>>b>>c;
stu[n].mo.Math=a;
stu[n].mo.English=b;
stu[n].mo.Sport=c;
stu[n].mo.chengji(a,b,c);
ofstream p;
p.open("E:\\1.txt",ios::app);
if(!p)
{
cout<<"打开失败"<<endl;
exit(0);
}
p<<endl<<stu[n].name<<" "<<stu[n].number<<" "<<stu[n].sex<<stu[n].mo.Math<<" "<<stu[n].mo.English<<" "<<stu[n].mo.Sport<<" " ;
n++;
}
void guanli::paihang(student *stu) //查看奖学金信息函数
{
int i;
cout<<"姓名"<<" "<<"学分绩"<<" "<<"奖学金数额"<<endl;
for(i=0;i<n;i++)
{
stu[i].pingding();
cout<<stu[i].name<<" "<<stu[i].GPA<<" "<<stu[i].money<<endl;
}
}
void guanli::find(student *stu) //查询奖学金函数
{
float b;
cout<<"请输入所查询学生学号"<<endl;
string ch;
cin>>ch;
int i;
for(i=0;i<n;i++)
{
if(ch==stu[i].number)
{
b=stu[i].pingding();
if(b>=6&&b<7)
cout<<"恭喜"<<stu[i].name<<"获得综合三等奖学金,数额为300"<<endl;
else if(b>=5&&b<6)
cout<<"恭喜"<<stu[i].name<<"获得单项奖学金,数额为150"<<endl;
else if(b>=7&&b<8)
cout<<"恭喜"<<stu[i].name<<"获得综合二等奖学金,数额为500"<<endl;
else if(b>=8)
cout<<"恭喜"<<stu[i].name<<"获得综合一等奖学金,数额为1000"<<endl;
else
cout<<"该生未获得奖学金,请继续努力"<<endl;
return ;
}
}
cout<<"查无此人"<<endl;
}
void main()
{
student stu[100],*CH;
guanli a;
CH=stu;
a.chushi(stu);
int i,lin;
loop1: a.print();
cin>>i;
if(i!=1&&i!=2&&i!=3&&i!=4&&i!=5)
{
cout<<"输入错误,请重新输入"<<endl;
goto loop1;
}
else
{
switch(i)
{
case 1:
a.fun1(CH);
lin=a.gameprint1();
if(lin==1)
goto loop1;
else exit(0);
case 2:
a.paihang(CH);
lin=a.gameprint1();
if(lin==1)
goto loop1;
else exit(0);
case 3:
a.find(CH);
lin=a.gameprint1();
if(lin==1)
goto loop1;
else exit(0);
#include<math.h>
#include<string>
#include<fstream>
using namespace std;
static int n=0;
class exam //成绩类
{
public:
float Math;
float English;
float Sport;
float mo;
};
class final:public exam
{
public:
float chengji(float a=0,float b=0,float c=0);
};
float final::chengji(float a,float b,float c)
{
mo=a+b+c;
return a+b+c;
}
class student //学生类
{
public:
float pingding();
public:
string name; //姓名
string number; //学号
char sex[5]; //性别
int money; //奖学金数额
float GPA; //学分绩
final mo; //期末考试成绩
};
float student::pingding()
{
float GPA;
GPA=(mo.Math*4+mo.English*3+mo.Sport*2)/9;
if(GPA>=8)
money=1000;
else if(GPA>=7&&GPA<8)
money=500;
else if(GPA>=6&&GPA<7)
money=300;
else if(GPA<6&&GPA>=5)
money=150;
else
money=0;
return GPA;;
}
class guanli
{
public:
void print();
int gameprint1();
void fun1(student *stu);
void paihang(student *stu);
void find(student *stu);
void chushi(student *stu);
};
void guanli::print()
{
cout<<"┃------------------------------------┃"<<endl;
cout<<"┃********* 奖学金评定 *********┃"<<endl;
cout<<"┃********* 1选择学生信息 *********┃"<<endl;
cout<<"┃********* 2查看奖学金信息 *********┃"<<endl;
cout<<"┃********* 3查询个人奖学金 *********┃"<<endl;
cout<<"┃********* 4退出 *********┃"<<endl;
cout<<"┃------------------------------------┃"<<endl;
}
int guanli::gameprint1()
{
int a;
cout<<"继续操作请按1,退出请按0"<<endl;
cin>>a;
return a;
}
void guanli::chushi(student *stu) //初始化学生信息函数
{
ifstream p;
int i;
if(!p)
{
cout<<"打开失败"<<endl;
exit(0);
}
while(!p.eof())
{
p>>stu[n].name>>stu[n].number>>stu[n].sex>>stu[n].mo.Math>>stu[n].mo.English>>stu[n].mo.Sport;
n++;
}
for(i=0;i<n;i++)
stu[i].pingding();
p.close();
}
void guanli::fun1(student *stu) //录入学生信息函数
{
float a,b,c;
cout<<"输入学生姓名,学号,性别"<<endl;
cin>>stu[n].name>>stu[n].number>>stu[n].sex;
cout<<"请选择输入"<<stu[n].name<<"的成绩"<<endl;
cout<<"请输入该生期末考试成绩--请按--数学 英语 的顺序输入,否则默认为0"<<endl;
cin>>a>>b>>c;
stu[n].mo.Math=a;
stu[n].mo.English=b;
stu[n].mo.Sport=c;
stu[n].mo.chengji(a,b,c);
ofstream p;
p.open("E:\\1.txt",ios::app);
if(!p)
{
cout<<"打开失败"<<endl;
exit(0);
}
p<<endl<<stu[n].name<<" "<<stu[n].number<<" "<<stu[n].sex<<stu[n].mo.Math<<" "<<stu[n].mo.English<<" "<<stu[n].mo.Sport<<" " ;
n++;
}
void guanli::paihang(student *stu) //查看奖学金信息函数
{
int i;
cout<<"姓名"<<" "<<"学分绩"<<" "<<"奖学金数额"<<endl;
for(i=0;i<n;i++)
{
stu[i].pingding();
cout<<stu[i].name<<" "<<stu[i].GPA<<" "<<stu[i].money<<endl;
}
}
void guanli::find(student *stu) //查询奖学金函数
{
float b;
cout<<"请输入所查询学生学号"<<endl;
string ch;
cin>>ch;
int i;
for(i=0;i<n;i++)
{
if(ch==stu[i].number)
{
b=stu[i].pingding();
if(b>=6&&b<7)
cout<<"恭喜"<<stu[i].name<<"获得综合三等奖学金,数额为300"<<endl;
else if(b>=5&&b<6)
cout<<"恭喜"<<stu[i].name<<"获得单项奖学金,数额为150"<<endl;
else if(b>=7&&b<8)
cout<<"恭喜"<<stu[i].name<<"获得综合二等奖学金,数额为500"<<endl;
else if(b>=8)
cout<<"恭喜"<<stu[i].name<<"获得综合一等奖学金,数额为1000"<<endl;
else
cout<<"该生未获得奖学金,请继续努力"<<endl;
return ;
}
}
cout<<"查无此人"<<endl;
}
void main()
{
student stu[100],*CH;
guanli a;
CH=stu;
a.chushi(stu);
int i,lin;
loop1: a.print();
cin>>i;
if(i!=1&&i!=2&&i!=3&&i!=4&&i!=5)
{
cout<<"输入错误,请重新输入"<<endl;
goto loop1;
}
else
{
switch(i)
{
case 1:
a.fun1(CH);
lin=a.gameprint1();
if(lin==1)
goto loop1;
else exit(0);
case 2:
a.paihang(CH);
lin=a.gameprint1();
if(lin==1)
goto loop1;
else exit(0);
case 3:
a.find(CH);
lin=a.gameprint1();
if(lin==1)
goto loop1;
else exit(0);
case 4: exit(0);}}}
为什么学分绩表达不出来?先谢谢各位大神了