YTU 2954: A改错题--是虫还是草
2954: A改错题--是虫还是草
时间限制: 1 Sec 内存限制: 128 MB
提交: 83 解决: 55
题目描述
冬虫夏草为虫体与菌座相连而成,冬天是虫子,夏天却是草。根据类生物(biological),虫(insect),草(grass),虫草(insectgrass)的继承关系,输出生物的名字。
注:本题只需要提交修改和完善部分的代码,请按照C++方式提交。
#include <iostream>
using namespace std;
class Biological
{
public:
Biological(string name) { this->name=name; }
virtual void Say() =0;
virtual ~Biological() {}
string GetName() { return name; }
private:
string name;
};
/* 修改和完善该部分代码
class Insect:virtual public Biological
{
public:
Insect(string name):Biological(name) {}
virtual void Say() { cout<<this->GetName()<<"是虫"<<endl; }
virtual ~Insect() {}
};
class Grass:virtual public Biological
{
public:
Grass(string name):Biological(name) {}
virtual ~Grass() {}
};
class InsectGrass:public Insect,public Grass
{
public:
InsectGrass(string name):Insect(name),Grass(name) {}
virtual ~InsectGrass() {}
};
*/
int main()
{
Biological *p[3];
string name;
getline(cin,name);
p[0]=new Insect(name);
getline(cin,name);
p[1]=new Grass(name);
getline(cin,name);
p[2]=new InsectGrass(name);
for(int i=0; i<3; i++)
{
p[i]->Say();
delete p[i];
}
return 0;
}
输入
第一行,虫的名字
第二行,草的名字
第三行,虫草的名字
输出
每行输出相应的名字及类别。
样例输入
Coccinellidae
Prunella vulgaris
Cordyceps sinensis
样例输出
Coccinellidae是虫
Prunella vulgaris是草
Cordyceps sinensis是虫也是草
你 离 开 了 , 我 的 世 界 里 只 剩 下 雨 。 。 。
#include <iostream>
using namespace std;
class Biological
{
public:
Biological(string name)
{
this->name=name;
}
virtual void Say() =0;
virtual ~Biological() {}
string GetName()
{
return name;
}
private:
string name;
};
class Insect:virtual public Biological
{
public:
Insect(string name):Biological(name) {}
void Say()
{
cout<<this->GetName()<<"是虫"<<endl;
}
virtual ~Insect() {}
};
class Grass:virtual public Biological
{
public:
Grass(string name):Biological(name) {}
void Say()
{
cout<<this->GetName()<<"是草"<<endl;
}
virtual ~Grass() {}
};
class InsectGrass:public Insect,public Grass
{
public:
InsectGrass(string name):Insect(name),Grass(name),Biological(name) {}
void Say()
{
cout<<this->GetName()<<"是虫也是草"<<endl;
}
virtual ~InsectGrass() {}
};
int main()
{
Biological *p[3];
string name;
getline(cin,name);
p[0]=new Insect(name);
getline(cin,name);
p[1]=new Grass(name);
getline(cin,name);
p[2]=new InsectGrass(name);
for(int i=0; i<3; i++)
{
p[i]->Say();
delete p[i];
}
return 0;
}
#include <iostream>
using namespace std;
class Biological
{
public:
Biological(string name)
{
this->name=name;
}
virtual void Say() =0;
virtual ~Biological() {}
string GetName()
{
return name;
} private:
string name;
};
class Insect:virtual public Biological
{
public:
Insect(string name):Biological(name) {}
void Say()
{
cout<<this->GetName()<<"是虫"<<endl;
}
virtual ~Insect() {}
};
class Grass:virtual public Biological
{
public:
Grass(string name):Biological(name) {}
void Say()
{
cout<<this->GetName()<<"是草"<<endl;
}
virtual ~Grass() {}
};
class InsectGrass:public Insect,public Grass
{
public:
InsectGrass(string name):Insect(name),Grass(name),Biological(name) {}
void Say()
{
cout<<this->GetName()<<"是虫也是草"<<endl;
}
virtual ~InsectGrass() {}
};
int main()
{
Biological *p[3];
string name;
getline(cin,name);
p[0]=new Insect(name);
getline(cin,name);
p[1]=new Grass(name);
getline(cin,name);
p[2]=new InsectGrass(name);
for(int i=0; i<3; i++)
{
p[i]->Say();
delete p[i];
}
return 0;
}
YTU 2954: A改错题--是虫还是草的更多相关文章
- YTU 2610: A改错题--体检情况分析
2610: A改错题--体检情况分析 时间限制: 1 Sec 内存限制: 128 MB 提交: 233 解决: 161 题目描述 注:本题只需要提交标记为修改部分之间的代码,请按照C++方式提交. ...
- YTU 2609: A改错题--学生信息的输入和输出
2609: A改错题--学生信息的输入和输出 时间限制: 1 Sec 内存限制: 128 MB 提交: 238 解决: 157 题目描述 注:本题只需要提交标记为修改部分之间的代码,请按照C++方 ...
- YTU 2955: A改错题--销售部的打印机
2955: A改错题--销售部的打印机 时间限制: 1 Sec 内存限制: 128 MB 提交: 61 解决: 47 题目描述 销售部新进了一台快速打印机,使用频率很高.为了能够对打印情况进行统计 ...
- YTU 2580: 改错题----修改revert函数
2580: 改错题----修改revert函数 时间限制: 1 Sec 内存限制: 128 MB 提交: 194 解决: 82 题目描述 修改revert函数,实现输入N个数,顺序倒置后输出 #i ...
- YTU 2844: 改错题A-看电影
2844: 改错题A-看电影 时间限制: 1 Sec 内存限制: 128 MB 提交: 69 解决: 47 题目描述 注:本题只需要提交标记为修改部分之间的代码,请按照C++方式提交. 小平家长为 ...
- YTU 2838: 改错题AB-装置连接
2838: 改错题AB-装置连接 时间限制: 1 Sec 内存限制: 128 MB 提交: 81 解决: 49 题目描述 注:本题只需要提交标记为修改部分之间的代码,请按照C++方式提交. 有AB ...
- YTU 2960: 改错题--小鼠标,你要干什吗?
2960: 改错题--小鼠标,你要干什吗? 时间限制: 1 Sec 内存限制: 128 MB 提交: 118 解决: 62 题目描述 鼠标双击不同的图标产生不同的效果,比如双击文档(documen ...
- YTU 2639: 改错题:类中私有成员的访问
2639: 改错题:类中私有成员的访问 时间限制: 1 Sec 内存限制: 128 MB 提交: 431 解决: 297 题目描述 /* 改错题: 设计一个日期类和时间类,并编写全局函数displ ...
- YTU 2622: B 虚拟继承(虚基类)-沙发床(改错题)
2622: B 虚拟继承(虚基类)-沙发床(改错题) 时间限制: 1 Sec 内存限制: 128 MB 提交: 487 解决: 393 题目描述 有一种特殊的床,既能当床(Bed)用又能当沙发(S ...
随机推荐
- js总结(三):面向对象,prototype ,oo模拟
http://aralejs.org/class/docs/competitors.html http://javascript.crockford.com/prototypal.html proto ...
- springmvc ajax传值详解
- zoj 2109 FatMouse' Trade
FatMouse' Trade Time Limit: 2 Seconds Memory Limit: 65536 KB FatMouse prepared M pounds of cat ...
- K/3Cloud 分页报表示例参考
分页报表首先需要实现的方法就是GetList,这个方法用来获得分页的条件. 其他的就和其他报表类似了. using System; using System.Collections.Generic; ...
- c/s程序版本自动升级的问题,如何判断client端版本号是否最新,然后从指定ftp服务器down
c/s程序版本自动升级的问题,如何判断client端版本号是否最新,然后从指定ftp服务器down http://blog.csdn.net/delphizhou/article/details/30 ...
- Educational Codeforces Round 37 (Rated for Div. 2) G
G. List Of Integers time limit per test 5 seconds memory limit per test 256 megabytes input standard ...
- 2018 江苏省邀请赛 H
题目链接 https://nanti.jisuanke.com/t/28872 解析 递推 直接套杜教板子 AC代码 #include <cstdio> #include <cstr ...
- P2863 [USACO06JAN]牛的舞会The Cow Prom
洛谷——P2863 [USACO06JAN]牛的舞会The Cow Prom 题目描述 The N (2 <= N <= 10,000) cows are so excited: it's ...
- Generate Parentheses(组合,回溯)
Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...
- mysql.bat
cls @echo off :设置窗口字体颜色 color 0a :设置窗口标题 TITLE MySQL管理程序 call :checkAdmin goto menu :菜单 :men ...