1、声明一个基类Student(学生)类,声明一个派生出新类College_student (大学生)类,并继承Student(学生)类,要求:
(1) 在Student类中包括:num(学号),name(姓名),sex(性别)等成员数据,viod display();(输出学生学号,姓名,性别)函数成员,构造函数自己设计。
(2) 在派生出新类College_student (大学生)类中包括:chinese(语文分),math(数学分),computer(计算机分)等成员数据,派生类构造函数,float total_score();(统计一个大学生的三科总分)。viod display();(输出学生信息)
(3) 建立一个对象数组,内放5位大学生的数据(学号、姓名、性别、语文分、数学分、计算机分),设立一个函数max,用指向对象的指针作函数参数,在max函数中找出5个学生中总成绩最高者,并输出该学生的所有信息(学号、姓名、性别、语文分、数学分、计算机分,及总分)。
(4) 对5位大学生按总分进行排
#include<iostream>
#include<string>
using namespace std;
class Student{
protected:
int num;
string name;
string sex;
public:
Student(int n,string nam,string s){num=n;name=nam;sex=s;}
void display()
{
cout<<num<<'/t'<<name<<'/t'<<sex<<endl;
}
};
class college_student:public Student{
private:
college_student(int n,string nam,string s,float c,float m,float com):Student(n,nam,s)
{
chinese=c;math=m;computer=com;
}
float total score()
{int sum;sum=c+m+com;}
void display()
{
cout<<num<<'/t'<<name<<'/t'<<sex<<<<'/t'<<chinese<<'/t'<<math<<'/t'<<computer<<endl;
}
};
void main()
{college_student stud[5]={college_student(101,"张三","男",80.5,78,90),
college_student(102,"李四","男",66,80,79),
college_student(103,"李梅","女",67,73,92),
college_student(104,"赵娜","女",81,76,88),
college_student(105,"宋明","男",82,79,92)};
cout<<"班级学生原始信息:"<<endl;
cout<<"----------------------------------------------------------"<<endl;
cout<<"5个学生中总成绩最高者学生信息:"<<endl;
college_student *p=&stud[0];
cout<<"----------------------------------------------------------"<<endl;
cout<<"学号"<<'/t'<<"姓名"<<'/t'<<"性别"<<'/t'<<"语文"<<'/t'<<"数学"<<'/t'<<"计算机"<<'/t'<<"总分"<<endl;
max(p);
cout<<"----------------------------------------------------------"<<endl;
cout<<"对5位大学生按总分进行排名:"<<endl;
cout<<"----------------------------------------------------------"<<endl;
cout<<"学号"<<'/t'<<"姓名"<<'/t'<<"性别"<<'/t'<<"语文"<<'/t'<<"数学"<<'/t'<<"计算机"<<'/t'<<"总分"<<endl;
sort(stud);
for(i=0;i<5;i++){
stud[i].display();
}
cout<<"----------------------------------------------------------"<<endl;
}
名,并输出排名后的结果。