自动售货机系统程序
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Coin类:
#include
#include
#include
using namespace std;
class Coin
{
public:
/**
Constructs a coin with a given name and value @param n the coin name
@param v the coin value
*/
Coin(string n, double v);
/**
Gets the coin name.
@return the name
*/
string get_name() const;
/**
Gets the coin value
@return the value
*/
double get_value() const;
private:
string name;
double value;
};
Coin::Coin(string n, double v)
{
name = n;
value = v;
}
string Coin::get_name() const
{
return name;
}
double Coin::get_value() const
{
return value;
}
Product类:
#include
#include
#include
using namespace std;
class Product
{
public:
/**
Constructs a product with a given name, price and quantity
@param n the product name
@param p the price
@param q the quantity
*/
Product(string n, double p, int q); /**
Gets the product name
@return the name
*/
string get_name() const;
/**
Gets the product price
@return the price
*/
double get_price() const;
/**
Gets the product quantity
@return the quantity
*/
int get_quantity() const;
/**
Adds to the product quantity
@param amount the amount to add */
void add_quantity(int amount); private:
string name;
double price;
int quantity;
};
Product::Product(string n, double p, int q) {
name = n;
price = p;
quantity = q;
}
string Product::get_name() const
{
return name;
}
double Product::get_price() const
{
return price;
}
int Product::get_quantity() const
{
return quantity;
}
void Product::add_quantity(int amount)
{
quantity = quantity + amount;
}
VendingMachine类:
class VendingMachine
{
public:
/**
Constructs a vending machine with no current
product selection.
*/
VendingMachine();
/**
Adds product to the machine.
@param p the product to add
*/
void add_product(Product p);
/**
Sets the currently selected product
@param name the product name
@return true if the machine has a product with the given name
*/
bool select_product(string name);
void chaxun_product();//查询当前售货机内的商品
/**
Adds a coin to pay for the currently selected product.
@param c the coin to add
@return true if sufficient coins have been added to pay for the selected product.
*/
bool add_coin(vector
/**