
这是一篇复习类的博客,主要综合运用以下知识:
格式化输入输出及打印菜单
类的封装
类的组合
子函数概念
共享指针
lambda表达式
头文件为了简便,就把类的声明和实现写在同一个VendingMachine.h文件里了
12345678#pragma once#include <string>#include <vector>#include <unordered_map>#include <iostream>#include <algorithm>#include <windows.h>using namespace std; //展开std命名空间
这里一次性给出所用的头文件,后文便不再添加了
封装商品类售货机当然要管理商品啦,那怎么管理呢?依然是先描述,再组织
怎么描述?把它封装成商品类
1234567891011struct Item{public: Item(const string& name,double price,int cnt) :_name(name),_price( ...