1).cpp
Код:
#include <iostream>
#include "Goods.h"
Goods::Goods(std::string name, std::string date, int price, int amount, int number) : name(name), date(date), price(price), amount(amount), number(number) {}
void Goods::SetGoods (std::string name, std::string date, int price, int amount, int number) {}
std::string& Goods::GetName()const { return name; } //получить название товара
std::string& Goods::GetDate()const { return date; } //получить дату оформления
int Goods::GetPrice()const { return price; } //получить цену товара
int Goods::PriceIncrease(int n) { return price += n; } //количество товара увеличить на заданное число
int Goods::PriceDecrease(int n) { return price -= n; } //количество товара уменьшить на заданное число
int Goods::GetAmount()const { return amount; } //получить количество товара
int Goods::GetNumber()const { return number; } //получить номер накладной
std::string Goods::ToStringPrice()const { return std::to_string(price); } //получить цену товара в виде строки
int Goods::GetTotalCost()const { return price * amount; } //получить общую стоимость
int Goods::GetCost(int n)const { return price * n; } //получить стоимость заданного числа товара
int Goods::AmountIncrease(int n) { return amount +=n; } //количество товара увеличить на заданное число
int Goods::AmountDecrease(int n) { return amount -= n; } //количество товара уменьшить на заданное число
2) Goods.h
Код:
#pragma once
#include <string>
class Goods
{
private:
std::string name; //название
std::string date; //дата оформления
int price{}; //цена
int amount{}; //количество
int number{}; //номер накладной
public:
Goods() = default;
Goods(std::string name, std::string date, int price, int amount, int number): name(name), date(date), price(price), amount(amount), number(number){}
void SetGoods (std::string name, std::string date, int price{}, int amount{}, int number{});
void SetName(std::string s) { name = s; } //задать название товара
void SetDate(std::string s) { date = s; } //задать дату оформления
void SetPrice(int p) { price = p; } //задать цену товара
void SetAmount(int a) { amount = a; } //задать количество товара
void SetNumber(int n) { number = n; } //задать номер накладной
//количество товара увеличить на заданное число
void PriceIncrease(int n) { price += n; }
//количество товара уменьшить на заданное число
void PriceDecrease(int n) { price -= n; }
//количество товара увеличить на заданное число
void AmountIncrease(int n) { amount += n; }
//количество товара уменьшить на заданное число
void AmountDecrease(int n) { amount -= n; }
int GetGoods(std::string name, std::string date, int price{}, int amount{}, int number{});
int GetName(std::string s);
int GetDate(std::string s);
int GetPrice(int p);
int GetAmount(int a);
int GetNumber(int n);
};
3) main.cpp
Код:
#include <iostream>
#include <string>
#include "Goods.h"
int main()
{
Goods g{ "milk", "22/12/2002", 55, 6, 7 };
std::cout << "Name:"<< g.GetName() << "\n";
std::cout << "Date:" << g.GetDate() << "\n";
std::cout << "Price:" << g.GetPrice() << "\n";
std::cout << "Amount:" << g.GetAmount() << "\n";
std::cout << "Number:" << g.GetNumber() << "\n";
std::cout << "Total cost:" << g.GetTotalCost() << "\n";
std::cout << "Cost:" << g.GetCost(5) << "\n";
std::cout << "Amount increase!"; g.AmountIncrease(5);
std::cout << "New amount:" << g.GetAmount() << "\n";
std::cout << "Price Increase!"; g.PriceIncrease(5);
std::cout << "New price:" << g.GetPrice() << "\n";
return 0;
}
В main.cpp на 21 строчке выдает ошибку - Class "Goods" не содержит члена "PriceIncrease". Как это исправить?