C++第五次实验作业——项目一
2016-05-06 10:43
330 查看
一、问题及代码
项目1:程序填空
#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 // (1)
{
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 // (2)
{
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 Engineer,public Leader{ } ;// (3)
int main()
{
chairman c;
c.setname("张三");
c.setage(42);
c.setjob("处长");
c.setdep("技术处");
c.setmajor("轮机设计");
c.setprof("高级工程师");
cout <<c.getname() << "," <<c.getage()<<" 岁,担任" <<c.getdep() <<c.getjob() <<endl;
cout <<c.getprof() << ",从事" << c.getmajor()<< "专业" << "。 " << endl;
return 0;
}
二、运行结果
项目1:程序填空
#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 // (1)
{
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 // (2)
{
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 Engineer,public Leader{ } ;// (3)
int main()
{
chairman c;
c.setname("张三");
c.setage(42);
c.setjob("处长");
c.setdep("技术处");
c.setmajor("轮机设计");
c.setprof("高级工程师");
cout <<c.getname() << "," <<c.getage()<<" 岁,担任" <<c.getdep() <<c.getjob() <<endl;
cout <<c.getprof() << ",从事" << c.getmajor()<< "专业" << "。 " << endl;
return 0;
}
二、运行结果
相关文章推荐
- 设计模式的解析和实现(C++)之二十一-完结篇
- C++第五次作业
- 【学习C++】C++ Primer Plus (第六版)第十章编程练习1-8
- C++第五次实验
- 设计模式C++学习笔记之十九(State状态模式)
- c++的第一次实验2
- C++ 第五次作业
- c++第五次实验-2
- 设计模式C++学习笔记之十八(Visitor访问者模式)
- 设计模式C++学习笔记之十七(Chain of Responsibility责任链模式)
- C++作业5
- C++ 模板
- 设计模式C++学习笔记之十六(Observer观察者模式)
- c++第五次作业
- C++作业5
- c++作业5
- 设计模式C++学习笔记之十五(Composite组合模式)
- c++第五次上机实验—作业
- 设计模式C++学习笔记之十四(Iterator迭代器模式)
- 设计模式C++学习笔记之十三(Decorator装饰模式)