将下列程序补充完整,不能修改主函数的内容,使得程序的输出结果为 姓名: 王华 工号: 201107
将下列程序补充完整,不能修改主函数的内容,使得程序的输出结果为姓名:王华工号:201107#include<iostream>#include<string>usingn...
将下列程序补充完整,不能修改主函数的内容,使得程序的输出结果为
姓名: 王华
工号: 201107#include<iostream>
#include<string>
using namespace std;
class Person
{
private:
string name;
public:
Person(string name);
void show();
};
class Employee:public Person
{
private:
string eno;
public:
Employee(string eno);
void show();
};
class Teacher:public Employee
{
private:
string degree;
public:
Teacher(string degree);
void show();
};
Person::Person(string name)
{
this->name = name;
}
void Person::show()
{
cout << "姓名: " << name << endl;
}
void Employee::show()
{
cout << "工号: " << eno << endl;
}
void Teacher::show()
{
cout << "学历: " << degree << endl;
}
int main()
{
Teacher tea("王华", "20110754", "doctor");
tea.show();
return 0;
} 展开
姓名: 王华
工号: 201107#include<iostream>
#include<string>
using namespace std;
class Person
{
private:
string name;
public:
Person(string name);
void show();
};
class Employee:public Person
{
private:
string eno;
public:
Employee(string eno);
void show();
};
class Teacher:public Employee
{
private:
string degree;
public:
Teacher(string degree);
void show();
};
Person::Person(string name)
{
this->name = name;
}
void Person::show()
{
cout << "姓名: " << name << endl;
}
void Employee::show()
{
cout << "工号: " << eno << endl;
}
void Teacher::show()
{
cout << "学历: " << degree << endl;
}
int main()
{
Teacher tea("王华", "20110754", "doctor");
tea.show();
return 0;
} 展开
1个回答
展开全部
#include <iostream>#include <string>using namespace std;
class Person{private:
string name;public:
Person(){};
Person(string); void show();
};
Person::Person(string name):name(name){}
void Person::show(){
cout<<"姓名:"<<this->name<<endl;
}
class Employee:public Person{private:
string eno;public:
Employee(){};
Employee(string); void show();
};
Employee::Employee(string eno):eno(eno){}void Employee::show(){
cout<<"工号:"<<this->eno<<endl;
}
class Teacher:public Employee,Person{private:
string degree;public:
Teacher(){};
Teacher(string,string,string); void show();
};
Teacher::Teacher(string name,string eno,string degree):degree(degree){
Person(name).show();
Employee(eno).show();
}void Teacher::show(){
cout<<"学历:"<<this->degree<<endl;
}
int main(){
Teacher tea("abcdef","12345","doctor");
tea.show();
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询