#include <iostream.h>
#include<string.h>
class student
{
public:
void get(char m[20],char *p)
{
strcpy(name,m);
id=p;
}
protected:
char name[20];
char *id;
};
class MajorStudent:public student // 类MajorStudent是类Student的公有派生类
{
public:
void fun(char ip[25],int c)
{
Malor=ip;
cost=c;
}
void print()
{
cout<<"该学生的ID为:"<<id<<endl;
cout<<"该学生的名字为:"<<name<<endl;
cout<<"该学生的专业为:"<<Malor<<endl;
cout<<"该学生的费用为:"<<cost<<endl;}
protected:
char *Malor;
int cost;
};
void main()
{
char p2[20],a[25],m[20];
int c1;
MajorStudent stu1;
cout<<"请输入学生名字:";
cin>>m;
cout<<"请输入学生的ID:";
cin>>p2;
cout<<"请输入学生专业:";
cin>>a;
cout<<"请输入学生费用:";
cin>>c1;
stu1.get(m,p2);
stu1.fun(a,c1);
stu1.print();
}
这个程序我测试过了,绝对正确!!!
温馨提示:答案为网友推荐,仅供参考