2 baidu 34564873 baidu_34564873 于 2016.05.10 13:16 提问

求大神帮忙看看这段代码的问题在哪,求修改一下 10C

图片说明这是题目,代码如下:

#include
#include
using namespace std;

class People
{
public:
People(const string&NO,const string&name,const string&sex,const string&IDNO,const string&Birthday);
virtual void show()=0;
protected:
string name,sex,NO,IDNO,Birthday;
};

class Student:virtual public People
{
public:
Student(const string&NO,const string&name,const string&sex,const string&IDNO,const string&Birthday,int ClassNO);
void show();
protected:
int ClassNO;

};

class Teacher:virtual public People
{
public:
Teacher(const string&NO,const string&name,const string&sex,const string&IDNO,const string&Birthday,const string&principalship,const string&Department);
void show();
protected:
string principalship,Department;

};

class Graduate:virtual public Student
{
public:
Graduate(const string&NO,const string&name,const string&sex,const string&IDNO,const string&Birthday,int ClassNO,const string&Subject,const Teacher&Teacheradviser);
void show();
protected:
string Subject;
Teacher Teacheradviser;
};

class TA:public Graduate,public Teacher
{
public:
TA(const string&NO,const string&name,const string&sex,const string&IDNO,const string&Birthday,int ClassNO,const string&Subject,const Teacher&Teacheradviser,const string&principalship,const string&Department);
void show();
};

People::People(const string&NO,const string&name,const string&sex,const string&IDNO,const string&Birthday)
:NO(NO),name(name),sex(sex),IDNO(IDNO),Birthday(Birthday){}

Student::Student(const string&NO,const string&name,const string&sex,const string&IDNO,const string&Birthday,int ClassNO)
:People(name,sex,NO,IDNO,Birthday),ClassNO(ClassNO){}

Teacher::Teacher(const string&NO,const string&name,const string&sex,const string&IDNO,const string&Birthday,const string&principalship,const string&Department)
:People(name,sex,NO,IDNO,Birthday),principalship(principalship),Department(Department){}

Graduate::Graduate(const string&NO,const string&name,const string&sex,const string&IDNO,const string&Birthday,int ClassNO,const string&Subject,const Teacher&Teacheradviser)
:Student(name,sex,NO,IDNO,Birthday,ClassNO),Subject(Subject),Teacheradviser(Teacheradviser){}

TA::TA(const string&NO,const string&name,const string&sex,const string&IDNO,const string&Birthday,int ClassNO,const string&Subject,const Teacher&Teacheradviser,const string&principalship,const string&Department)
:Graduate(name,sex,NO,IDNO,Birthday,ClassNO,Subject,Teacheradviser),Teacher(name,sex,NO,IDNO,Birthday,principalship,Department){}

void Student::show()
{
cout<<" name: "<<name<<" sex: "<<sex<<" NO: "<<NO<<" IDNO: "<<IDNO<<"Birthday:"<<Birthday<<"ClassNO:"<<ClassNO<<endl;
}

void Teacher::show()
{
cout<<" name: "<<name<<" sex: "<<sex<<" NO: "<<NO<<" IDNO: "<<IDNO<<"Birthday:"<<Birthday<<"principalship:"<<principalship<<"Department:"<<Department<<endl;
}

void Graduate::show()
{
cout<<" name: "<<name<<" sex: "<<sex<<" NO: "<<NO<<" IDNO: "<<IDNO<<"Birthday:"<<Birthday<<"ClassNO:"<<ClassNO<<"Subject:"<<Subject<<"Teacheradviser:"<<Teacheradviser<<endl;
}

void TA::show()
{
cout<<" name: "<<name<<" sex: "<<sex<<" NO: "<<NO<<" IDNO: "<<IDNO<<"Birthday:"<<Birthday<<"ClassNO:"<<ClassNO<<"Subject:"<<Subject<<"Teacheradviser:"<<Teacheradviser<<"principalship:"<<principalship<<"Department:"<<Department<<endl;
}

int main()

{

Student p1("张三","男","1","532931199001150031","1990-01-15",3);
Teacher p2("李四","女","2","532931199001150041","1990-01-15","班主任","英语部");
Graduate p3("王五","男","3","532931199001150051","1990-01-15",3,"计科","李四");
TA p4("赵六","男","4","532931199001150061","1990-01-15",3,"计科","李四","助教","信息部");
p1.show();

p2.show();
p3.show();
p4.show();
return 0;

}


1个回答

qq423399099
qq423399099   Ds   Rxr 2016.05.10 14:47

问题有点多:
1.构造p3和p4的时候传参不对
2.不能直接这样<<Teacheradviser,因为你没有重载过<<
3.构造函数也不对
PS:稍微帮楼主改了下

 #include<iostream>
