Advertisement
IllyaCod

Untitled

May 20th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.96 KB | None | 0 0
  1. function.cpp
  2. #include<iostream>
  3. #include<string>
  4. #include "Header.h"
  5.  
  6. void Automate::plusSumMoney()
  7. {
  8. cout << "You gave: " << money << " $";
  9. cout << "Please, give plus " << differntly << "$ for good sales!";
  10. double h;
  11. cin >> h;
  12. this->money += h;
  13. }
  14. void Automate::Display::Menuchoice()
  15. {
  16. cout << "1.Korona...............5(dollars)" << endl;
  17. cout << "2.Milka..............12.5(dollars)" << endl;
  18. cout << "3.Snikers.............4.5(dollars)" << endl;
  19. cout << "4.Nuts................3.8(dollars)" << endl << endl;
  20. cout << "Please, make your choice..." << endl << endl;
  21. }
  22.  
  23. void Automate::Display::setMassege(string massege)
  24. {
  25. this->massege = massege;
  26. }
  27.  
  28. string Automate::Display::printMassege()
  29. {
  30. return this->massege;
  31. }
  32. int Automate::getChoise()
  33. {
  34. return this->choise;
  35. }
  36. double Automate::getMoney()
  37. {
  38. return this->money;
  39. }
  40. Automate::Automate()
  41. {
  42. this->money = 0;
  43. this->numbersweets = 20;
  44. this->choise = 0;
  45. this->differntly = 0;
  46. }
  47. Automate::~Automate()
  48. {
  49. cout << "keep kalm!";
  50. }
  51. void Automate::MenuforYou()
  52. {
  53. display.Menuchoice();
  54. }
  55. void Automate::printMassege()
  56. {
  57. display.printMassege();
  58. }
  59. void Automate::getMoneyFromuser(User & user)
  60. {
  61. cout << "Пожалуйста внесите кюпюры номиналом 1 2 5 10 или 20 доларов" << endl;
  62. cout << "Для завершения введите 0" << endl;
  63.  
  64. this->setMoney(user.giveMoney());
  65. }
  66.  
  67. void Automate::getChoiseFromUser(User & user)
  68. {
  69. cout << "Введите номер товара: "<<endl;
  70. choise = user.doChoise();
  71. }
  72.  
  73. void Automate::giveSweets(Sweets & sweets, Automate & automate)
  74. {
  75. cout << sweets.obgortka(automate);
  76. }
  77.  
  78. bool Automate::checkMoneyPrize()
  79. {
  80. switch (this->choise)
  81. {
  82. case (1):
  83. {
  84. if (money < 5) { plusSumMoney(); }
  85.  
  86. else if (money >= 5) { cout << "Оплата прошла успешно!"<<endl; }
  87. this->differntly = money - 5;
  88. return true;
  89. break;
  90. }
  91. case (2):
  92. {
  93. if (money < 12.5) { plusSumMoney(); }
  94.  
  95. else if (money >= 12.5) { cout << "Оплата прошла успешно!"<<endl; }
  96. this->differntly = money - 12.5;
  97. return 1;
  98. break;
  99. }
  100. case (3):
  101. {
  102. if (money < 4.5) { plusSumMoney(); }
  103.  
  104. else if (money >= 4.5) { cout << "Оплата прошла успешно!"<<endl; }
  105. this->differntly = money - 4.5;
  106. return 1;
  107. break;
  108. }
  109. case (4):
  110. {
  111. if (money < 3.8) plusSumMoney();
  112.  
  113. else if (money >= 3.8) cout << "Оплата прошла успешно!"<<endl;
  114. this->differntly = money - 3.8;
  115. return 1;
  116. break;
  117. }
  118. default: cout << "Система сломана беги!"; break;
  119. }
  120. }
  121. void Automate::plusSweets()
  122. {
  123. if (this->numbersweets <= 3) this->numbersweets += 25;
  124. }
  125. void Automate::setMoney(double money)
  126. {
  127. this->money = money;
  128. }
  129. double Automate::getDifferently()
  130. {
  131. return this->differntly;
  132. }
  133. Sweets::Sweets()
  134. {
  135. this->name = "Chocolate";
  136. this->price = 20;
  137. }
  138. Sweets::~Sweets()
  139. {
  140. cout << "I am working";
  141. }
  142. void Sweets::setName(string name)
  143. {
  144. this->name = name;
  145. }
  146. string Sweets::getname()
  147. {
  148. return this->name;
  149. }
  150. void Sweets::setPrice(double price)
  151. {
  152. this->price = price;
  153. }
  154. double Sweets::getPrice()
  155. {
  156. return price;
  157. }
  158. string Sweets::obgortka(Automate & automate)
  159. {
  160. if ((automate.getChoise() == 1) && (automate.checkMoneyPrize() == true))
  161. {
  162. return "Sweets |>Korona<| Приятного апетита! ";
  163. }
  164. else if ((automate.getChoise() == 2) && (automate.checkMoneyPrize() == true))
  165. {
  166. return "Sweets |>Milka<| Приятного апетита! ";
  167. }
  168. else if ((automate.getChoise() == 3) && (automate.checkMoneyPrize() == true))
  169. {
  170. return "Sweets |>Snikers<| Приятного апетита! ";
  171. }
  172. else if ((automate.getChoise() == 4) && (automate.checkMoneyPrize() == true))
  173. {
  174. return "Sweets |>Nuts<| Приятного апетита! ";
  175. }
  176. }
  177. User::User()
  178. {
  179. this->usermoney = 1000;
  180. this->usersweets = 0;
  181. this->userchoice = 0;
  182. }
  183. User::~User()
  184. {
  185. cout << "I am working";
  186. }
  187. void User::setUserMoney()
  188. {
  189. cout << "Сколько у меня денег???"<<endl;
  190. cin >> usermoney;
  191. }
  192. double User::getUserMoney()
  193. {
  194. return this->usermoney;
  195. }
  196. void User::setUserSweets(double usersweets)
  197. {
  198. this->usersweets = usersweets;
  199. }
  200. double User::getUserSweets()
  201. {
  202. return this->usersweets;
  203. }
  204.  
  205. double User::giveMoney()
  206. {
  207. double summa = 0;
  208. int k;
  209.  
  210. do
  211. {
  212. cin >> k;
  213. if (k == 1 || k == 2 || k == 10 || k == 20 || k == 5)
  214. {
  215. this->usermoney -= k;
  216. summa += k;
  217.  
  218. }
  219.  
  220. else if (k != 0)
  221. cout << "Пожалуйста внесите кюпюры номиналом 1 2 5 10 или 20 доларов, попробуйте ещё раз!" << endl;
  222.  
  223. } while (k != 0);
  224. return summa;
  225. }
  226. int User::doChoise()
  227. {
  228.  
  229. int g;
  230. do {
  231. cin >> g;
  232. if (g < 1 || g > 4)
  233. {
  234. cout << "Неверний ответ! Попробуйте ещё раз!"<<endl;
  235. }
  236. } while (g < 1 || g > 4);
  237. this->userchoice = g;
  238. return userchoice;
  239. }
  240. void User::getSdacha(Automate & automate)
  241. {
  242. cout << "Ваша сдача" << automate.getDifferently() << " $. Незабудьте забрать сдачу!"<<endl;
  243. this->sdacha = automate.getDifferently();
  244. }
  245. Header.h
  246. #include<iostream>
  247. #include<string>
  248.  
  249. using namespace std;
  250.  
  251. class Automate;
  252.  
  253. class Candy
  254. {
  255. protected:
  256. double price;
  257. };
  258.  
  259. class Sweets : public Candy
  260. {
  261. private:
  262. string name;
  263. public:
  264. Sweets();
  265. ~Sweets();
  266. void setName(string name);
  267. string getname();
  268. void setPrice(double price);
  269. double getPrice();
  270. string obgortka(Automate& automate);
  271. };
  272.  
  273. class User
  274. {
  275. private:
  276. double usermoney;
  277. int usersweets;
  278. int userchoice;
  279. double sdacha;
  280. public:
  281. User();
  282. ~User();
  283.  
  284. void setUserMoney();
  285. double getUserMoney();
  286.  
  287. void setUserSweets(double usersweets);
  288. double getUserSweets();
  289.  
  290. //void setUserChoice(double userchoice);
  291. //double getUserChoice();
  292.  
  293. double giveMoney();
  294. int doChoise();
  295. void getSdacha(Automate& automate);
  296. };
  297.  
  298.  
  299. class Automate
  300. {
  301. private:
  302. double money;
  303. double numbersweets;
  304. int choise;
  305. double differntly;
  306. void plusSumMoney();
  307. class Display
  308. {
  309. private:
  310. string massege;
  311. public:
  312. void Menuchoice();
  313. void setMassege(string massege);
  314. string printMassege();
  315. };
  316. Display display;
  317. public:
  318. int getChoise();
  319. double getMoney();
  320. Automate();
  321. ~Automate();
  322. void MenuforYou();
  323. void printMassege();
  324. void getMoneyFromuser(User& user);
  325. void getChoiseFromUser(User& user);
  326. bool checkMoneyPrize();
  327. void giveSweets(Sweets& sweets, Automate& automate);
  328. void plusSweets();
  329. void setMoney(double money);
  330. //double getMoney() { return this->money; }
  331. double getDifferently();
  332. };
  333. source.cpp
  334. #include<iostream>
  335. #include<string>
  336. #include"Header.h"
  337.  
  338. int main()
  339. {
  340. setlocale(LC_ALL, "ru");
  341. Automate a;
  342. Sweets c;
  343. User u;
  344. u.setUserMoney();
  345. a.MenuforYou();
  346. a.getMoneyFromuser(u);
  347. a.getChoiseFromUser(u);
  348. a.checkMoneyPrize();
  349. c.obgortka(a);
  350. a.giveSweets(c, a);
  351. u.getSdacha(a);
  352. system("pause");
  353. return 0;
  354. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement