weixin_44797297
Limevii
2019-05-04 16:38

有大佬可以帮我看一下程序吗?程序能运行,但是没有结果

  • c++

这是一个作业,程序能运行,但是没有结果
题目:图片说明

我的代码:(我做的是多文件格式,我把他们放到一起吧)
第一次提问,后面不知道为什么打不了字……
各位大佬帮忙看一下吧(手动滑稽.jpg)
感谢!

#include<iostream>
#include<string>

using namespace std;

class Date
{
protected:
    char* name;
public:
    Date(const char* n= 0); 
    ~Date();
    char *getname();
};

class Teacher:public Date
{
protected:
    float sal;   //保存工资
public:
    Teacher(const char *n,float  s);    //初始化工资
    float getsal(float s);
    void disp();
};

class Student :public Date
{
protected:
    char ID[13];
public:
    Student(const char *n,const char* id=0);
    char getID(char* id);
    void disp();
};

class Postgard :public Student
{
private:
     char* dn;     //系别
public:
    Postgard(const char *n,const char *id,const char* dnn);
    char *getdn(char* dnn);
    void disp();
};

class Tpost:public Teacher ,public Postgard    //在职研究生
{
public:
    Tpost(const char *n,float s,const char *id, const char* nn, const char *dnn);
};






Date::Date(const char *n)
{
    int len;
    len = strlen(n);
    name = new char[len + 1];
    strcpy_s(name,len+1, n);
}


Date::~Date()
{
    if (name)
        delete[]name;
}

char* Date::getname()
{
    return name;
}


Teacher::Teacher(const char *n,float s):Date(n)
{
    sal = s;
}

float Teacher::getsal(float s)
{
    return sal;
}

void Teacher::disp()
{
    cout << "teacher name:" << name << endl;
    cout << "teacher sal:" << sal << endl;
}


Student::Student(const char *n,const char* id):Date(n)
{
    if (id) {
        new char[strlen(id) + 1];
        strcpy_s(ID, id);
    }
}

char Student::getID(char* id)
{
    return ID[15];
}

void Student::disp()
{
    cout << "student name:" << name << endl;
    cout << "student ID:" << ID  << endl;
}



Postgard::Postgard(const char* n,const  char* id, const char* dnn) :Student(n,id)
{
    int len;
    len = strlen(dnn);
    dn = new char[len + 1];
    strcpy_s(dn, len + 1, dnn);
}

char* Postgard::getdn(char* dnn)
{
    return dn;
}

void Postgard::disp()
{
    cout << "postgrad's name:" << name << endl;
    cout << "postgrad's dn:" << dn << endl;
}



Tpost::Tpost(const char* n, float s,const  char* id,const char *nn, const char* dnn):Teacher(n,s),Postgard(nn,id,dnn)
{
    if (n=nn)
        cout << "y";
    else cout << "n";
}



int main()
{
    Date ptr;
    Teacher  t("张三",33);
    Student s1("lalla","2018");
    Postgard p1( "ppp", "205","软件工程");
    Tpost pt("aaa",5.0,"676","aaa","huanjing");
    t.disp();
    s1.disp();
    p1.disp();
    return 0;
}
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答