#include <iostream>
#include <string>
using namespace std;
class Person
{
string name; // 姓名
int age; // 年龄
public:
Person() {}
void setname(string na)
{
name=na;
}
void setage(int a)
{
age=a;
}
string getname()
{
return name;
}
int getage()
{
return age;
}
};
class Leader: virtual public Person
{
string job; // 职务
string dep; // 部门
public:
Leader() { }
void setjob(string jb)
{
job=jb;
}
void setdep(char dp[])
{
dep=dp;
}
string getjob()
{
return job;
}
string getdep()
{
return dep;
}
};
class Engineer: virtual public Person
{
string major; // 专业
string prof; // 职称
public:
Engineer () { }
void setmajor(string maj)
{
major=maj;
}
void setprof(string pf)
{
prof=pf;
}
string getmajor()
{
return major;
}
string getprof()
{
return prof;
}
};
class chairman: public Leader, public Engineer { } ;
int main()
{
chairman c;
//初始化:
c.setname("张三");
c.setage(42);
c.setjob("处长");
c.setdep("技术处");
c.setmajor("轮机设计");
c.setprof("高级工程师");
//cout:
cout <<c.getname() << "," <<c.getage()<<" 岁,担任" <<c.getdep() <<c.getjob() <<endl;
cout <<c.getprof() << ",从事" << c.getmajor()<< "专业" << "。 " << endl;
return 0;
}
C++第五次作业
最新推荐文章于 2023-05-07 21:38:55 发布