求教高手c++编程 构造一个person类 然后student类继承

来源:百度知道 编辑:UC知道 时间:2024/05/07 15:24:02
person类中有姓名跟年龄两个成员 有构造函数
student类继承它 并且有成员学号 要求能够使学生对象按学号排序并输出
我实在是不会啊
高分悬赏!

#include "stdafx.h"
#include "iostream.h"

class person
{
public:
char* name;
int age;
person()
{
name=new char[20];
age=0;
}
};
class student:public person
{
public:
int num;
};
int main(int argc, char* argv[])
{
student stu[10];
char count='y';
int n=0;
while(count=='y'||count=='Y')
{
cout<<"enter(num name age):"<<endl;
cin>>stu[n].num>>stu[n].name>>stu[n].age;
n++;
cout<<"more?"<<endl;
cin>>count;
}
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-1-i;j++)
{
if(stu[j].num>stu[j+1].num)
{
student st=stu[j+1];
stu[j+1]=stu[j];
stu[j]=st;
}
}
}
for(i=0;i<n;i++)
{