主题:[讨论]关于重载,有不明白的地方,希望可以指教一下,谢谢
3.建立一个简单的学校人员管理系统,包括对学生、员工和在职学生(既是员工又是学生)的管理。需要完成如下功能
(1)建立一个SCHOOL类,在其中定义按照姓名增加人员的APPEND函数,删除人员的DELETE的函数和SEARCH的查询函数
(以姓名为为准)。
(2)建立一个基类PERSON类,要具有姓名和性别的属性,并把输出函数SHOWME()定义为纯虚函数;
(3)建立一个员工STAFF类和一个学生类,均由PERSON继承而来。要求可以输出员工类(学生类)对象的属性(姓名、性别和工作证号码(或学生学号),分别写出对SHOWME()函数的具体实现。
(4)建立一个在职学生类STAFF_STUDENT类,由员工类和学生类继承而来。写出对SHOWME()函数的具体实现,可以输出对象属性。
(5)重载,实现用CIN为员工类、学生类和在职学生类对象赋值。
(6)编写MAIN()主函数,测试上述功能。
#include <iostream>
#include <cstring>
using namespace std;
class school
{
public:
void APPEND();
void DELETE();
void SEARCH();
};
class person
{
protected:
string name;
char sex;
public:
virtual void show()=0;
};
class student:virtual public person
{
protected:
string stunum;
public:
void set(string na,char se,string num){name=na;sex=se;stunum=num;}
void show();
};
void student::show()
{
//cout<<"姓名:"<<name;
// cout<<"性别:"<<sex;
cout<<"学生卡号:"<<stunum<<endl;
}
class staff:virtual public person
{
protected:
string stanum;
public:
void set(string num){stunum=num;}
void show();
};
void staff::show()
{
cout<<"姓名:"<<name<<endl<<"性别:"<<sex<<endl<<"学生卡号:"<<stanum<<endl;
}
class satff_student:public student,public staff
{
public:
void show();
};
void satff_student::show()
{
cout<<student::show()<<endl;
cout<<stanum<<endl;
}
int main()
{
student stu;
stu.set("时刻",'m',"134324324");
stu.show();
return 0;
}
--------------------Configuration: 3 - Win32 Debug--------------------
Compiling...
3.cpp
c:\documents and settings\administrator\桌面\练习c+\第9次作业\3\3.cpp(36) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char
> >' (or there is no acceptable conversion)
c:\documents and settings\administrator\桌面\练习c+\第9次作业\3\3.cpp(50) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char
> >' (or there is no acceptable conversion)
c:\documents and settings\administrator\桌面\练习c+\第9次作业\3\3.cpp(61) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'void' (or there is no acceptable conversion)
c:\documents and settings\administrator\桌面\练习c+\第9次作业\3\3.cpp(62) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char
> >' (or there is no acceptable conversion)
执行 cl.exe 时出错.
3.obj - 1 error(s), 0 warning(s)
上述是我的作业,总是不对,请指导下···谢谢
(1)建立一个SCHOOL类,在其中定义按照姓名增加人员的APPEND函数,删除人员的DELETE的函数和SEARCH的查询函数
(以姓名为为准)。
(2)建立一个基类PERSON类,要具有姓名和性别的属性,并把输出函数SHOWME()定义为纯虚函数;
(3)建立一个员工STAFF类和一个学生类,均由PERSON继承而来。要求可以输出员工类(学生类)对象的属性(姓名、性别和工作证号码(或学生学号),分别写出对SHOWME()函数的具体实现。
(4)建立一个在职学生类STAFF_STUDENT类,由员工类和学生类继承而来。写出对SHOWME()函数的具体实现,可以输出对象属性。
(5)重载,实现用CIN为员工类、学生类和在职学生类对象赋值。
(6)编写MAIN()主函数,测试上述功能。
#include <iostream>
#include <cstring>
using namespace std;
class school
{
public:
void APPEND();
void DELETE();
void SEARCH();
};
class person
{
protected:
string name;
char sex;
public:
virtual void show()=0;
};
class student:virtual public person
{
protected:
string stunum;
public:
void set(string na,char se,string num){name=na;sex=se;stunum=num;}
void show();
};
void student::show()
{
//cout<<"姓名:"<<name;
// cout<<"性别:"<<sex;
cout<<"学生卡号:"<<stunum<<endl;
}
class staff:virtual public person
{
protected:
string stanum;
public:
void set(string num){stunum=num;}
void show();
};
void staff::show()
{
cout<<"姓名:"<<name<<endl<<"性别:"<<sex<<endl<<"学生卡号:"<<stanum<<endl;
}
class satff_student:public student,public staff
{
public:
void show();
};
void satff_student::show()
{
cout<<student::show()<<endl;
cout<<stanum<<endl;
}
int main()
{
student stu;
stu.set("时刻",'m',"134324324");
stu.show();
return 0;
}
--------------------Configuration: 3 - Win32 Debug--------------------
Compiling...
3.cpp
c:\documents and settings\administrator\桌面\练习c+\第9次作业\3\3.cpp(36) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char
> >' (or there is no acceptable conversion)
c:\documents and settings\administrator\桌面\练习c+\第9次作业\3\3.cpp(50) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char
> >' (or there is no acceptable conversion)
c:\documents and settings\administrator\桌面\练习c+\第9次作业\3\3.cpp(61) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'void' (or there is no acceptable conversion)
c:\documents and settings\administrator\桌面\练习c+\第9次作业\3\3.cpp(62) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char
> >' (or there is no acceptable conversion)
执行 cl.exe 时出错.
3.obj - 1 error(s), 0 warning(s)
上述是我的作业,总是不对,请指导下···谢谢