根据所给代码和输入输出将代码补充完整。
1)定义一个大学生类Student,函数私有数据成员:姓名(name)、学号(StuNum)、校名(universty_name),并为它定义带参数的构造函数、参数带缺省值的构造函数
和输出数据成员值的print()公有成员函数;
2)另定义研究生类(GraStudent),它以公有继承方式派生于类Student,新增加“研究方向(special)、导师名(directorname)”两个私有数据成员,并定义带参数的构造函数和输出研究生数据的print()公有成员函数。
#include
using namespace std;
#include<string.h>
class Student
{
protected:
char *name;
char *stunum;
char uniname;
public:
Student();
Student(char pn, char ps, char pu);
void print();
};// 在此处补充你的代码int main()
{
Student stu1("Li","1600141","CUC");
stu1.print();
GraStudent gstu("Wang","1600240","CUC","Computer","Zhang");
gstu.print();
return 0;
}输入无输出第一行:大学生的姓名
第二行:大学生的学号
第三行:大学生的校名
第四行:研究生的姓名
第五行:研究生的学号
第六行:研究生的校名
第七行:研究生的研究方向
第八行:研究生的导师姓名样例输入NULL样例输出name=Li
StuNum=1600141
universty_name=CUC
name=Wang
StuNum=1600240
universty_name=CUC
special is Computer
director is Zhang
#include<iostream>
using namespace std;
#include<string.h>
class Student
{
protected:
char *name;
char *stunum;
char *uniname;
public:
Student();
Student(char *pn, char* ps, char* pu);
void print();
};
Student::Student(){};
Student::Student(char *pn, char* ps, char* pu){
name=new char[20];
stunum=new char[30];
uniname=new char[30];
strcpy(name,pn);
strcpy(stunum,ps);
strcpy(uniname,pu);
}
void Student::print(){
int a;
a=sizeof(name);
cout<<"name=";
for(int i=0;i<a;i++){
cout<<*name;
name++;
}
cout<<endl;
cout<<"StuNum=";
int b;
b=sizeof(stunum);
for(int i=0;i<a;i++){
cout<<*stunum;
stunum++;
}
cout<<endl;
cout<<"universty_name=";
int c;
c=sizeof(uniname);
for(int i=0;i<c;i++){
cout<<*uniname;
uniname++;}
cout<<endl;}
class GraStudent:public Student{
private:
char special[20];
char directorname[20];
public:
GraStudent(char *pn, char* ps, char* pu,char special2[20],char directorname2[20]){
name=new char[20];
stunum=new char[30];
uniname=new char[30];
strcpy(name,pn);
strcpy(stunum,ps);
strcpy(uniname,pu);
strcpy(special,special2);
strcpy(directorname,directorname2);
}
void print(){
int a;
a=sizeof(name);
cout<<"name=";
for(int i=0;i<a;i++){
cout<<*name;
name++;
}
cout<<endl;
cout<<"StuNum=";
int b;
b=sizeof(stunum);
for(int i=0;i<a;i++){
cout<<*stunum;
stunum++;
}
cout<<endl;
cout<<"universty_name=";
int c;
c=sizeof(uniname);
for(int i=0;i<c;i++){
cout<<*uniname;
uniname++;}
cout<<endl;
cout<<"special is "<<special<<endl;
cout<<"director is "<<directorname<<endl;
}
};
int main()
{
Student stu1("Li","1600141","CUC");
stu1.print();
GraStudent gstu("Wang","1600240","CUC","Computer","Zhang");
gstu.print();
return 0;
}
name=Li
StuNum=1600141
universty_name=CUC
name=Wang
StuNum=1600240
universty_name=CUC
special is Computer
director is Zhang
--------------------------------
Process exited after 0.4075 seconds with return value 0
请按任意键继续. . .