#include
using namespace std;
class Product
{
public:
Product(string n,int p,int q); //构造函数
~Product(){}; //析构函数
void buy(int money) ; //购买产品
void get() const; //显示剩余产品数量
private:
string name; //产品名称
int price; //产品单价
int quantity; //剩余产品数量
};
Product::Product(string n,int p,int q)
{
name=n;
price=p;
quantity=q;
}
void Product::buy(int money)
{
cout<<"名称:"<<name<<",单价:"<<price<<endl;
cout<<"顾客使用"<<money<<",购买"<<money/price<<"台,";
cout<<"剩余"<<money-price*(money/price)<<"元"<<endl;
}
****_void Product::get() const
{
cout<<"产品:"<<name<<",单价:"<<price<<",剩余:"<<money<<"台"<<endl;
}****_
int main()
{
Product p("Iphone6",99,20);
p.buy(10);
p.get();
cout<<"\n==========================\n"<<endl;
p.buy(1000);
p.get();
return 0;
}