警察和厨师1
来源:互联网 发布:mac ps4手柄设置 编辑:程序博客网 时间:2024/05/17 08:05
#include <iostream>
using namespace std;
class Person
{
public:
Person(int a,string nam);
void action();
string getname(){return name;}
protected:
int age;
string name;
};
Person::Person(int a,string nam):age(a),name(nam){}
void Person::action()
{
cout<<"姓名:"<<name<<endl;
cout<<"年龄:"<<age<<endl;
}
class Police:public Person
{
public:
Police(int a,string nam,int l,Person p);
void arrest(Person);
void show();
private:
int level;
Person leader;
};
Police::Police(int a,string nam,int l,Person p):Person(a,nam),level(l),leader(p){}
void Police::arrest(Person p)
{
cout<<"Police"<<name<<" arrest "<<p.getname()<<endl;
}
void Police::show()
{
cout<<"Police "<<getname()<<", leader is " <<leader.getname()<<endl;
}
class Cook:public Person
{
public:
Cook(int a,string nam,double s,Police p);
void getCake(int );
void show();
private:
double salary;
Police protector;
};
Cook::Cook(int a,string nam,double s,Police p):Person(a,nam),salary(s),protector(p){}
void Cook::show()
{
cout<<"Cook "<<getname()<<" is protected by Police "<<protector.getname()<<endl;
}
void Cook::getCake(int n)
{
cout<<name<<" cook "<<n<<" cake."<<endl;
}
int main()
{
Person jerry(43,"Jerry");
Police jack(30,"Jack",2,jerry);
Cook john(24,"John",5000,jack);
jack.show();
john.show();
return 0;
}
using namespace std;
class Person
{
public:
Person(int a,string nam);
void action();
string getname(){return name;}
protected:
int age;
string name;
};
Person::Person(int a,string nam):age(a),name(nam){}
void Person::action()
{
cout<<"姓名:"<<name<<endl;
cout<<"年龄:"<<age<<endl;
}
class Police:public Person
{
public:
Police(int a,string nam,int l,Person p);
void arrest(Person);
void show();
private:
int level;
Person leader;
};
Police::Police(int a,string nam,int l,Person p):Person(a,nam),level(l),leader(p){}
void Police::arrest(Person p)
{
cout<<"Police"<<name<<" arrest "<<p.getname()<<endl;
}
void Police::show()
{
cout<<"Police "<<getname()<<", leader is " <<leader.getname()<<endl;
}
class Cook:public Person
{
public:
Cook(int a,string nam,double s,Police p);
void getCake(int );
void show();
private:
double salary;
Police protector;
};
Cook::Cook(int a,string nam,double s,Police p):Person(a,nam),salary(s),protector(p){}
void Cook::show()
{
cout<<"Cook "<<getname()<<" is protected by Police "<<protector.getname()<<endl;
}
void Cook::getCake(int n)
{
cout<<name<<" cook "<<n<<" cake."<<endl;
}
int main()
{
Person jerry(43,"Jerry");
Police jack(30,"Jack",2,jerry);
Cook john(24,"John",5000,jack);
jack.show();
john.show();
return 0;
}
0 0
- 警察和厨师1
- 警察和厨师-(1)
- 项目3-警察和厨师(1)
- 项目3-警察和厨师1
- 警察和厨师
- 警察和厨师
- 项目-警察和厨师
- 警察和厨师
- 警察和厨师
- 警察和厨师2
- 警察和厨师
- 警察和厨师(2)
- 警察和厨师-(2)
- 第十周项目四 警察和厨师(1)
- 11周3-1项目-警察和厨师 简易
- 第十、十一周项目三-警察和厨师(1)
- 第十一周项目3-警察和厨师(1)
- 第十、十一周项目4:警察和厨师(1)
- Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for U
- @dynamic
- macOS 下安装配置 Tomcat
- C++中的Sleep() 函数
- 关于卡尔曼滤波和粒子滤波最直白的解释
- 警察和厨师1
- Makefile常用函数总结
- 《STL 源码剖析》 读后感
- 编程之禅 -- 写给自己的话
- Linux经典书籍
- 各种常用类1
- HTML5 WebSocket
- Leetcode题解(Python): 9. Palindrome Number
- 警察与厨师2