product.h

来自「一个自动售货机的模拟」· C头文件 代码 · 共 136 行

H
136
字号
#include <iostream>

#include <string>

#include <vector>

 

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;

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?