C++ STL 第五次实验
来源:互联网 发布:java数字转化为字符串 编辑:程序博客网 时间:2024/06/06 03:19
//各种头文件#include <iostream>#include <functional>#include <algorithm>#include <vector>#include <string.h>using namespace std;class FoodIngredients{ int price;public: FoodIngredients(int price):price(price){} int getPrice(){return this->price;} //纯虚函数 virtual void printDetail()=0;};class Beef:public FoodIngredients{public: Beef(int price = 12):FoodIngredients(price){} void printDetail(){cout << "Beef:" << "12 " << endl;}};class Cheese:public FoodIngredients{public: Cheese(int price = 2):FoodIngredients(price){} void printDetail(){cout << "Cheese:" << "2 " << endl;}};class Mustard:public FoodIngredients{public: Mustard(int price = 1):FoodIngredients(price){} void printDetail(){cout << "Mustard: " << "1 " << endl;}};class Onion:public FoodIngredients{public: Onion(int price = 1):FoodIngredients(price){} void printDetail(){cout << "Onion: " << "1 " << endl;}};class Tomoto:public FoodIngredients{public: Tomoto(int price = 2):FoodIngredients(price){} void printDetail(){cout << "Tomoto: " << "2 " << endl;}};class Bread:public FoodIngredients{public: Bread(int price):FoodIngredients(price){} void printDetail(){cout << "Bread: " << this->getPrice() << endl;}};class Wheat_bread:public Bread{public: Wheat_bread(int price = 7):Bread(price){} void printDetail(){cout << "Wheat_bread: " << "7 " << endl;}};class Honey_bread:public Bread{public: Honey_bread(int price = 8):Bread(price){} void printDetail(){cout << "Honey_bread: " << "8 " << endl;}};static int sum = 0;class Hotdog{private: vector<FoodIngredients *> v; Bread *m_b;public: Hotdog(Bread *b):m_b(b){} int GetTotalPrice(){ for(int i=0;i<v.size();i++){ sum += v[i]->getPrice(); } return sum; } void printDetails(){ for_each(v.begin(),v.end(),mem_fun(&FoodIngredients::printDetail)); } bool addFood(FoodIngredients *pFoodIngredients){ v.push_back(pFoodIngredients); return true; }};int main() { Hotdog *h = new Hotdog(new Wheat_bread()); h->addFood(new Beef()); h->addFood(new Cheese()); h->addFood(new Mustard()); h->addFood(new Onion()); h->addFood(new Onion()); h->addFood(new Tomoto()); h->printDetails();}
阅读全文
2 0
- C++ STL 第五次实验
- C++STL 第八次实验
- 第五次C语言上机实验报告
- 第五次C程序设计实验报告
- 第五次C语言上机实验报告
- C语言第五次上机实验
- 第五次实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次实验报告
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- 第五次上机实验
- tomcat服务器
- a+b
- Blog16@linux存储设备的管理(2)—分区
- sqlmap一力破十会
- 旋转数组的最小数字
- C++ STL 第五次实验
- canvas中的Uncaught TypeError: Cannot read property 'getContext' of null 错误
- C++:观察者模式
- [RK3288][Android6.0] 调试笔记 --- 交叉编译X264库出错
- fastjson:SerializerFeature属性使用
- 深度学习框架caffe的安装无GPU版
- python下多线程爬虫爬取斗图网的所有最新图片
- sql复杂查询:A表与B表一对多,查询A表所有用户对应B表中的数据,去除B表中的日期最大值
- 斐波那契数列