-
. z
Coin类:
*include <iostream>
*include <string>
*includy() 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
-
. z
return true if the machine has a product with the given
name
*/
bool select_product(string name);
void cha*un_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<Coin> current_pay);
/**
Removes all coins that were added to pay for the current
product.
return the value of the returned coins
*/
double return_coins();
/**
Removes all money that was paid for products.
return the value of the money
*/
double remove_money();
double add_coinbijiao(vector<Coin> current_pay );//对投入的金钱和所购置的商品的价格进展比较
double return_yiyoucoins();//统计售货机中已有的货款
void setcurrent_product();//把当前选择的商品代号置为-1
int getcurrent_product();//得到当前选择的商品代号
private:
vector<Product> products;
-
. z
int current_product;
vector<Coin> current_payment;
vector<Coin> coins;
};
VendingMachine::VendingMachine()
{
current_product = -1;
}
void VendingMachine::add_product(Product p)//添加商品
{
for (int i = 0; i < (); i++)
{
if (products[i].get_name() == () && pro
自动售货机系统程序 来自淘豆网m.daumloan.com转载请标明出处.