Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <cmath>
  4.  
  5. struct CompanyBalance
  6. {
  7. CompanyBalance(double money, double goods)
  8. {
  9. money_ = money;
  10. goods_ = goods;
  11. }
  12. double money_;
  13. double goods_;
  14. };
  15.  
  16. struct Random
  17. {
  18. int a_;
  19. int b_;
  20.  
  21. Random()
  22. {
  23. srand(time(0));
  24. a_ = 1;
  25. b_ = 10;
  26. }
  27.  
  28. int randomNumber()
  29. {
  30. return(a_ + rand() % b_);
  31. }
  32.  
  33. int randomNumber(int a, int b)
  34. {
  35. return(a + rand() % b);
  36. }
  37. };
  38.  
  39. struct Demand
  40. {
  41. int demandCount_;
  42. int checkDemand(Random rndm)
  43. {
  44. demandCount_ = 0;
  45. for (int i = 1; i < 5; i++)
  46. {
  47. int a = 0;
  48. if ((i == 1) || (i == 4))
  49. {
  50. a = rndm.randomNumber(1, 6);
  51. }
  52. else
  53. {
  54. a = rndm.randomNumber(1, 3);
  55. }
  56. if (a == 1)
  57. {
  58. demandCount_ += i;
  59. }
  60. }
  61. return(demandCount_);
  62. }
  63. };
  64.  
  65. struct ProductOrder
  66. {
  67. double waitOrderTime_;
  68. int orderQty_;
  69. bool waitOrder_;
  70. ProductOrder()
  71. {
  72. waitOrder_ = false;
  73. waitOrderTime_ = 0;
  74. orderQty_ = 0;
  75. }
  76.  
  77. void order(CompanyBalance &cb, Random rndm)
  78. {
  79. if (orderQty_ > 0)
  80. {
  81. cb.money_ -= 32 + (3 * orderQty_);
  82. waitOrderTime_ = rndm.randomNumber(3, 5)*0.1;
  83. }
  84. else
  85. {
  86. waitOrderTime_ = 0;
  87. }
  88. }
  89.  
  90. int order(int qty)
  91. {
  92. orderQty_ = qty;
  93. if (orderQty_ > 0)
  94. {
  95. int money =( 32 + (3 * orderQty_));
  96. return(money);
  97. }
  98. }
  99.  
  100. };
  101.  
  102. struct OrderStrategy
  103. {
  104. int minProductQty_;//s
  105. int mountProductQty_;//I
  106. int lastProductQty_;//S
  107. OrderStrategy(int minproduct)
  108. {
  109. minProductQty_ = minproduct;
  110. }
  111.  
  112. int checkOrder(CompanyBalance &cb,int lastQty)
  113. {
  114. if (cb.goods_ < minProductQty_)
  115. {
  116. lastProductQty_ = lastQty;
  117. int order = lastProductQty_ -cb.goods_;
  118. return(order);
  119. }
  120. else
  121. {
  122. return(0);
  123. }
  124. }
  125. };
  126.  
  127. struct mounthTimer
  128. {
  129. double mounth_;
  130. double lastTimeDef_;
  131. mounthTimer()
  132. {
  133. mounth_ = 0;
  134. lastTimeDef_ = 0;
  135. }
  136.  
  137. double getTime()
  138. {
  139. double inta;
  140. double time;
  141. time = modf(mounth_,&inta);
  142.  
  143. return (time);
  144. }
  145.  
  146. void upTime(Random rndm)
  147. {
  148. lastTimeDef_= rndm.randomNumber(5, 11) * 0.01;//random 0.05-0.15 month;
  149. mounth_ += lastTimeDef_;
  150. }
  151.  
  152. };
  153.  
  154. struct ProductHold
  155. {
  156. int moneyHold_;
  157. int lastMoneyHold_;
  158. int ordercount_;
  159.  
  160. ProductHold()
  161. {
  162. moneyHold_ = 0;
  163. lastMoneyHold_ = 0;
  164. ordercount_ =0;
  165. }
  166.  
  167. void newMouth()
  168. {
  169. moneyHold_ = 0;
  170. lastMoneyHold_ = 0;
  171. ordercount_ = 0;
  172. }
  173.  
  174. void producthold(CompanyBalance cb, int mh)
  175. {
  176. int buff=cb.goods_ - mh;
  177. if (buff >= 0)
  178. {
  179. lastMoneyHold_ = buff;
  180. }
  181. else
  182. {
  183. lastMoneyHold_ = buff * -5;
  184. }
  185. ordercount_++;
  186. moneyHold_ += lastMoneyHold_;
  187. }
  188.  
  189. double monthHoldResult(bool a)
  190. {
  191. double result;
  192. if (a)
  193. {
  194. result = (moneyHold_-lastMoneyHold_)/(ordercount_-1);
  195.  
  196. }else
  197. {
  198. result = (moneyHold_) / ordercount_;
  199. }
  200. return(result);
  201. }
  202.  
  203.  
  204. };
  205.  
  206.  
  207. int main()
  208. {
  209. double mounth =0;
  210. std::cout << "write month:";
  211. std::cin >> mounth;
  212. double mounthN = 1;
  213. mounthN +=mounth;
  214. std::cout << "\n";
  215. int checkMouth = 0;
  216. int summDef = 0;
  217. int holdsumm = 0;
  218.  
  219. ProductHold ph;
  220. mounthTimer timer;
  221. OrderStrategy os(50);
  222. ProductOrder po;
  223. Random rm;
  224. Demand dm;
  225. CompanyBalance cb(100, 10);
  226.  
  227. while (timer.mounth_ <= mounthN)
  228. {
  229. if (timer.mounth_ >= checkMouth)
  230. {
  231. if (timer.getTime() != 0)
  232. {
  233. if (timer.mounth_)
  234. {
  235. po.orderQty_ = os.checkOrder(cb, summDef - dm.demandCount_);
  236. po.order(cb, rm);
  237. po.waitOrder_ = true;
  238. cb.money_-=ph.monthHoldResult(timer.getTime() != 0);
  239. int moun = timer.mounth_;
  240. int res = ph.monthHoldResult(timer.getTime() != 0);
  241. std::cout << "\n" << "mounth:" << moun << "\n";
  242. std::cout << "costs storage=" << res <<" costs buy="<< po.order(summDef - dm.demandCount_) << " demand=" << summDef - dm.demandCount_ << " goods=" << cb.goods_ << std::endl;
  243. }
  244. }
  245. else
  246. {
  247. if (timer.mounth_)
  248. {
  249. po.orderQty_ = os.checkOrder(cb, summDef);
  250. po.order(cb, rm);
  251. po.waitOrder_ = true;
  252. cb.money_ -= ph.monthHoldResult(timer.getTime() != 0);
  253. int moun = timer.mounth_;
  254. int res = ph.monthHoldResult(timer.getTime() != 0);
  255. std::cout << "\n" << "mounth:" << moun << "\n";
  256. std::cout << "costs storage=" << res << "costs buy=" << po.order(summDef - dm.demandCount_) << "costs buy=" << "demand=" << summDef - dm.demandCount_ << " goods=" << cb.goods_ << std::endl;
  257. }
  258. }
  259.  
  260.  
  261.  
  262. //last month money def
  263. ph.newMouth();
  264. summDef = 0;
  265. checkMouth++;
  266. }
  267. if ((po.waitOrderTime_ <= timer.getTime())&&(po.waitOrder_))
  268. {
  269. cb.goods_ += po.orderQty_;
  270. po.waitOrder_ = false;
  271. }
  272.  
  273. summDef += dm.checkDemand(rm);
  274. timer.upTime(rm);
  275. ph.producthold(cb,summDef);
  276. }
  277.  
  278. system("pause");
  279. return 0;
  280. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement