Advertisement
Sanlover

Untitled

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