标签:
/* *Copyright (c) 2016,烟台大学计算机学院 *All rights reserved. *文件名称 : *作 者 : 刘云 *完成日期 : 2016年5月8号 *版 本 号 : v6.0 * *问题描述 : 警察和厨师
*输入描述 : 无 *程序输出 : */ #include<iostream> #include<cstring> using namespace std; class Person { public: Person(int a,string nam):age(a),name(nam){} void action(); int getage(){return age;} string getname(){return name;} private: int age; string name; }; void Person::action() { cout<<"姓名:"<<name<<" 年龄:"<<age<<" 平时最爱做的事为吃饭、睡觉、打豆豆!!!"<<endl; } class Polic:public Person { public: Polic(int a,string nam,int l):Person(a,nam),level(l){} void arrest(Person); private: int level; }; void Polic::arrest(Person per) { cout<<"获得犯罪分子的姓名:"<<per.getname()<<" 获得犯罪分子的年龄:"<<per.getage()<<"\n************该罪犯被逮获!!!"<<endl; } class Cook:public Person { public: Cook(int a,string nam,double s):Person(a,nam),salary(s){} string getcake(int); private: double salary; string cake; }; string Cook::getcake(int n) { switch(n) { case 0: cake="Helveticrolls"; return cake; case 1: cake="Tiramisu"; return cake; case 2: cake="Souffle"; return cake; case 3: cake="BostonCreamPie"; return cake; case 4: cake="Yule log"; return cake; case 5: cake="Cheesecake"; return cake; default : cake="不存在"; return cake; } } int main() { int n; string ccake; Person per(23,"Alice"); Polic po(18,"juice",6); Cook co(56,"apple",2000); per.action(); po.arrest(po); cout<<"0*************************** Helveticrolls"<<endl; cout<<"1*************************** Tiramisu"<<endl; cout<<"2*************************** Souffle"<<endl; cout<<"3*************************** BostonCreamPie"<<endl; cout<<"4*************************** Yule log"<<endl; cout<<"5*************************** Cheesecake"<<endl; cout<<"请输入所选蛋糕的序号:"; cin>>n; ccake=co.getcake(n); cout<<"您所选的蛋糕为:"<<ccake<<endl; return 0; }
运行结果:
标签:
原文地址:http://blog.csdn.net/jingmin52296358al/article/details/51345250