读书人

作业题大概框架都写出细节出错

发布时间: 2012-03-09 21:42:55 作者: rapoo

作业题,大概框架都写出,细节出错,求助!
#include <iostream>

using namespace std;

class CDate
{
public:
CDate(){}
void setDate();
void display();
~CDate(){}
private:
int day;
int month;
int year;
};

void CDate::setDate()
{
cout < < "Please input day month and year: ";
cin > > day > > month > > year;
}

void CDate::display()
{
cout < < "The date is: " < < day < < '/ ' < < month < < '/ ' < < year < <endl;
}

class People
{
public:
People(int num, char s, CDate birth, char i[])
{number = num; sex = s; birthday = birth; strcpy(id, i);}
inline People(People &p);
void setData();
void display();
~People(){}
protected:
int number;
char sex;
CDate birthday;
char id[20];
};

People::People(People &p)
{
number = p.number;
sex = p.sex;
birthday = p.birthday;
strcpy(id, p.id);
}

void People::setData()
{
birthday.setDate();
cout < < "Please input number sex and id: ";
cin > > number > > sex > > id;
}

void People::display()
{
birthday.display();
cout < < "The people number is: " < < number < < endl;
cout < < "The people sex is: " < < sex < < endl;
cout < < "The people id is: " < < id < < endl;


}

class Student : virtual public People
{
public:
Student(int num, char s, CDate birth, char i[], char cla[]):People(num, s, birth, i)
{strcpy(classNO, cla);}
void setData();
void display();
protected:
char classNO[7];
};

void Student::setData()
{
People::setData();
cout < < "Please input the class NO.: ";
cin > > classNO;
}

void Student::display()
{
People::display();
cout < < "The classNO. is: " < < classNO < < endl;
}

class Teacher : virtual public People
{
public:
Teacher(int num, char s, CDate birth, char i[], char ps[], char depart[]):People(num, s, birth, i)
{strcpy(principalship, ps); strcpy(department, depart);}
Teacher(Teacher &T);
void setData();
void display();
protected:
char principalship[11];
char department[21];
};

Teacher::Teacher(Teacher &T) //从这里提示出错的
{
number = T.number;
sex = T.sex;
birthday = T.birthday;
strcpy(id, T.id);
strcpy(principalship, T.principalship);
strcpy(department, T.department);
}

void Teacher::setData()
{
People::setData();
cout < < "Please input the principalship and the department: ";
cin > > principalship > > department;
}

void Teacher::display()
{
People::display();
cout < < "The principalship is: " < < principalship < <endl;
cout < < "The department is: " < < department < < endl;


}

class Gradute : public Student
{
public:
Gradute(int num, char s, CDate birth, char i[], char cla[], char sub[], Teacher adv):
People(num, s, birth, i), Student(num, s, birth, i, cla)
{strcpy(subject, sub); adviser = adv;}
void setData();
void display();
protected:
char subject[21];
Teacher adviser;
};

void Gradute::setData()
{
Student::setData();
adviser.setData();
cout < < "Please input the subject: ";
cin > > subject;
}

void Gradute::display()
{
Student::display();
adviser.display();
cout < < "The subject is: " < < subject < < endl;
}

class TA : public Gradute, public Teacher
{
public:
TA(int nmu, char s, CDate birth, char i, char cla, char sub, Teacher adv):
People(num, s, birth, i),Student(num, s, birth, i, cla), Gradute(num, s, birth, i, cla, sub, adv){}
void setData();
void display();
};

void TA::setData()
{
Teacher::setData();
Gradute::setData();
}

void TA::display()
{
Teacher::display();
Gradute::display();
}

int main()
{
TA person;
person.setData();
person.display();
system( "pause ");
return 0;
}

我用的是DEVCPP编译器,实在是找不出该怎么修改了,请帮帮忙,下面是编译器给出的错误提示!

编译器: Default compiler
执行 g++.exe...
g++.exe "E:\Upan\C++作业\finalpeople.cpp " -o "E:\Upan\C++作业\finalpeople.exe " -I "e:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include " -I "e:\Dev-Cpp\include\c++\3.4.2\backward " -I "e:\Dev-Cpp\include\c++\3.4.2\mingw32 " -I "e:\Dev-Cpp\include\c++\3.4.2 " -I "e:\Dev-Cpp\include " -L "e:\Dev-Cpp\lib "


E:\Upan\C++作业\finalpeople.cpp: In copy constructor `Teacher::Teacher(Teacher&) ':
E:\Upan\C++作业\finalpeople.cpp:106: error: no matching function for call to `People::People() '
E:\Upan\C++作业\finalpeople.cpp:46: note: candidates are: People::People(People&)
E:\Upan\C++作业\finalpeople.cpp:33: note: People::People(int, char, CDate, char*)

E:\Upan\C++作业\finalpeople.cpp: In constructor `Gradute::Gradute(int, char, CDate, char*, char*, char*, Teacher) ':
E:\Upan\C++作业\finalpeople.cpp:134: error: no matching function for call to `Teacher::Teacher() '
E:\Upan\C++作业\finalpeople.cpp:106: note: candidates are: Teacher::Teacher(Teacher&)
E:\Upan\C++作业\finalpeople.cpp:95: note: Teacher::Teacher(int, char, CDate, char*, char*, char*)

E:\Upan\C++作业\finalpeople.cpp: In constructor `TA::TA(int, char, CDate, char, char, char, Teacher) ':
E:\Upan\C++作业\finalpeople.cpp:161: error: `num ' undeclared (first use this function)

