一个C++题
40个学生,5门课程,5门总平均成绩超过全班总平均成绩20%的发一等奖学金,超过10%的为二等。要把一等奖、二等奖学生的学号和平均成绩输出来我们老师也是,总共输入240个项目。。。
答案:#include<iostream>
#include<vector>
#include<string>
using namespace std;
class Student
{
private:
string Name;
int StudentNum;
double SQA;
double Math;
double Chinese;
double English;
double Biology;
double Geography;
//数据:学生姓名,学号,平均分数,五门课程的分数
public:
Student(string N=" 无",int S=0,double M=0.0,double C=0.0,double E=0.0,double B=0.0,double G=0.0):Name(N),StudentNum(S),Math(M),Chinese(C),English(E),Biology(B),Geography(G){SQA=(M+C+E+B+G)/5;}
virtual ~Student(){}
void set_Name(string Na);
void set_StudentNum(int SN);
void set_Math(double Ma);
void set_Chinese(double Ch);
void set_English(double En);
void set_Biology(double Bi);
void set_Geography(double Ge);
//重新设置数据
int get_StudentNum()const{return StudentNum;}
double get_SQA()const{return SQA;}
double get_Math()const{return Math;}
double get_Chinese()const{return Chinese;}
double get_English()const{return English;}
double get_Biology()const{return Biology;}
double get_Geography()const{return Geography;}
//返回数据
void printnum()const;//打印数据
double total_points()const;//五门课总分
};
void Student::set_Name(string Na)
{
Name=Na;
}
void Student::set_StudentNum(int SN)
{
StudentNum=SN;
}
void Student::set_Math(double Ma)
{
Math=Ma;
SQA=(Math+Chinese+English+Biology+Geography)/5;
}
void Student::set_Chinese(double Ch)
{
Chinese=Ch;
SQA=(Math+Chinese+English+Biology+Geography)/5;
}
void Student::set_English(double En)
{
English=En;
SQA=(Math+Chinese+English+Biology+Geography)/5;
}
void Student::set_Biology(double Bi)
{
Biology=Bi;
SQA=(Math+Chinese+English+Biology+Geography)/5;
}
void Student::set_Geography(double Ge)
{
Geography=Ge;
SQA=(Math+Chinese+English+Biology+Geography)/5;
}
void Student::printnum()const
{
cout<<"姓名:"<<Name
<<" 型号:"<<StudentNum
<<" 数学:"<<Math
<<" 语文:"<<Chinese
<<" 英语:"<<English
<<" 生物:"<<Biology
<<" 地理:"<<Geography
<<" 总分:"<<total_points()
<<" 均分:"<<SQA
<<"\t";
}
double Student::total_points()const
{
return Math+Chinese+English+Biology+Geography;
}
void Max(vector<Student> &vec,int Num)
{
for(int i=0;i<Num;i++)
for(int j=Num-1;j>i;j--)
if( vec[i].get_SQA()<vec[j].get_SQA() )
swap(vec[i],vec[j]);
}//按平均成绩重新排列名次
double frist_prize(double a)
{
return (a/40)*1.2;
}//一等奖学金的最低标准
double second_prize(double a)
{
return (a/40)*1.1;
}//二等奖学金的最低标准
int prize( double ALL_NUM,double MY_SQA )
{
if( frist_prize(ALL_NUM)<=MY_SQA )return 1;
else if( frist_prize(ALL_NUM)>MY_SQA && second_prize(ALL_NUM)<=MY_SQA)return 0;
else return -1;
}//判断是否能拿奖学金,能拿几等奖学金
void main()
{
const int n=40;//40名学生
Student *p=new Student[n];
p[0].set_Name("王晓宏");
p[0].set_StudentNum(20090102);
p[0].set_Math(125.0);
p[0].set_Chinese(10.5);
p[0].set_English(87.5);
p[0].set_Biology(87.5);
p[0].set_Geography(88.0);
p[1].set_Name("李明");
p[1].set_StudentNum(20090103);
p[1].set_Math(20.0);
p[1].set_Chinese(22.5);
p[1].set_English(36.5);
p[1].set_Biology(27.5);
p[1].set_Geography(40.0);
p[2].set_Name("张芳");
p[2].set_
上一个:vb与c++哪个更有用
下一个:如何学好C++?