Guest User

Untitled

a guest
May 27th, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.82 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<string>
  4. #include<sstream>
  5.  
  6. using namespace std;
  7.  
  8. class PC
  9. {
  10. public:
  11. string operatingSystem, model;
  12. int ramSlots, pcieSlots, cpu, totalRamSlots, gbPerRam, ssd, cost, gpu, afterb;
  13.  
  14. virtual void Upgrade(string line) = 0;
  15. virtual void Print() = 0;
  16. PC(string m, string os, int rams, int pcies, int c, int totalRams, int gbPer, int s, int co, int g, int ab)
  17. {
  18. model = m;
  19. operatingSystem = os;
  20. ramSlots = rams;
  21. pcieSlots = pcies;
  22. cpu = c;
  23. totalRamSlots = totalRams;
  24. gbPerRam = gbPer;
  25. ssd = s;
  26. cost = co;
  27. gpu = g;
  28. afterb = ab;
  29. }
  30. };
  31.  
  32. class HomePC: public PC
  33. {
  34. public:
  35. HomePC(string _model) : PC(model, "MacOS", 2, 0, 2, 1, 4, 256, 800, 0, 0)
  36. {
  37. this->model = _model;
  38. }
  39.  
  40. void Upgrade(string line)
  41. {
  42. string tempcpu, tempTotalRamSlots, tempgbPerRam, del = " ";
  43. stringstream ss;
  44. int r = 1;
  45.  
  46. tempcpu = line.substr(0, line.find(del));
  47. line.erase(0, line.find(del) + del.length());
  48.  
  49. tempTotalRamSlots = line.substr(0, line.find(del));
  50. line.erase(0, line.find(del) + del.length());
  51.  
  52. tempgbPerRam = line.substr(0, line.find(del));
  53. line.erase(0, line.find(del) + del.length());
  54.  
  55. if(tempcpu != "1" && tempcpu != "2" && tempcpu != "4" && tempcpu != "6" && tempcpu != "8")
  56. {
  57. cout << "Error: Wrong CPU cores number." << endl;
  58. r = 0;
  59. }
  60.  
  61. if(tempTotalRamSlots != "2")
  62. {
  63. cout << "Error: Wrong RAM slots number." << endl;
  64. r = 0;
  65. }
  66.  
  67. if(tempgbPerRam != "2" && tempgbPerRam != "4" && tempgbPerRam != "8" && tempgbPerRam != "16" && tempgbPerRam != "32" && tempgbPerRam != "64" && tempgbPerRam != "128")
  68. {
  69. cout << "Error: Wrong GB per RAM number." << endl;
  70. r = 0;
  71. }
  72.  
  73. if(r == 1)
  74. {
  75. ss.clear();
  76. ss.str(tempcpu);
  77. ss >> cpu;
  78.  
  79. ss.clear();
  80. ss.str(tempTotalRamSlots);
  81. ss >> totalRamSlots;
  82.  
  83. ss.clear();
  84. ss.str(tempgbPerRam);
  85. ss >> gbPerRam;
  86. }
  87. }
  88.  
  89. void Print()
  90. {
  91. cout << "Model: " << model << endl;
  92. cout << "Operating System: " << operatingSystem << endl;
  93. cout << "CPU: " << cpu << endl;
  94. cout << "Motherboard: " << ramSlots << ", " << pcieSlots << endl;
  95. cout << "RAM: " << totalRamSlots << ", " << gbPerRam << endl;
  96. cout << "SSD: " << ssd << "GB" << endl;
  97. cout << "Cost: " << cost << "EUR" << endl;
  98. }
  99. };
  100.  
  101. class GamingPC: public PC
  102. {
  103. public:
  104. GamingPC(string _model) : PC(model, "Windows", 4, 2, 6, 2, 8, 1024, 1300, 1, 0)
  105. {
  106. this->model = _model;
  107. }
  108.  
  109. void Upgrade(string line)
  110. {
  111. string tempcpu, tempTotalRamSlots, tempgbPerRam, tempgpu, del = " ";
  112. stringstream ss;
  113. int r = 1;
  114.  
  115. tempcpu = line.substr(0, line.find(del));
  116. line.erase(0, line.find(del) + del.length());
  117.  
  118. tempTotalRamSlots = line.substr(0, line.find(del));
  119. line.erase(0, line.find(del) + del.length());
  120.  
  121. tempgbPerRam = line.substr(0, line.find(del));
  122. line.erase(0, line.find(del) + del.length());
  123.  
  124. tempgpu = line.substr(0, line.find(del));
  125. line.erase(0, line.find(del) + del.length());
  126.  
  127. if(tempcpu != "1" && tempcpu != "2" && tempcpu != "4" && tempcpu != "6" && tempcpu != "8")
  128. {
  129. cout << "Error: Wrong CPU cores number." << endl;
  130. r = 0;
  131. }
  132.  
  133. if(tempTotalRamSlots != "2" && tempTotalRamSlots != "4")
  134. {
  135. cout << "Error: Wrong RAM slots number." << endl;
  136. r = 0;
  137. }
  138.  
  139. if(tempgbPerRam != "2" && tempgbPerRam != "4" && tempgbPerRam != "8" && tempgbPerRam != "16" && tempgbPerRam != "32" && tempgbPerRam != "64" && tempgbPerRam != "128")
  140. {
  141. cout << "Error: Wrong GB per RAM number." << endl;
  142. r = 0;
  143. }
  144.  
  145. if(tempgpu != "0" && tempgpu != "1" && tempgpu != "2")
  146. {
  147. cout << "Error: Wrong GPU number." << endl;
  148. r = 0;
  149. }
  150.  
  151. if(r == 1)
  152. {
  153. ss.clear();
  154. ss.str(tempcpu);
  155. ss >> cpu;
  156.  
  157. ss.clear();
  158. ss.str(tempTotalRamSlots);
  159. ss >> totalRamSlots;
  160.  
  161. ss.clear();
  162. ss.str(tempgbPerRam);
  163. ss >> gbPerRam;
  164.  
  165. ss.clear();
  166. ss.str(tempgpu);
  167. ss >> gpu;
  168. }
  169. }
  170.  
  171. void Print()
  172. {
  173. cout << "Model: " << model << endl;
  174. cout << "Operating System: " << operatingSystem << endl;
  175. cout << "CPU: " << cpu << endl;
  176. cout << "Motherboard: " << ramSlots << ", " << pcieSlots << endl;
  177. cout << "RAM: " << totalRamSlots << ", " << gbPerRam << endl;
  178. cout << "SSD: " << ssd << "GB" << endl;
  179. cout << "GPU: " << gpu << endl;
  180. cout << "Cost: " << cost << "EUR" << endl;
  181. }
  182. };
  183.  
  184. class WorkstationPC: public PC
  185. {
  186. public:
  187. WorkstationPC(string _model) : PC(model, "Linux", 8, 1, 6, 4, 16, 2048, 1600, 0, 0)
  188. {
  189. this->model = _model;
  190. }
  191.  
  192. void Upgrade(string line)
  193. {
  194. string tempcpu, tempTotalRamSlots, tempgbPerRam, tempgpu, tempafterb, del = " ";
  195. stringstream ss;
  196. int r = 1;
  197.  
  198. tempcpu = line.substr(0, line.find(del));
  199. line.erase(0, line.find(del) + del.length());
  200.  
  201. tempTotalRamSlots = line.substr(0, line.find(del));
  202. line.erase(0, line.find(del) + del.length());
  203.  
  204. tempgbPerRam = line.substr(0, line.find(del));
  205. line.erase(0, line.find(del) + del.length());
  206.  
  207. tempgpu = line.substr(0, line.find(del));
  208. line.erase(0, line.find(del) + del.length());
  209.  
  210. tempafterb = line.substr(0, line.find(del));
  211. line.erase(0, line.find(del) + del.length());
  212.  
  213. if(tempcpu != "1" && tempcpu != "2" && tempcpu != "4" && tempcpu != "6" && tempcpu != "8")
  214. {
  215. cout << "Error: Wrong CPU cores number." << endl;
  216. r = 0;
  217. }
  218.  
  219. if(tempTotalRamSlots != "2" && tempTotalRamSlots != "4" && tempTotalRamSlots != "6" && tempTotalRamSlots != "8")
  220. {
  221. cout << "Error: Wrong RAM slots number." << endl;
  222. r = 0;
  223. }
  224.  
  225. if(tempgbPerRam != "2" && tempgbPerRam != "4" && tempgbPerRam != "8" && tempgbPerRam != "16" && tempgbPerRam != "32" && tempgbPerRam != "64" && tempgbPerRam != "128")
  226. {
  227. cout << "Error: Wrong GB per RAM number." << endl;
  228. r = 0;
  229. }
  230.  
  231. if(tempgpu != "0" && tempgpu != "1")
  232. {
  233. cout << "Error: Wrong GPU number." << endl;
  234. r = 0;
  235. }
  236.  
  237. if(tempafterb != "0" && tempafterb != "1")
  238. {
  239. cout << "Error: Wrong Afterburner number. 1" << endl;
  240. r = 0;
  241. } else if(gpu == 0 && tempafterb == "1")
  242. {
  243. cout << "Error: Wrong Afterburner number. 2" << endl;
  244. r = 0;
  245. }
  246.  
  247. if(r == 1)
  248. {
  249. ss.clear();
  250. ss.str(tempcpu);
  251. ss >> cpu;
  252.  
  253. ss.clear();
  254. ss.str(tempTotalRamSlots);
  255. ss >> totalRamSlots;
  256.  
  257. ss.clear();
  258. ss.str(tempgbPerRam);
  259. ss >> gbPerRam;
  260.  
  261. ss.clear();
  262. ss.str(tempgpu);
  263. ss >> gpu;
  264.  
  265. ss.clear();
  266. ss.str(tempafterb);
  267. ss >> afterb;
  268. }
  269. }
  270.  
  271. void Print()
  272. {
  273. cout << "Model: " << model << endl;
  274. cout << "Operating System: " << operatingSystem << endl;
  275. cout << "CPU: " << cpu << endl;
  276. cout << "Motherboard: " << ramSlots << ", " << pcieSlots << endl;
  277. cout << "RAM: " << totalRamSlots << ", " << gbPerRam << endl;
  278. cout << "SSD: " << ssd << "GB" << endl;
  279. cout << "GPU: " << gpu << endl;
  280. cout << "Afterburner: " << afterb << endl;
  281. cout << "Cost: " << cost << "EUR" << endl;
  282. }
  283. };
  284.  
  285. int main()
  286. {
  287. string line, cmd, del = " ";
  288. vector<PC*> pcList;
  289. int i;
  290.  
  291. while(getline(cin, line))
  292. {
  293. cmd = line.substr(0, line.find(del));
  294. line.erase(0, line.find(del) + del.length());
  295.  
  296. if(cmd == "new")
  297. {
  298. string type, model;
  299.  
  300. type = line.substr(0, line.find(del));
  301. line.erase(0, line.find(del) + del.length());
  302. model = line.substr(0, line.find(del));
  303.  
  304. if(type == "homepc")
  305. {
  306. HomePC* homepc = new HomePC(model);
  307. pcList.push_back(homepc);
  308. }
  309. else if(type == "gamingpc")
  310. {
  311. GamingPC* gamingpc = new GamingPC(model);
  312. pcList.push_back(gamingpc);
  313. }
  314. else if(type == "workstationpc")
  315. {
  316. WorkstationPC* workstationpc = new WorkstationPC(model);
  317. pcList.push_back(workstationpc);
  318. }
  319. } else if(cmd == "upgrade")
  320. {
  321. string model;
  322.  
  323. model = line.substr(0, line.find(del));
  324. line.erase(0, line.find(del) + del.length());
  325.  
  326. for(i = 0; i < pcList.size(); i++)
  327. {
  328. if(pcList[i]->model == model)
  329. {
  330. pcList[i]->Upgrade(line);
  331. }
  332. }
  333. } else if(cmd == "delete")
  334. {
  335. string model;
  336.  
  337. model = line.substr(0, line.find(del));
  338. line.erase(0, line.find(del) + del.length());
  339.  
  340. for(i = 0; i < pcList.size(); i++)
  341. {
  342. if(pcList[i]->model == model)
  343. {
  344. //pcList[i].erase(pcList.begin(), pcList.end());
  345. }
  346. }
  347. } else if(cmd == "print")
  348. {
  349. cout << endl;
  350. string type;
  351.  
  352. type = line.substr(0, line.find(del));
  353. line.erase(0, line.find(del) + del.length());
  354.  
  355. for(i = 0; i < pcList.size(); i++)
  356. {
  357. if(type == "homepc")
  358. {
  359. if(pcList[i]->operatingSystem == "MacOS")
  360. pcList[i]->Print();
  361. } else if(type == "gamingpc")
  362. {
  363. if(pcList[i]->operatingSystem == "Windows")
  364. pcList[i]->Print();
  365. } else if(type == "workstationpc")
  366. {
  367. if(pcList[i]->operatingSystem == "Linux")
  368. pcList[i]->Print();
  369. }
  370. cout << endl;
  371. }
  372. }
  373. }
  374. }
Add Comment
Please, Sign In to add comment