Advertisement
Metaraddin

Untitled

Mar 25th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.88 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. struct Banknote
  7. {
  8. int OneRub = 0;
  9. int TwoRub = 0;
  10. int FiveRub = 0;
  11. int TenRub = 0;
  12. int FiftyRub = 0;
  13. int HundredRub = 0;
  14. int TwoHundredRub = 0;
  15. int FiveHundredRub = 0;
  16. int ThousandRub = 0;
  17. int TwoThousandRub = 0;
  18. int FiveThousandRub = 0;
  19. int Sum = (OneRub + TwoRub + FiveRub + TenRub + FiftyRub + HundredRub + TwoHundredRub + FiveHundredRub + ThousandRub + TwoThousandRub + FiveThousandRub);
  20. };
  21.  
  22. struct Ingredient
  23. {
  24. int Cup = 1;
  25. int Water = 1;
  26. int Milk = 0;
  27. int WhippedMilk = 0;
  28. int IceCream = 0;
  29. int Chocolate = 0;
  30. int Sugar = 0;
  31. int CoffeeIng = 1;
  32. };
  33.  
  34. struct Coffee
  35. {
  36. string Name;
  37. int Price;
  38. Ingredient Recipe;
  39. };
  40.  
  41. void NewListOfRecipes(); // Объявление и заполнения массива с рецептами.
  42. Banknote InputOneBanknote(Banknote & Balance); // Приём одной банкноты.
  43. void InputMoney(Coffee ListOfRecipes[], int CoffeeNum, Banknote & Balance); // Вызов InputBanknote, пока не наберётся нужная сумма.
  44. Banknote OutputMoneyCheck(Coffee ListOfRecipes[], int CoffeeNum, Banknote & Balance, Banknote Amount, int & check); // Возвращает сдачу, если её можно выдать, и принятые купюры, если нельзя.
  45.  
  46. int main()
  47. {
  48. Banknote Balance;
  49. Banknote Amount;
  50. Banknote Surrender;
  51. NewListOfRecipes();
  52. return 0;
  53. }
  54.  
  55. void NewListOfRecipes()
  56. {
  57. Coffee ListOfRecipes[7];
  58.  
  59. ListOfRecipes[0].Name = "Espresso";
  60. ListOfRecipes[0].Price = 30;
  61.  
  62. ListOfRecipes[1].Name = "Cappuccino";
  63. ListOfRecipes[1].Price = 35;
  64. ListOfRecipes[1].Recipe.Milk = 1;
  65. ListOfRecipes[1].Recipe.WhippedMilk = 1;
  66.  
  67. ListOfRecipes[2].Name = "Glasse";
  68. ListOfRecipes[2].Price = 50;
  69. ListOfRecipes[2].Recipe.IceCream = 1;
  70. ListOfRecipes[2].Recipe.Chocolate = 1;
  71.  
  72. ListOfRecipes[3].Name = "Ristretto";
  73. ListOfRecipes[3].Price = 35;
  74. ListOfRecipes[3].Recipe.CoffeeIng = 2;
  75.  
  76. ListOfRecipes[4].Name = "Mocha";
  77. ListOfRecipes[4].Price = 60;
  78. ListOfRecipes[4].Recipe.Milk = 1;
  79. ListOfRecipes[4].Recipe.WhippedMilk = 1;
  80. ListOfRecipes[4].Recipe.Chocolate = 1;
  81.  
  82. ListOfRecipes[5].Name = "Americano";
  83. ListOfRecipes[5].Price = 25;
  84. ListOfRecipes[5].Recipe.Water = 2;
  85.  
  86. ListOfRecipes[6].Name = "Mochaccino";
  87. ListOfRecipes[6].Price = 50;
  88. ListOfRecipes[6].Recipe.Chocolate = 1;
  89. ListOfRecipes[6].Recipe.Milk = 1;
  90.  
  91. Banknote Balance;
  92.  
  93. Balance.FiveThousandRub = Balance.FiveThousandRub + 1;
  94. Balance.TwoThousandRub = Balance.TwoThousandRub + 1;
  95. Balance.ThousandRub = Balance.ThousandRub + 2;
  96. Balance.FiveHundredRub = Balance.FiveHundredRub + 2;
  97. Balance.TwoHundredRub = Balance.TwoHundredRub + 2;
  98. Balance.HundredRub = Balance.HundredRub + 5;
  99. Balance.FiftyRub = Balance.FiftyRub + 5;
  100. Balance.TenRub = Balance.TenRub + 10;
  101. Balance.FiveRub = Balance.FiveRub + 20;
  102. Balance.TwoRub = Balance.TwoRub + 30;
  103. Balance.OneRub = Balance.OneRub + 40;
  104.  
  105. Ingredient Precence;
  106.  
  107. Precence.Cup = Precence.Cup + 10;
  108. Precence.Water = Precence.Water + 10;
  109. Precence.Milk = Precence.Milk + 10;
  110. Precence.WhippedMilk = Precence.WhippedMilk + 10;
  111. Precence.IceCream = Precence.IceCream + 10;
  112. Precence.Chocolate = Precence.Chocolate + 10;
  113. Precence.Sugar = Precence.Sugar + 10;
  114. Precence.CoffeeIng = Precence.CoffeeIng + 10;
  115. }
  116.  
  117. Banknote InputOneBanknote(Banknote & Balance)
  118. {
  119. Banknote Amount;
  120. int BankInd;
  121. int Check = 0;
  122. cin >> BankInd;
  123.  
  124. do
  125. {
  126. switch (BankInd)
  127. {
  128. Check = 1;
  129. case 1 :
  130. {
  131. Amount.OneRub = Amount.OneRub + 1;
  132. Balance.OneRub = Balance.OneRub + 1;
  133. break;
  134. }
  135. case 2:
  136. {
  137. Amount.TwoRub = Amount.TwoRub + 1;
  138. Balance.TenRub = Balance.TenRub + 1;
  139. break;
  140. }
  141. case 5:
  142. {
  143. Amount.FiveRub = Amount.FiveRub + 1;
  144. Balance.FiftyRub = Balance.FiftyRub + 1;
  145. break;
  146. }
  147. case 10:
  148. {
  149. Amount.TenRub = Amount.TenRub + 1;
  150. Balance.TenRub = Balance.TenRub + 1;
  151. break;
  152. }
  153. case 50:
  154. {
  155. Amount.FiftyRub = Amount.FiftyRub + 1;
  156. Balance.FiftyRub = Balance.FiftyRub + 1;
  157. break;
  158. }
  159. case 100:
  160. {
  161. Amount.HundredRub = Amount.HundredRub + 1;
  162. Balance.HundredRub = Balance.HundredRub + 1;
  163. break;
  164. }
  165. case 200:
  166. {
  167. Amount.TwoHundredRub = Amount.TwoHundredRub + 1;
  168. Balance.TwoHundredRub = Balance.TwoHundredRub + 1;
  169. break;
  170. }
  171. case 500:
  172. {
  173. Amount.FiveHundredRub = Amount.FiveHundredRub + 1;
  174. Balance.FiveHundredRub = Balance.FiveHundredRub + 1;
  175. break;
  176. }
  177. case 1000:
  178. {
  179. Amount.ThousandRub = Amount.ThousandRub + 1;
  180. Balance.ThousandRub = Balance.ThousandRub + 1;
  181. break;
  182. }
  183. case 2000:
  184. {
  185. Amount.TwoThousandRub = Amount.TwoThousandRub + 1;
  186. Balance.TwoThousandRub = Balance.TwoThousandRub + 1;
  187. break;
  188. }
  189. case 5000:
  190. {
  191. Amount.FiveThousandRub = Amount.FiveThousandRub + 1;
  192. Balance.FiveThousandRub = Balance.FiveThousandRub + 1;
  193. break;
  194. }
  195. default:
  196. {
  197. Check = 0;
  198. break;
  199. }
  200. }
  201. } while (Check = 0);
  202. return (Amount);
  203. }
  204.  
  205. void InputMoney(Coffee ListOfRecipes[], int CoffeeNum, Banknote & Balance)
  206. {
  207. Banknote Amount;
  208. do
  209. {
  210. Amount = InputOneBanknote(Balance);
  211. } while (Amount.Sum >= ListOfRecipes[CoffeeNum].Price);
  212. }
  213.  
  214. Banknote OutputMoneyCheck(Coffee ListOfRecipes[], int CoffeeNum, Banknote & Balance, Banknote Amount, int & check)
  215. {
  216. Banknote Surrender;
  217. int IAmountSum = Amount.Sum - ListOfRecipes[CoffeeNum].Price;
  218. if (IAmountSum <= Balance.Sum)
  219. {
  220. while (IAmountSum >= 5000 && Balance.FiveThousandRub >= 1)
  221. {
  222. Surrender.FiveThousandRub = Surrender.FiveThousandRub + 1;
  223. IAmountSum = IAmountSum - 5000;
  224. }
  225. while (IAmountSum >= 2000 && Balance.TwoThousandRub >= 1)
  226. {
  227. Surrender.TwoThousandRub = Surrender.TwoThousandRub + 1;
  228. IAmountSum = IAmountSum - 2000;
  229. }
  230. while (IAmountSum >= 1000 && Balance.ThousandRub >= 1)
  231. {
  232. Surrender.ThousandRub = Surrender.ThousandRub + 1;
  233. IAmountSum = IAmountSum - 1000;
  234. }
  235. while (IAmountSum >= 500 && Balance.FiveHundredRub >= 1)
  236. {
  237. Surrender.FiveHundredRub = Surrender.FiveHundredRub + 1;
  238. IAmountSum = IAmountSum - 500;
  239. }
  240. while (IAmountSum >= 100 && Balance.HundredRub >= 1)
  241. {
  242. Surrender.HundredRub = Surrender.HundredRub + 1;
  243. IAmountSum = IAmountSum - 100;
  244. }
  245. while (IAmountSum >= 50 && Balance.FiftyRub >= 1)
  246. {
  247. Surrender.FiftyRub = Surrender.FiftyRub + 1;
  248. IAmountSum = IAmountSum - 50;
  249. }
  250. while (IAmountSum >= 10 && Balance.TenRub >= 1)
  251. {
  252. Surrender.TenRub = Surrender.TenRub + 1;
  253. IAmountSum = IAmountSum - 10;
  254. }
  255. while (IAmountSum >= 5 && Balance.FiveRub >= 1)
  256. {
  257. Surrender.FiveRub = Surrender.FiftyRub + 1;
  258. IAmountSum = IAmountSum - 5;
  259. }
  260. while (IAmountSum >= 2 && Balance.TwoRub >= 1)
  261. {
  262. Surrender.TwoRub = Surrender.TwoRub + 1;
  263. IAmountSum = IAmountSum - 2;
  264. }
  265. while (IAmountSum >= 1 && Balance.OneRub >= 1)
  266. {
  267. Surrender.OneRub = Surrender.OneRub + 1;
  268. IAmountSum = IAmountSum - 1;
  269. }
  270. if (IAmountSum = 0)
  271. {
  272. check = 1;
  273. return Surrender;
  274. }
  275. else
  276. {
  277. // Автомат не может дать сдачу, вместо сдачи возвращаются принятые купюры.
  278. return Amount;
  279. }
  280. }
  281. else
  282. {
  283. // Автомат не может дать сдачу, вместо сдачи возвращаются принятые купюры.
  284. return Amount;
  285. }
  286. }
  287.  
  288. void OutputMoney(Banknote Surrender, Banknote & Balance)
  289. {
  290. Balance.FiveThousandRub = Balance.FiveThousandRub - Surrender.FiveThousandRub;
  291. Balance.TwoThousandRub = Balance.TwoThousandRub - Surrender.TwoThousandRub;
  292. Balance.ThousandRub = Balance.ThousandRub - Surrender.ThousandRub;
  293. Balance.FiveHundredRub = Balance.FiveHundredRub - Surrender.FiveHundredRub;
  294. Balance.TwoHundredRub = Balance.TwoHundredRub - Surrender.TwoHundredRub;
  295. Balance.HundredRub = Balance.HundredRub - Surrender.HundredRub;
  296. Balance.FiftyRub = Balance.FiftyRub - Surrender.FiftyRub;
  297. Balance.TenRub = Balance.TenRub - Surrender.TenRub;
  298. Balance.FiveRub = Balance.FiveRub - Surrender.FiveRub;
  299. Balance.TwoRub = Balance.TwoRub - Surrender.TwoRub;
  300. Balance.OneRub = Balance.OneRub - Surrender.OneRub;
  301. }
  302.  
  303. void OutputCoffee(Ingredient Precence, Coffee ListOfRecipes[], int CoffeeNum)
  304. {
  305. Precence.Chocolate = Precence.Chocolate - ListOfRecipes[CoffeeNum].Recipe.Chocolate;
  306. Precence.CoffeeIng = Precence.CoffeeIng - ListOfRecipes[CoffeeNum].Recipe.CoffeeIng;
  307. Precence.Cup = Precence.Cup - ListOfRecipes[CoffeeNum].Recipe.Cup;
  308. Precence.IceCream = Precence.IceCream - ListOfRecipes[CoffeeNum].Recipe.IceCream;
  309. Precence.Milk = Precence.Milk - ListOfRecipes[CoffeeNum].Recipe.Milk;
  310. Precence.Sugar = Precence.Sugar - ListOfRecipes[CoffeeNum].Recipe.Sugar;
  311. Precence.Water = Precence.Water - ListOfRecipes[CoffeeNum].Recipe.Water;
  312. Precence.WhippedMilk = Precence.WhippedMilk - ListOfRecipes[CoffeeNum].Recipe.WhippedMilk;
  313. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement