Problem A: 让动物们叫起来吧!
Description
Tom家里养了很多动物,比如有鸭子、火鸡和公鸡。它们的叫声都不相同。现在,请编写类Animal、Cock、Turkey和Duck,根据给出的main()函数及样例分析每个类的属性、行为及相互关系,以模仿Tom家的情况。
提示:动物们都有自己的名字。
Input
输入有多行。第一行正整数M表示之后有M个测试用例,每个测试用例包括2部分:前一部分是动物的名字,后一部分是动物的类型(用A、B、C分别表示鸭子、火鸡和公鸡)。
Output
输出有M行,每个测试用例对应一样。见样例。
Sample Input
Sample Output
HINT
Append Code
int main(){ int cases; string name; char type; Animal *animal; cin>>cases; for (int i = 0; i < cases; i++) { cin>>name>>type; switch(type) { case 'A': animal = new Duck(name); break; case 'B': animal = new Turkey(name); break; case 'C': animal = new Cock(name); break; } animal->sound(); } return 0;}#include <iostream>using namespace std;class Animal{ public: Animal(){} virtual void sound(){}};class Cock:public Animal{ string name1;public: Cock(string n):name1(n){} void sound() { cout<<name1<<" is a cock, and it can crow."<<endl; }};class Turkey:public Animal{ string name2;public: Turkey(string n):name2(n){} void sound() { cout<<name2<<" is a turkey, and it can gobble."<<endl; }};class Duck:public Animal{ string name3;public: Duck(string n):name3(n){} void sound() { cout<<name3<<" is a duck, and it can quack."<<endl; }};int main(){ int cases; string name; char type; Animal *animal; cin>>cases; for (int i = 0; i < cases; i++) { cin>>name>>type; switch(type) { case 'A': animal = new Duck(name); break; case 'B': animal = new Turkey(name); break; case 'C': animal = new Cock(name); break; } animal->sound(); } return 0;}Problem A: 让动物们叫起来吧!的更多相关文章
- 实验12:Problem J: 动物爱好者
#define null ""是用来将字符串清空的 #define none -1是用来当不存在这种动物时,返回-1. 其实这种做法有点多余,不过好理解一些. Home Web B ...
- Problem 2128 最长子串(kmp+strstr好题经典)
Problem 2128 最长子串 Accept: 134 Submit: 523Time Limit: 3000 mSec Memory Limit : 65536 KB Probl ...
- Problem E: 动物爱好者
Problem E: 动物爱好者 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 882 Solved: 699[Submit][Status][Web ...
- 《动物世界》的剪刀石头布 HDU --- 6418
题目连接: https://vjudge.net/problem/1812686/origin emmm 这一题的资料来自<动物世界>这一个李易峰演的电影.. 主要的思路就是概率,但是会牵 ...
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
随机推荐
- css复合选择器的权重
选择器的权重 标签选择器的权重为0001 class选择器的权重为0010 id选择器的权重为0100 属性选择器的权重为0010 伪类选择器的权重为0010 伪元素选择器的权重为0010 包含选择器 ...
- 生信工具汇总--OMICtools
各种生信工具: https://omictools.com/
- C# 封装SDK 获取摄像头的水平角度和垂直角度
最近需要做一个C#版本的控制终端,控制摄像头,获取摄像头的水平角度和垂直角度 获取当前摄像头的角度,需要调用一个名为NET_DVR_GetDVRConfig的bool类型的函数 在C++中,函数定义: ...
- CSS之垂直水平居中方法
//居中方法1 position: absolute; top: 0; left: 0; right: 0; bottom: 0; margin: auto; width: 346px; height ...
- java中捕获Oracle异常
try{ } catch (Exception e){ String msg=.getMessage(): int index= msg. toUpperCase(). indexOf("O ...
- Lab 10-3
This lab includes a driver and an executable. You can run the executable from anywhere, but in order ...
- vue版 文字滚动
用法:<marque :text="bannerText"></marque> 下载
- 在tensorflow中使用batch normalization
问题 训练神经网络是一个很复杂的过程,在前面提到了深度学习中常用的激活函数,例如ELU或者Relu的变体能够在开始训练的时候很大程度上减少梯度消失或者爆炸问题,但是却不能保证在训练过程中不出现该问题, ...
- 树莓派 连接 JY901(MPU9250) python 代码
先说BUG,最近要做项目需要树莓派和陀螺仪,资金充足的话肯定是买一个硬件卡尔曼滤波的传感器类似JY901模块,资金不足的就买MPU6050. 网上关于MPU6050在树莓派上的代码还能用,关于JY90 ...
- ArcGIS中删除“点”附带的对应“文本信息”
现状: 用ArcMap打开对应的.mxd文件,导入KML数据后,几何类型“点” - 每一个点都附带对应的文本信息“Placemark”,如下图: 问题:ArcGIS中如何 删除“点”附带的对应“文本信 ...