C++高手赐教,请帮忙编写下面这道题。

3.设计一个基类Person,包含name数据成员:由它派生出学生类Student和教师类Teacher,其中学生类添加学号no数据,教师类添加职称title数据;每个类... 3.设计一个基类Person,包含name数据成员:由它派生出学

生类Student和教师类Teacher,其中学生类添加学号no数据,

教师类添加职称title数据;每个类要定义构造函数和输出成

员的函数;然后由学生类Student和教师类Teacher派生

S_Teacher类(这类人是在学校读书的在职教师)。请给出测

试用例。
展开
 我来答
忘至白葬不情必0T
2012-01-10 · TA获得超过3万个赞
知道大有可为答主
回答量:1.1万
采纳率:90%
帮助的人:1.2亿
展开全部
#include <iostream>
#include <string>
using namespace std;

class Person{
public:
Person(){name="";}
Person(string n){
name=n;
}
~Person(){}
virtual void print(){}
protected:
string name;
};

class Student:virtual public Person{
public:
Student(){name=no="";}
Student(string name,string no){
this->name=name;
this->no=no;
}
~Student(){}
void print(){
cout<<"Student "<<no<<":"<<name<<endl;
}
protected:
string no;
};

class Teacher:virtual public Person{
public:
Teacher(){name=title="";}
Teacher(string name,string title){
this->name=name;
this->title=title;
}
~Teacher(){}
void print(){
cout<<"Teacher "<<name<<":"<<title<<endl;
}
protected:
string title;
};

class S_Teacher:public Student,public Teacher{
public:
S_Teacher(){name=no=title="";}
S_Teacher(string name,string no,string title){
this->name=name;
this->no=no;
this->title=title;
}
~S_Teacher(){}
void print(){
cout<<"S_Teacher "<<name<<":"<<no<<","<<title<<endl;
}
};

void main()
{
Student a("Tom","12345");
Teacher b("Lucy","Pro");
S_Teacher c("Li Lei","9999","ass");
a.print();
b.print();
c.print();
}
hkqbs163
2012-01-10 · 超过22用户采纳过TA的回答
知道答主
回答量:83
采纳率:0%
帮助的人:55万
展开全部
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

class person
{
public:
person(string i):name(i){};
void personout(){cout<<name;};
private:
string name;

};

class student: public person{
public:
student(string i,int j):person(i),no(j){};
void stout(){cout<<no;};
private:
int no;
};

class teacher: public person{
public:
teacher(string i,string j):person(i),title(j){};
void tout(){cout<<title;};
private:
string title;

};

class S_Teacher: public teacher, public student{

};
int main()
{
system("pause");

}

通过编译
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式