CC20020419 2022-04-10 08:54 采纳率: 85%
浏览 58
已结题

我运行后和答案是一样的,怎么oj不通过呢

根据所给代码和输入输出将代码补充完整。
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


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; 
        }
};
  • 写回答

1条回答 默认 最新

  • hfhua 2022-04-11 08:56
    关注

    不是要私有吗,你的是protected

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月26日
  • 已采纳回答 4月18日
  • 创建了问题 4月10日

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么