Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.83 KB | None | 0 0
  1. #include <windows.h>
  2. #include <iostream>
  3. #include <string>
  4. #include <fstream>
  5. #include <algorithm>
  6. #include <vector>
  7. using namespace std;
  8.  
  9.  
  10.  
  11.  
  12. class Details {
  13.  
  14. };
  15.  
  16. class CPU : public Details {
  17. public:
  18. void read(vector <string>& box, string pathCPU) {
  19. ifstream fin;
  20.  
  21. fin.open(pathCPU);
  22.  
  23. string str;
  24.  
  25.  
  26. while (!fin.eof())
  27. {
  28. str = "";
  29. getline(fin, str);
  30.  
  31. box.push_back(str);
  32.  
  33. }
  34. fin.close();
  35. }
  36. };
  37.  
  38. class Motherboard : public Details {
  39. public:
  40. void read(vector <string>& box, string pathMotherboard) {
  41. ifstream fin;
  42.  
  43. fin.open(pathMotherboard);
  44.  
  45. string str;
  46.  
  47. while (!fin.eof())
  48. {
  49. str = "";
  50. getline(fin, str);
  51. box.push_back(str);
  52. }
  53.  
  54.  
  55. fin.close();
  56. }
  57.  
  58. };
  59.  
  60. class Gaphics_card : public Details {
  61. public:
  62. void read(vector <string>& box, string pathGaphics_card) {
  63. ifstream fin;
  64.  
  65. fin.open(pathGaphics_card);
  66.  
  67. string str;
  68. while (!fin.eof())
  69. {
  70. str = "";
  71. getline(fin, str);
  72. box.push_back(str);
  73. }
  74.  
  75. fin.close();
  76. }
  77. };
  78.  
  79. class RAM : public Details {
  80. public:
  81. void read(vector <string>& box, string pathRAM) {
  82. ifstream fin;
  83.  
  84. fin.open(pathRAM);
  85.  
  86. string str;
  87.  
  88. while (!fin.eof())
  89. {
  90. str = "";
  91. getline(fin, str);
  92. box.push_back(str);
  93. }
  94.  
  95. fin.close();
  96. }
  97. };
  98.  
  99. class Power_Supply : public Details {
  100. public:
  101. void read(vector <string>& box, string pathPower_Supply) {
  102. ifstream fin;
  103.  
  104. fin.open(pathPower_Supply);
  105.  
  106. string str;
  107.  
  108. while (!fin.eof())
  109. {
  110. str = "";
  111. getline(fin, str);
  112. box.push_back(str);
  113. }
  114.  
  115. fin.close();
  116. }
  117. };
  118.  
  119. class Corps : public Details {
  120. public:
  121. void read(vector <string>& box, string pathCorps) {
  122. ifstream fin;
  123.  
  124. string str;
  125.  
  126. while (!fin.eof())
  127. {
  128. str = "";
  129. getline(fin, str);
  130. box.push_back(str);
  131. }
  132.  
  133. fin.close();
  134. }
  135. };
  136.  
  137. class Cooler : public Details {
  138. public:
  139. void read(vector <string>& box, string pathCooler) {
  140. ifstream fin;
  141.  
  142. fin.open(pathCooler);
  143.  
  144. string str;
  145.  
  146. while (!fin.eof())
  147. {
  148. str = "";
  149. getline(fin, str);
  150. /* if str != " " */
  151. box.push_back(str);
  152. }
  153.  
  154. fin.close();
  155. }
  156. };
  157.  
  158. class SSD : public Details {
  159. public:
  160. void read(vector <string>& box, string pathSSD) {
  161.  
  162. ifstream fin;
  163.  
  164. fin.open(pathSSD);
  165.  
  166. string str;
  167.  
  168. while (!fin.eof())
  169. {
  170. str = "";
  171. getline(fin, str);
  172. box.push_back(str);
  173. }
  174.  
  175. fin.close();
  176. }
  177.  
  178.  
  179. };
  180.  
  181. class HDD : public Details {
  182. public:
  183. void read(vector <string>& box, string pathHDD) {
  184. ifstream fin;
  185.  
  186. fin.open(pathHDD);
  187.  
  188. string str;
  189.  
  190. while (!fin.eof())
  191. {
  192. str = "";
  193. getline(fin, str);
  194. box.push_back(str);
  195. }
  196. fin.close();
  197. }
  198.  
  199. };
  200. void menu2(int n, int& m2, vector <string>& box, string pathCPU, string pathMotherboard, string pathGaphics_card, string pathRAM,
  201. string pathPower_Supply, string pathCorps, string pathCooler, string pathSSD, string pathHDD, CPU a,
  202. Motherboard b, Gaphics_card c, RAM d, Power_Supply e, Corps f, Cooler g, SSD h, HDD i);
  203. void menu1(int m2, vector <string>& box, string pathCPU, string pathMotherboard, string pathGaphics_card, string pathRAM,
  204. string pathPower_Supply, string pathCorps, string pathCooler, string pathSSD, string pathHDD, CPU a,
  205. Motherboard b, Gaphics_card c, RAM d, Power_Supply e, Corps f, Cooler g, SSD h, HDD i);
  206. void Sohrn(int n, int m2, vector <string>& box, string pathCPU, string pathMotherboard, string pathGaphics_card, string pathRAM,
  207. string pathPower_Supply, string pathCorps, string pathCooler, string pathSSD, string pathHDD);
  208.  
  209.  
  210. void create(vector <string>& box, string pathCPU, string pathMotherboard, string pathGaphics_card, string pathRAM,
  211. string pathPower_Supply, string pathCorps, string pathCooler, string pathSSD, string pathHDD)
  212. {
  213. ofstream fout1;
  214. fout1.open(pathCPU, ofstream::app);
  215. fout1.close();
  216.  
  217. ofstream fout2;
  218. fout2.open(pathMotherboard, ofstream::app);
  219. fout2.close();
  220.  
  221. ofstream fout3;
  222. fout3.open(pathGaphics_card, ofstream::app);
  223. fout3.close();
  224.  
  225. ofstream fout4;
  226. fout4.open(pathRAM, ofstream::app);
  227. fout4.close();
  228.  
  229. ofstream fout5;
  230. fout5.open(pathPower_Supply, ofstream::app);
  231. fout5.close();
  232.  
  233. ofstream fout6;
  234. fout6.open(pathCorps, ofstream::app);
  235. fout6.close();
  236.  
  237. ofstream fout7;
  238. fout7.open(pathCooler, ofstream::app);
  239. fout7.close();
  240.  
  241. ofstream fout8;
  242. fout8.open(pathSSD, ofstream::app);
  243. fout8.close();
  244.  
  245. ofstream fout9;
  246. fout9.open(pathHDD, ofstream::app);
  247. fout9.close();
  248.  
  249. }
  250.  
  251.  
  252.  
  253. void add(vector <string>& box) {
  254. system("cls");
  255. cout << "Введите новый тип детали (с заглавной буквы)" << endl;
  256.  
  257. string a;
  258. getline(cin, a);
  259. getline(cin, a);
  260. box.push_back(a);
  261. }
  262.  
  263. bool startsWith(string s, string pattern) {
  264. for (int i = 0; i < pattern.size(); i++) {
  265. if (s[i] != pattern[i]) {
  266. return false;
  267. }
  268. }
  269. return true;
  270. }
  271.  
  272.  
  273.  
  274.  
  275.  
  276. void sortirovka(int n, int m2, vector <string>& box, string pathCPU, string pathMotherboard, string pathGaphics_card, string pathRAM,
  277. string pathPower_Supply, string pathCorps, string pathCooler, string pathSSD, string pathHDD, CPU a,
  278. Motherboard b, Gaphics_card c, RAM d, Power_Supply e, Corps f, Cooler g, SSD h, HDD i) {
  279. int l;
  280. int k = 0;
  281.  
  282. cout << "Сортировка по" << endl << "1. Алфавиту" << endl << "2. Производителю" << endl << "3. Назад" << endl;
  283. string m;
  284. cin >> l;
  285.  
  286. switch (l)
  287. {
  288. case 1:
  289. system("cls");
  290. sort(box.begin(), box.end());
  291. cout << "Нас складе:" << box.size() - 1 << endl << endl;
  292. for (int i = 0; i < box.size(); i++)
  293. if (box[i] != "") {
  294. cout << " " << i + 1 << ". " << box[i] << endl;
  295. }
  296. break;
  297. case 2:
  298. system("cls");
  299. cout << "Выберите название производителя (с заглавной буквы)" << endl;
  300. cin >> m;
  301.  
  302. system("cls");
  303.  
  304.  
  305. for (int i = 1; i < box.size(); i++) {
  306. if (startsWith(box[i], m)) {
  307. k++;
  308. cout << " " << k << ". " << box[i] << endl;
  309.  
  310. }
  311. }
  312. if (k == 0)
  313. cout << "Детали по запросу не найдены" << endl;
  314. case 3:
  315. menu2(n, m2, box, pathCPU, pathMotherboard, pathGaphics_card, pathRAM,
  316. pathPower_Supply, pathCorps, pathCooler, pathSSD, pathHDD, a,
  317. b, c, d, e, f, g, h, i);
  318. break;
  319. }
  320. }
  321.  
  322. void del(vector <string>& box) {
  323. int i;
  324.  
  325. cout << endl << "Введите номер строки которую вы хотите удалить" << endl;
  326. cin >> i;
  327. box[i].erase();
  328. }
  329.  
  330. void get(vector <string>& box) {
  331. int k = 0;
  332. cout << "На складе: " << box.size() - 1 << endl << endl;
  333. for (int i = 0; i < box.size(); i++)
  334. if (box[i] != "") {
  335. k++;
  336. cout << " " << i << ". " << box[i] << endl;
  337. }
  338. }
  339.  
  340.  
  341.  
  342.  
  343. void Sohrn(int n, int m2, vector <string>& box, string pathCPU, string pathMotherboard, string pathGaphics_card, string pathRAM,
  344. string pathPower_Supply, string pathCorps, string pathCooler, string pathSSD, string pathHDD) {
  345.  
  346. ofstream fout;
  347.  
  348. if (n == 1) {
  349. fout.open(pathCPU);
  350. if (m2 == 1) {
  351. fout << endl;
  352. };
  353. for (int i = 0; i < box.size(); i++) {
  354. if (box[i] != "") {
  355. if (i != box.size() - 1) {
  356. fout << box[i] << endl;
  357. }
  358. else
  359. fout << box[i];
  360. }
  361. }
  362. fout.close();
  363. }
  364.  
  365. if (n == 2) {
  366. fout.open(pathMotherboard);
  367. if (m2 == 1) {
  368. fout << endl;
  369. }
  370. for (int i = 0; i < box.size(); i++) {
  371. if (box[i] != "") {
  372. if (i != box.size() - 1) {
  373. fout << box[i] << endl;
  374. }
  375. else
  376. fout << box[i];
  377. }
  378. }
  379. fout.close();
  380. }
  381.  
  382. if (n == 3) {
  383. fout.open(pathGaphics_card);
  384. if (m2 == 1) {
  385. fout << endl;
  386. }
  387. for (int i = 0; i < box.size(); i++) {
  388. if (box[i] != "") {
  389. if (i != box.size() - 1) {
  390. fout << box[i] << endl;
  391. }
  392. else
  393. fout << box[i];
  394. }
  395. }
  396. fout.close();
  397. }
  398.  
  399. if (n == 4) {
  400. fout.open(pathRAM);
  401. if (m2 == 1) {
  402. fout << endl;
  403. }
  404. for (int i = 0; i < box.size(); i++) {
  405. if (box[i] != "") {
  406. if (i != box.size() - 1) {
  407. fout << box[i] << endl;
  408. }
  409. else
  410. fout << box[i];
  411. }
  412. }
  413. fout.close();
  414. }
  415.  
  416. if (n == 5) {
  417. fout.open(pathPower_Supply);
  418. if (m2 == 1) {
  419. fout << endl;
  420. }
  421. for (int i = 0; i < box.size(); i++) {
  422. if (box[i] != "") {
  423. if (i != box.size() - 1) {
  424. fout << box[i] << endl;
  425. }
  426. else
  427. fout << box[i];
  428. }
  429. }
  430. fout.close();
  431. }
  432.  
  433. if (n == 6) {
  434. fout.open(pathCorps);
  435. if (m2 == 1) {
  436. fout << endl;
  437. }
  438. for (int i = 0; i < box.size(); i++) {
  439. if (box[i] != "") {
  440. if (i != box.size() - 1) {
  441. fout << box[i] << endl;
  442. }
  443. else
  444. fout << box[i];
  445. }
  446. }
  447. fout.close();
  448. }
  449.  
  450. if (n == 7) {
  451. fout.open(pathCooler);
  452. if (m2 == 1) {
  453. fout << endl;
  454. }
  455. for (int i = 0; i < box.size(); i++) {
  456. if (box[i] != "") {
  457. if (i != box.size() - 1) {
  458. fout << box[i] << endl;
  459. }
  460. else
  461. fout << box[i];
  462. }
  463. }
  464. fout.close();
  465. }
  466.  
  467. if (n == 8) {
  468. fout.open(pathSSD);
  469. if (m2 == 1) {
  470. fout << endl;
  471. }
  472. for (int i = 0; i < box.size(); i++) {
  473. if (box[i] != "") {
  474. if (i != box.size() - 1) {
  475. fout << box[i] << endl;
  476. }
  477. else
  478. fout << box[i];
  479. }
  480. }
  481. fout.close();
  482. }
  483.  
  484. if (n == 9) {
  485. fout.open(pathHDD);
  486. if (m2 == 1) {
  487. fout << endl;
  488. }
  489. for (int i = 0; i < box.size(); i++) {
  490. if (box[i] != "") {
  491. if (i != box.size() - 1) {
  492. fout << box[i] << endl;
  493. }
  494. else
  495. fout << box[i];
  496. }
  497. }
  498. fout.close();
  499. }
  500.  
  501. }
  502.  
  503. void menu1(int m2, vector <string>& box, string pathCPU, string pathMotherboard, string pathGaphics_card, string pathRAM,
  504. string pathPower_Supply, string pathCorps, string pathCooler, string pathSSD, string pathHDD, CPU a,
  505. Motherboard b, Gaphics_card c, RAM d, Power_Supply e, Corps f, Cooler g, SSD h, HDD i) {
  506.  
  507. int n = 0;
  508.  
  509. while (true) {
  510. cout << "Выбери деталь" << endl << endl;
  511. cout << " 1. Центральный процессор" << endl;
  512. cout << " 2. Материнская плата" << endl;
  513. cout << " 3. Видеокарта" << endl;
  514. cout << " 4. Оперативная память" << endl;
  515. cout << " 5. Блок питания" << endl;
  516. cout << " 6. Корпус" << endl;
  517. cout << " 7. Охлаждение компьютера" << endl;
  518. cout << " 8. SSD" << endl;
  519. cout << " 9. HDD" << endl;
  520. cout << " 0. Выход" << endl << endl;
  521. cout << "Номер детали: ";
  522.  
  523. cin >> n;
  524.  
  525. switch (n)
  526. {
  527.  
  528. case 1:
  529. box.clear();
  530. a.read(box, pathCPU);
  531. system("cls");
  532. get(box);
  533. break;
  534. case 2:
  535. box.clear();
  536. b.read(box, pathMotherboard);
  537. system("cls");
  538. get(box);
  539. break;
  540.  
  541. case 3:
  542. box.clear();
  543. c.read(box, pathGaphics_card);
  544. system("cls");
  545. get(box);
  546. break;
  547. case 4:
  548. box.clear();
  549.  
  550. d.read(box, pathRAM);
  551. system("cls");
  552. get(box);
  553. break;
  554. case 5:
  555. box.clear();
  556. e.read(box, pathPower_Supply);
  557. system("cls");
  558. get(box);
  559. break;
  560. case 6:
  561. box.clear();
  562. f.read(box, pathCorps);
  563. system("cls");
  564. get(box);
  565. break;
  566. case 7:
  567. box.clear();
  568. g.read(box, pathCooler);
  569. system("cls");
  570. get(box);
  571. break;
  572. case 8:
  573. box.clear();
  574. h.read(box, pathSSD);
  575. system("cls");
  576. get(box);
  577. break;
  578. case 9:
  579. box.clear();
  580. i.read(box, pathHDD);
  581. system("cls");
  582. get(box);
  583. break;
  584. case 0:
  585.  
  586. exit(0);
  587. default:
  588. break;
  589. }
  590. menu2(n, m2, box, pathCPU, pathMotherboard, pathGaphics_card, pathRAM,
  591. pathPower_Supply, pathCorps, pathCooler, pathSSD, pathHDD, a,
  592. b, c, d, e, f, g, h, i);
  593.  
  594. }
  595. }
  596.  
  597. void menu2(int n, int& m2, vector <string>& box, string pathCPU, string pathMotherboard, string pathGaphics_card, string pathRAM,
  598. string pathPower_Supply, string pathCorps, string pathCooler, string pathSSD, string pathHDD, CPU a,
  599. Motherboard b, Gaphics_card c, RAM d, Power_Supply e, Corps f, Cooler g, SSD h, HDD i) {
  600. int m=1;
  601.  
  602. while (true) {
  603. cout << endl << "//----------------------" << endl << "Выберите вариант действия: " << endl << endl << " 1. Добавить" << endl << " 2. Список деталей нa складе" << endl << " 3. Сортировка" << endl << " 4. Удалить деталь со склада" << endl << " 5. Назад" << endl << endl << "Действие: ";
  604.  
  605. cin >> m;
  606. if (m == 1)
  607. m2 = m;
  608.  
  609. switch (m)
  610. {
  611. case 1:
  612. add(box);
  613. break;
  614. case 2:
  615. system("cls");
  616. get(box);
  617. break;
  618. case 3:
  619. system("cls");
  620. sortirovka(n, m2, box, pathCPU, pathMotherboard, pathGaphics_card, pathRAM,
  621. pathPower_Supply, pathCorps, pathCooler, pathSSD, pathHDD, a,
  622. b, c, d, e, f, g, h, i);
  623. break;
  624.  
  625. case 4:
  626. system("cls");
  627. get(box);
  628. del(box);
  629. break;
  630.  
  631. case 5:
  632. Sohrn(n, m2, box, pathCPU, pathMotherboard, pathGaphics_card, pathRAM,
  633. pathPower_Supply, pathCorps, pathCooler, pathSSD, pathHDD);
  634. system("cls");
  635. return;
  636. default:
  637. system("cls");
  638. get(box);
  639. break;
  640. }
  641. }
  642.  
  643. }
  644.  
  645. int main() {
  646. //руссификация
  647. setlocale(LC_ALL, "ru");
  648. SetConsoleCP(1251);
  649. SetConsoleOutputCP(1251);
  650.  
  651. string pathCPU = "CPU.txt";
  652. string pathMotherboard = "Motherboard.txt";
  653. string pathGaphics_card = "Gaphics_card.txt";
  654. string pathRAM = "RAM.txt";
  655. string pathPower_Supply = "Power_Supply.txt";
  656. string pathCorps = "Corps.txt";
  657. string pathCooler = "Cooler.txt";
  658. string pathSSD = "SSD.txt";
  659. string pathHDD = "HDD.txt";
  660.  
  661. vector <string> box;
  662.  
  663. CPU a;
  664. Motherboard b;
  665. Gaphics_card c;
  666. RAM d;
  667. Power_Supply e;
  668. Corps f;
  669. Cooler g;
  670. SSD h;
  671. HDD i;
  672.  
  673.  
  674.  
  675. create(box, pathCPU, pathMotherboard, pathGaphics_card, pathRAM,
  676. pathPower_Supply, pathCorps, pathCooler, pathSSD, pathHDD);
  677. int m2 = 0;
  678. menu1(m2, box, pathCPU, pathMotherboard, pathGaphics_card, pathRAM,
  679. pathPower_Supply, pathCorps, pathCooler, pathSSD, pathHDD, a,
  680. b, c, d, e, f, g, h, i);
  681.  
  682.  
  683. return 0;
  684. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement