CC20020419 2022-04-12 17:44 采纳率: 85%
浏览 79
已结题

我的输出和样例哪里不一样,答案不对

根据所给代码和输入输出将代码补充完整。
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
请按任意键继续. . .
  • 写回答

1条回答 默认 最新

  • 非西昂 2022-04-12 21:09
    关注

    为啥看起来感觉是一样的啊

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 4月19日
  • 创建了问题 4月12日

悬赏问题

  • ¥15 安装quartus II18.1时弹出此error,怎么解决?
  • ¥15 keil官网下载psn序列号在哪
  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错
  • ¥25 自动填写QQ腾讯文档收集表
  • ¥15 DbVisualizer Pro 12.0.7 sql commander光标错位 显示位置与实际不符