1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#include <string>
#include <iostream>
#include <map>
class Stock {
int code {};
std::string name;
double valuePerUnit {};
public:
Stock() {}
Stock(int code_, const std::string& name_, double vpu) : code(code_), name(name_), valuePerUnit(vpu) {}
void display() const {
std::cout << code << "\t" << name << "\t" << valuePerUnit;
}
double getval() const { return valuePerUnit; }
bool operator<(const Stock& other) const
{
return (name < other.name);
}
};
class Invoice {
int numberInvoice {};
int dateIssue {};
std::map<Stock, int> goods;
public:
Invoice() {}
Invoice(int _numberInvoice, int _dateIssue) : numberInvoice(_numberInvoice), dateIssue(_dateIssue) {}
void addGood(Stock s, int num) { goods[s] += num; }
void display() const {
std::cout << "\nInvoice " << numberInvoice << '\n';
std::cout << "Date of issue " << dateIssue << '\n';
std::cout << "Goods:\n";
std::cout << "Code\t" << "Name\t" << "vpu\t" << "Num\t" << "Value\n";
double total {};
for (const auto& [s, num] : goods) {
const auto gtot {num * s.getval()};
s.display();
std::cout << "\t" << num << '\t' << gtot << '\n';
total += gtot;
}
std::cout << "\nInvoice total: " << total << '\n';
}
};
int main() {
Stock s1 {1, "s1", 1};
Stock s2 {2, "s2", 2};
Invoice i1 {1, 1};
i1.addGood(s1, 2);
i1.addGood(s2, 3);
i1.display();
}
|