多态案例二-制作饮品

cpp 复制代码
#include<iostream>
using namespace std;
class AbsstractDrinking
{
public:
	//煮水
	virtual void Boil() = 0;
	//冲泡
	virtual void Brew() = 0;
	//倒入杯中
	virtual void PourInCup() = 0;
	//加入佐料
	virtual void Putsomething() = 0;
	void MakeDrinking()
	{
		Boil();
		Brew();
		PourInCup();
		Putsomething();
	}

};
class Coffee:public AbsstractDrinking
{
public:
	//煮水
	virtual void Boil()
	{
		cout << "煮矿泉水" << endl;
	}
	//冲泡
	virtual void Brew()
	{
		cout << "冲泡咖啡" << endl;
	}
	//倒入杯中
	virtual void PourInCup()
	{
		cout << "倒入杯中" << endl;
	}
	//加入佐料
	virtual void Putsomething()
	{
		cout << "加入牛奶和白砂糖" << endl;
	}

};
class Tea :public AbsstractDrinking
{
public:
	//煮水
	virtual void Boil()
	{
		cout << "煮农夫山泉" << endl;
	}
	//冲泡
	virtual void Brew()
	{
		cout << "冲泡茶叶" << endl;
	}
	//倒入杯中
	virtual void PourInCup()
	{
		cout << "倒入茶壶" << endl;
	}
	//加入佐料
	virtual void Putsomething()
	{
		cout << "加入枸杞和枣子" << endl;
	}

};
void doDrinking()
{
	AbsstractDrinking* abs = new Coffee;
	abs->MakeDrinking();
	delete abs;

	cout << "____________________" << endl;

	abs = new Tea;
	abs->MakeDrinking();
	delete abs;
}
void test01()
{
	doDrinking();
}
int main()
{
	test01();
	return 0;
}
相关推荐
像风一样的男人@4 小时前
python --读取psd文件
开发语言·python·深度学习
输出输入4 小时前
前端核心技术
开发语言·前端
加油,小猿猿4 小时前
Java开发日志-双数据库事务问题
java·开发语言·数据库
薛定谔的猫喵喵4 小时前
天然气压力能利用系统综合性评价平台:基于Python和PyQt5的AHP与模糊综合评价集成应用
开发语言·python·qt
.小墨迹4 小时前
apollo学习之借道超车的速度规划
linux·c++·学习·算法·ubuntu
独好紫罗兰4 小时前
对python的再认识-基于数据结构进行-a004-列表-实用事务
开发语言·数据结构·python
gjxDaniel4 小时前
Objective-C编程语言入门与常见问题
开发语言·objective-c
choke2334 小时前
[特殊字符] Python异常处理
开发语言·python
云中飞鸿4 小时前
linux中qt安装
开发语言·qt
少控科技4 小时前
QT第6个程序 - 网页内容摘取
开发语言·qt