E:\Upan\C++作业\finalpeople.cpp:161: error: (Each undeclared identifier is reported only once for each function it appears in.)
E:\Upan\C++作业\finalpeople.cpp:161: error: type `class Student ' is not a direct or virtual base of `TA '
E:\Upan\C++作业\finalpeople.cpp:161: error: no matching function for call to `Teacher::Teacher(const void**) '
E:\Upan\C++作业\finalpeople.cpp:106: note: candidates are: Teacher::Teacher(Teacher&)
E:\Upan\C++作业\finalpeople.cpp:95: note: Teacher::Teacher(int, char, CDate, char*, char*, char*)

E:\Upan\C++作业\finalpeople.cpp: In function `int main() ':
E:\Upan\C++作业\finalpeople.cpp:180: error: no matching function for call to `TA::TA() '
E:\Upan\C++作业\finalpeople.cpp:158: note: candidates are: TA::TA(TA&)
E:\Upan\C++作业\finalpeople.cpp:160: note: TA::TA(int, char, CDate, char, char, char, Teacher)

执行结束

[解决办法]
没个说明看得好累的,这段程序是要干什么总要说一下吧
[解决办法]
1.error: no matching function for call to `People::People()
你没有提供People类的默认构造函数,还有其它几处也是同样问题.Teacher类TA类也是没有默认构造函数.
2/函数TA::TA(int, char, CDate, char, char, char, Teacher)中num打错了
3.在TA的成员初始化列表中用了Student类,而Student类并不是TA的基类
就这些吧
[解决办法]
程序居然没一行注释,你太NB了
------解决方案--------------------


下面这个可以运行:


class CDate
{
public:
CDate(){setDate();}
void setDate();
void display();
~CDate(){}
private:
int day;
int month;
int year;
};

void CDate::setDate()
{
cout < < "Please input day month and year: ";
cin > > day > > month > > year;
}

void CDate::display()
{
cout < < "The date is: " < < day < < '/ ' < < month < < '/ ' < < year < <endl;
}

class People
{
public:
People(){setData();}//看你main中的调用 ,应该是所有的数据都从键盘输入,所以需要这个无参构造,而后面的有参构造倒反而是可以不要的
//People(int number, char sex, CDate birthday, char *id)//使用函数的人可能不是类的设计都,所以,尽量让函数的参数名易懂.而成员变量反而可以次要点
//{_number = number; _sex = sex; _birthday = birthday; strcpy(_id, id);}
inline People(People &p);
void setData();
void display();
~People(){}
protected:
int _number;
char _sex;
CDate _birthday;
char _id[20];
};

People::People(People &p)
{
_number = p._number;
_sex = p._sex;
_birthday = p._birthday;
strcpy(_id, p._id);
}

void People::setData()
{
//_birthday.setDate();无参构造函数默认会调用成员无参构造函数,所以这句不要.
cout < < "Please input number sex and id: ";
cin > > _number > > _sex > > _id;
}

void People::display()
{
_birthday.display();
cout < < "The people number is: " < < _number < < endl;
cout < < "The people sex is: " < < _sex < < endl;
cout < < "The people id is: " < < _id < < endl;
}

class Student : virtual public People
{
public:
Student()//因为无参构造默认会调用基类的无参构造,所以本类中的setData()可以不再调用基类setData()
{setData();}
//Student(int num, char s, CDate birth, char i[], char cla[]):People(num, s, birth, i)
// {strcpy(classNO, cla);}
void setData();
void display();
protected:
char classNO[7];
};

void Student::setData()
{
//People::setData();//因为无参构造默认会调用基类的无参构造,所以本类中的setData()可以不再调用基类setData()
cout < < "Please input the class NO.: ";
cin > > classNO;
}

void Student::display()
{
People::display();
cout < < "The classNO. is: " < < classNO < < endl;
}

class Teacher : virtual public People
{
public:
Teacher(){setData();}
//Teacher(int num, char s, CDate birth, char i[], char ps[], char depart[]):People(num, s, birth, i)
//{strcpy(principalship, ps); strcpy(department, depart);}
Teacher(Teacher &T);
void setData();
void display();
protected:
char principalship[11];
char department[21];
};

Teacher::Teacher(Teacher &T):People(T) //从这里提示出错的
{
_number = T._number;
_sex = T._sex;
_birthday = T._birthday;
strcpy(_id, T._id);
strcpy(principalship, T.principalship);
strcpy(department, T.department);
}

void Teacher::setData()
{
//People::setData();
cout < < "Please input the principalship and the department: ";
cin > > principalship > > department;
}

void Teacher::display()
{
People::display();
cout < < "The principalship is: " < < principalship < <endl;


cout < < "The department is: " < < department < < endl;
}

class Gradute : public Student
{
public:
Gradute(){setData();}
//Gradute(int num, char s, CDate birth, char i[], char cla[], char sub[], Teacher adv):
//People(num, s, birth, i), Student(num, s, birth, i, cla)
//{strcpy(subject, sub); adviser = adv;}
void setData();
void display();
protected:
char subject[21];
Teacher adviser;
};

void Gradute::setData()
{
//Student::setData();
adviser.setData();
cout < < "Please input the subject: ";
cin > > subject;
}

void Gradute::display()
{
Student::display();
adviser.display();
cout < < "The subject is: " < < subject < < endl;
}

class TA : public Gradute, public Teacher
{
public:
TA(){}
//TA(int num, char s, CDate birth, char i[], char cla[], char sub[], Teacher adv):
//People(num, s, birth, i)/*,Student(num, s, birth, i, cla)*/, Gradute(num, s, birth, i, cla, sub, adv){}
void setData();
void display();
};

void TA::setData()
{
Teacher::setData();
Gradute::setData();
}

void TA::display()
{
Teacher::display();
Gradute::display();
}

int main()
{
TA person;
//person.setData();
person.display();
system( "pause ");
return 0;
}

读书人网 >C++

热点推荐