/*
* Copyright (c) 2016,烟台大学计算机与控制工程学院
* All rights reserved.
* 文件名称:main.cpp
* 作 者:王俊锐
* 完成日期:2016年6月9日
* 版 本 号:v1.0
*
* 问题描述:根据图示写出代码,增加对象扩充代码。
*/
#include <iostream>
using namespace std;
class Person
{
public:
Person(int a,string na):age(a),name(na){};
void action();
void show()
{
cout<<"姓名:"<<name<<" 年龄:"<<age<<endl;
}
string getname(){return name;}
private:
int age;
string name;
};
void Person::action()
{
cout<<"学习,运动,吃喝"<<endl;
}
class Polic:public Person
{
public:
Polic(int a,string n,int l,int ag,string na):Person(a,n),level(l),leader(ag,na){};
void arresr(Person p);
private:
int level;
Person leader;
};
void Polic::arresr(Person p)
{
cout<<level<<"级警官 "<<getname()<<"领导:";
leader.show();
cout<<"逮捕犯人"<<endl;
p.show();
}
class Cook:public Person
{
public:
Cook(int a,string nam,double n,Polic m);
string getCake(int );
void display();
private:
double salary;
Polic protector;
};
Cook::Cook(int a,string nam,double n,Polic m):Person(a,nam),salary(n),protector(m){}
string Cook::getCake(int n)
{
string s;
s="四喜丸子";
return s;
}
void Cook::display()
{
cout<<endl<<"Cook";
show();
cout<<"工资:"<<salary<<endl;
cout<<"保护者:";
protector.show();
}
int main()
{
Person a(21,"zhangsan");
Polic b(25,"lisi",5,35,"liwu");
b.arresr(a);
Cook c(26,"wangwu",5000,b);
c.display();
<pre code_snippet_id="1683715" snippet_file_name="blog_20160514_1_6387797" name="code" class="cpp"> return 0;
第十一周 项目三 警察与厨师(2)
最新推荐文章于 2016-06-13 14:35:18 发布