#include<string>
using namespace std;
class People
{
public:
    People(const string&NO,const string&name,const string&sex,const string&IDNO,const string&Birthday);
    People(){}
    virtual void show()=0;
protected:
    string NO,name,sex,IDNO,Birthday;
};
class Student:virtual public People
{
public:
    Student(){}
    Student(const string&NO,const string&name,const string&sex,const string&IDNO,const string&Birthday,int ClassNO);
    void show();
protected:
    int ClassNO;
};
class Teacher:virtual public People
{
public:
    Teacher(const string&NO,const string&name,const string&sex,const string&IDNO,const string&Birthday,const string&principalship,const string&Department);
    void show();
protected:
    string principalship,Department;
};
class Graduate:virtual public Student
{
public:
    Graduate(const string&NO,const string&name,const string&sex,const string&IDNO,const string&Birthday,int ClassNO,const string&Subject,const Teacher&Teacheradviser);
    void show();
protected:

    Teacher Teacheradviser;
    string Subject;
};
class TA:public Graduate,public Teacher
{
public:
    TA(const string&NO,const string&name,const string&sex,const string&IDNO,const string&Birthday,int ClassNO,const string&Subject,const Teacher&Teacheradviser,const string&principalship,const string&Department);
    void show();
};
People::People(const string&NO,const string&name,const string&sex,const string&IDNO,const string&Birthday)
    :NO(NO),name(name),sex(sex),IDNO(IDNO),Birthday(Birthday){}
Student::Student(const string&NO,const string&name,const string&sex,const string&IDNO,const string&Birthday,int ClassNO)
    :People(name,sex,NO,IDNO,Birthday),ClassNO(ClassNO)
{
    this->NO = NO;
    this->name = name;
    this->sex = sex;
    this->IDNO = IDNO;
    this->Birthday = Birthday;
    this->ClassNO = ClassNO;
}
Teacher::Teacher(const string&NO,const string&name,const string&sex,const string&IDNO,const string&Birthday,const string&principalship,const string&Department)
    :People(name,sex,NO,IDNO,Birthday),principalship(principalship),Department(Department)
{
    this->NO = NO;
    this->name = name;
    this->sex = sex;
    this->IDNO = IDNO;
    this->Birthday = Birthday;
}
Graduate::Graduate(const string&NO,const string&name,const string&sex,const string&IDNO,const string&Birthday,int ClassNO,const string&Subject,const Teacher&Teacheradviser)
    :Student(name,sex,NO,IDNO,Birthday,ClassNO),Subject(Subject),Teacheradviser(Teacheradviser)
{
    this->NO = NO;
    this->name = name;
    this->sex = sex;
    this->IDNO = IDNO;
    this->Birthday = Birthday;
    this->ClassNO = ClassNO;
}
TA::TA(const string&NO,const string&name,const string&sex,const string&IDNO,const string&Birthday,int ClassNO,const string&Subject,const Teacher&Teacheradviser,const string&principalship,const string&Department)
    :Graduate(name,sex,NO,IDNO,Birthday,ClassNO,Subject,Teacheradviser),Teacher(name,sex,NO,IDNO,Birthday,principalship,Department)
{
    this->NO = NO;
    this->name = name;
    this->sex = sex;
    this->IDNO = IDNO;
    this->Birthday = Birthday;
    this->ClassNO = ClassNO;
}
void Student::show()
{
    cout<<" name: "<<name<<" sex: "<<sex<<" NO: "<<NO<<" IDNO: "<<IDNO<<" Birthday:"<<Birthday<<" ClassNO:"<<ClassNO<<endl;
}
void Teacher::show()
{
    cout<<" name: "<<name<<" sex: "<<sex<<" NO: "<<NO<<" IDNO: "<<IDNO<<" Birthday:"<<Birthday<<" principalship:"<<principalship<<" Department:"<<Department<<endl;
}
void Graduate::show()
{
    cout<<" name: "<<name<<" sex: "<<sex<<" NO: "<<NO<<" IDNO: "<<IDNO<<" Birthday:"<<Birthday<<" ClassNO:"<<ClassNO<<" Subject:"<<Subject<<endl;
}
void TA::show()
{
    cout<<" name: "<<name<<" sex: "<<sex<<" NO: "<<NO<<" IDNO: "<<IDNO<<" Birthday:"<<Birthday<<" ClassNO:"<<ClassNO<<" Subject:"<<Subject<<" principalship:"<<principalship<<" Department:"<<Department<<endl;
}
int main()
{

    Student p1("1","张三","男","532931199001150031","1990-01-15",3); 
    Teacher p2("2","李四","女","532931199001150041","1990-01-15","班主任","英语部");
    Graduate p3("3","王五","男","532931199001150051","1990-01-15",3,"计科",p2);
    TA p4("4","赵六","男","532931199001150061","1990-01-15",3,"计科",p2,"助教","信息部");
    p1.show();

    p2.show();
    p3.show();
    p4.show();
    return 0;

}

图片说明

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!