Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "product.hpp"
- #include <iostream>
- using namespace std;
- Product::Product() {
- setName("");
- setAmount(0.0);
- setPrice(0.0);
- setUnit("");
- }
- Product::Product(string Name, double Price, string Unit, double Amount) {
- setName(Name);
- setPrice(Price);
- setUnit(Unit);
- setAmount(Amount);
- }
- void Product::setName(string name){
- this->name = name;
- }
- void Product::setUnit(string unit){
- this->unit = unit;
- }
- void Product::setPrice(double price){
- this->price = price;
- }
- void Product::setAmount(double amount){
- this->amount = amount;
- }
- string Product::getName() const{
- return name;
- }
- double Product::getPrice() const{
- return price;
- }
- double Product::getAmount() const{
- return amount;
- }
- string Product::getUnit() const{
- return unit;
- }
- double Product::getBought(){
- return bought;
- }
- void Product::buy(double amount_buy) {
- if (getAmount() < amount_buy) {
- cout << "Необходимого количества товара нет" << endl;
- cout << "Вы можете купить только " << getAmount() << " " << getUnit() << " товара " << getName() << endl;
- return;
- }
- bought = bought + amount_buy;
- setAmount(getAmount() - amount_buy);
- cout << "Вы успешно купили " << getName() << " в количестве " << amount_buy << " " << getUnit() << endl;
- }
- double Product::getProfit() {
- return getBought() * getPrice();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement