Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <Windows.h>
- //struct Data
- //{
- // int day;
- // int month;
- // int year;
- //
- // Data()
- // {
- // day = 0;
- // month = 0;
- // year = 0;
- // }
- // Data(int day, int month, int year) : day(day), month(month), year(year)
- // {
- // }
- //};
- //
- using namespace std;
- class Item
- {
- protected:
- string date;
- float cost;
- int nSold;
- int nRemain;
- public:
- Item()
- {
- date = "0.0.0000";
- cost = 0;
- nSold = 0;
- nRemain = 0;
- }
- Item(int d, int m, int y, float c, int s, int r)
- {
- date = to_string(d) + '.' + to_string(m) + '.' + to_string(y);
- cost = c;
- nSold = s;
- nRemain = r;
- }
- int get_sold()
- {
- return nSold;
- }
- int get_remain()
- {
- return nRemain;
- }
- float get_cost()
- {
- return cost;
- }
- string get_data()
- {
- return date;
- };
- void set_sold(int amount)
- {
- nSold = amount;
- };
- void set_remain(int amount)
- {
- nRemain = amount;
- };
- void set_cost(float value)
- {
- cost = value;
- };
- void set_data(int day, int month, int year)
- {
- date = to_string(day) + '.' + to_string(month) + '.' + to_string(year);
- }
- friend long double percent(Item x);
- };
- class ItemList : public Item
- {
- private:
- string name;
- Item* list;
- int size;
- public:
- ItemList(string n, int s)
- {
- if (s <= 0)
- {
- cout << "Size must be pozitive";
- exit(0);
- }
- name = n;
- size = s;
- list = new Item[size];
- }
- Item& operator[](int index)
- {
- if (index >= size)
- {
- cout << "Array index out of bound, exiting";
- exit(0);
- }
- return list[index];
- }
- friend void fillFromConsole(ItemList myList);
- friend void print(ItemList myList);
- };
- void fillFromConsole(ItemList list)
- {
- cout << endl << "Заполните дни товара '" << list.name << "' :";
- for (int i = 0; i < list.size; i++)
- {
- float cost;
- int nSold, nRemain, day, month, year;
- cout << endl << "[" << i + 1 << "] день" << endl;
- cout << " Введите дату: " << endl;
- cout << " День = "; cin >> day;
- cout << " Месяц = "; cin >> month;
- cout << " Год = "; cin >> year;
- cout << " Стоимость = "; cin >> cost;
- cout << " Количество проданных = "; cin >> nSold;
- cout << " Количество оставшихся на складе = "; cin >> nRemain;
- list[i].set_data(day, month, year);
- list[i].set_cost(cost);
- list[i].set_remain(nRemain);
- list[i].set_sold(nSold);
- }
- };
- void print(ItemList list)
- {
- cout << endl << "Лист учёта товара '" << list.name << "' :";
- for (int i = 0; i < list.size; i++)
- {
- cout << endl << "[" << i + 1 << "] день" << endl;
- cout << " Стоимость = " << list[i].get_cost() << endl;
- cout << " Количество проданных = " << list[i].get_sold() << endl;
- cout << " Количество оставшихся на складе = " << list[i].get_remain() << endl;
- cout << " Дата = " << list[i].get_data() << endl;
- cout << " Процент продаж = " << percent(list[i]) << '%' << endl;
- }
- }
- int main()
- {
- SetConsoleOutputCP(1251);
- SetConsoleCP(1251);
- string firstName, secondName, thirdName;
- int firstDays, secondDays, thirdDays;
- ItemList* first, * second, * third;
- first = second = third = nullptr;
- cout << "Введите название первого товара = ";
- getline(cin, firstName);
- cout << "Введите количество дней учёта = ";
- cin >> firstDays;
- cout << endl << "Введите название второго товара = ";
- cin.ignore();
- getline(cin, secondName);
- cout << "Введите количество дней учёта = ";
- cin >> secondDays;
- cout << endl << "Введите название третьего товара = ";
- cin.ignore();
- getline(cin, thirdName);
- cout << "Введите количество дней учёта = ";
- cin >> thirdDays;
- first = new ItemList(firstName, firstDays);
- second = new ItemList(secondName, secondDays);
- third = new ItemList(thirdName, thirdDays);
- fillFromConsole(*first);
- fillFromConsole(*second);
- fillFromConsole(*third);
- cout << endl << endl;
- print(*first);
- print(*second);
- print(*third);
- return 0;
- }
- long double percent(Item x)
- {
- return (double(x.nSold) / x.nRemain) * 100;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement