Sanlover

Untitled

Nov 8th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <Windows.h>
  4. using namespace std;
  5.  
  6. class Item
  7. {
  8. protected:
  9. string date;
  10. float cost;
  11. int nSold;
  12. int nRemain;
  13.  
  14. public:
  15. Item()
  16. {
  17. date = "0.0.0000";
  18. cost = 0;
  19. nSold = 0;
  20. nRemain = 0;
  21. }
  22. Item(int d, int m, int y, float c, int s, int r)
  23. {
  24. date = to_string(d) + '.' + to_string(m) + '.' + to_string(y);
  25.  
  26. cost = c;
  27. nSold = s;
  28. nRemain = r;
  29. }
  30.  
  31. int get_sold()
  32. {
  33. return nSold;
  34. }
  35. int get_remain()
  36. {
  37. return nRemain;
  38. }
  39. float get_cost()
  40. {
  41. return cost;
  42. }
  43. string get_data()
  44. {
  45. return date;
  46. };
  47.  
  48. void set_sold(int amount)
  49. {
  50. nSold = amount;
  51. };
  52. void set_remain(int amount)
  53. {
  54. nRemain = amount;
  55. };
  56. void set_cost(float value)
  57. {
  58. cost = value;
  59. };
  60. void set_data(int day, int month, int year)
  61. {
  62. date = to_string(day) + '.' + to_string(month) + '.' + to_string(year);
  63. }
  64.  
  65. friend long double percent(Item x);
  66. };
  67.  
  68. class ItemList : public Item
  69. {
  70. private:
  71. string name;
  72. Item* list;
  73. int size;
  74.  
  75. public:
  76. ItemList(string n, int s)
  77. {
  78. if (s <= 0)
  79. {
  80. cout << "Size must be pozitive";
  81. exit(0);
  82. }
  83. name = n;
  84. size = s;
  85. list = new Item[size];
  86. }
  87. Item& operator[](int index)
  88. {
  89. if (index >= size)
  90. {
  91. cout << "Array index out of bound, exiting";
  92. exit(0);
  93. }
  94. return list[index];
  95. }
  96.  
  97. friend void fillFromConsole(ItemList myList);
  98. friend void print(ItemList myList);
  99. };
  100.  
  101. void fillFromConsole(ItemList list)
  102. {
  103. cout << endl << "Заполните дни товара '" << list.name << "' :";
  104. for (int i = 0; i < list.size; i++)
  105. {
  106. float cost;
  107. int nSold, nRemain, day, month, year;
  108.  
  109. cout << endl << "[" << i + 1 << "] день" << endl;
  110.  
  111. cout << " Введите дату: " << endl;
  112. cout << " День = "; cin >> day;
  113. cout << " Месяц = "; cin >> month;
  114. cout << " Год = "; cin >> year;
  115. cout << " Стоимость = "; cin >> cost;
  116. cout << " Количество проданных = "; cin >> nSold;
  117. cout << " Количество оставшихся на складе = "; cin >> nRemain;
  118.  
  119. list[i].set_data(day, month, year);
  120. list[i].set_cost(cost);
  121. list[i].set_remain(nRemain);
  122. list[i].set_sold(nSold);
  123. }
  124. };
  125. void print(ItemList list)
  126. {
  127. cout << endl << "Лист учёта товара '" << list.name << "' :";
  128. for (int i = 0; i < list.size; i++)
  129. {
  130. cout << endl << "[" << i + 1 << "] день" << endl;
  131. cout << " Стоимость = " << list[i].get_cost() << endl;
  132. cout << " Количество проданных = " << list[i].get_sold() << endl;
  133. cout << " Количество оставшихся на складе = " << list[i].get_remain() << endl;
  134. cout << " Дата = " << list[i].get_data() << endl;
  135. cout << " Процент продаж = " << percent(list[i]) << '%' << endl;
  136. }
  137. }
  138.  
  139. int main()
  140. {
  141. SetConsoleOutputCP(1251);
  142. SetConsoleCP(1251);
  143.  
  144. string firstName, secondName, thirdName;
  145. int firstDays, secondDays, thirdDays;
  146.  
  147. ItemList* first, * second, * third;
  148.  
  149. first = second = third = nullptr;
  150.  
  151. cout << "Введите название первого товара = ";
  152. getline(cin, firstName);
  153. cout << "Введите количество дней учёта = ";
  154. cin >> firstDays;
  155.  
  156. cout << endl << "Введите название второго товара = ";
  157. cin.ignore();
  158. getline(cin, secondName);
  159. cout << "Введите количество дней учёта = ";
  160. cin >> secondDays;
  161.  
  162. cout << endl << "Введите название третьего товара = ";
  163. cin.ignore();
  164. getline(cin, thirdName);
  165. cout << "Введите количество дней учёта = ";
  166. cin >> thirdDays;
  167.  
  168. first = new ItemList(firstName, firstDays);
  169. second = new ItemList(secondName, secondDays);
  170. third = new ItemList(thirdName, thirdDays);
  171.  
  172. fillFromConsole(*first);
  173. fillFromConsole(*second);
  174. fillFromConsole(*third);
  175.  
  176. cout << endl << endl;
  177. print(*first);
  178. print(*second);
  179. print(*third);
  180.  
  181. return 0;
  182. }
  183.  
  184. long double percent(Item x)
  185. {
  186. return (double(x.nSold) / x.nRemain) * 100;
  187. };
Add Comment
Please, Sign In to add comment