Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- class Details {
- };
- class CPU : public Details {
- public:
- void read(vector <string>& box, string pathCPU) {
- ifstream fin;
- fin.open(pathCPU);
- string str;
- while (!fin.eof())
- {
- str = "";
- getline(fin, str);
- box.push_back(str);
- }
- fin.close();
- }
- };
- class Motherboard : public Details {
- public:
- void read(vector <string>& box, string pathMotherboard) {
- ifstream fin;
- fin.open(pathMotherboard);
- string str;
- while (!fin.eof())
- {
- str = "";
- getline(fin, str);
- box.push_back(str);
- }
- fin.close();
- }
- };
- class Gaphics_card : public Details {
- public:
- void read(vector <string>& box, string pathGaphics_card) {
- ifstream fin;
- fin.open(pathGaphics_card);
- string str;
- while (!fin.eof())
- {
- str = "";
- getline(fin, str);
- box.push_back(str);
- }
- fin.close();
- }
- };
- class RAM : public Details {
- public:
- void read(vector <string>& box, string pathRAM) {
- ifstream fin;
- fin.open(pathRAM);
- string str;
- while (!fin.eof())
- {
- str = "";
- getline(fin, str);
- box.push_back(str);
- }
- fin.close();
- }
- };
- class Power_Supply : public Details {
- public:
- void read(vector <string>& box, string pathPower_Supply) {
- ifstream fin;
- fin.open(pathPower_Supply);
- string str;
- while (!fin.eof())
- {
- str = "";
- getline(fin, str);
- box.push_back(str);
- }
- fin.close();
- }
- };
- class Corps : public Details {
- public:
- void read(vector <string>& box, string pathCorps) {
- ifstream fin;
- string str;
- while (!fin.eof())
- {
- str = "";
- getline(fin, str);
- box.push_back(str);
- }
- fin.close();
- }
- };
- class Cooler : public Details {
- public:
- void read(vector <string>& box, string pathCooler) {
- ifstream fin;
- fin.open(pathCooler);
- string str;
- while (!fin.eof())
- {
- str = "";
- getline(fin, str);
- /* if str != " " */
- box.push_back(str);
- }
- fin.close();
- }
- };
- class SSD : public Details {
- public:
- void read(vector <string>& box, string pathSSD) {
- ifstream fin;
- fin.open(pathSSD);
- string str;
- while (!fin.eof())
- {
- str = "";
- getline(fin, str);
- box.push_back(str);
- }
- fin.close();
- }
- };
- class HDD : public Details {
- public:
- void read(vector <string>& box, string pathHDD) {
- ifstream fin;
- fin.open(pathHDD);
- string str;
- while (!fin.eof())
- {
- str = "";
- getline(fin, str);
- box.push_back(str);
- }
- fin.close();
- }
- };
- void menu2(int n, int& m2, vector <string>& box, string pathCPU, string pathMotherboard, string pathGaphics_card, string pathRAM,
- string pathPower_Supply, string pathCorps, string pathCooler, string pathSSD, string pathHDD, CPU a,
- Motherboard b, Gaphics_card c, RAM d, Power_Supply e, Corps f, Cooler g, SSD h, HDD i);
- void menu1(int m2, vector <string>& box, string pathCPU, string pathMotherboard, string pathGaphics_card, string pathRAM,
- string pathPower_Supply, string pathCorps, string pathCooler, string pathSSD, string pathHDD, CPU a,
- Motherboard b, Gaphics_card c, RAM d, Power_Supply e, Corps f, Cooler g, SSD h, HDD i);
- void Sohrn(int n, int m2, vector <string>& box, string pathCPU, string pathMotherboard, string pathGaphics_card, string pathRAM,
- string pathPower_Supply, string pathCorps, string pathCooler, string pathSSD, string pathHDD);
- void create(vector <string>& box, string pathCPU, string pathMotherboard, string pathGaphics_card, string pathRAM,
- string pathPower_Supply, string pathCorps, string pathCooler, string pathSSD, string pathHDD)
- {
- ofstream fout1;
- fout1.open(pathCPU, ofstream::app);
- fout1.close();
- ofstream fout2;
- fout2.open(pathMotherboard, ofstream::app);
- fout2.close();
- ofstream fout3;
- fout3.open(pathGaphics_card, ofstream::app);
- fout3.close();
- ofstream fout4;
- fout4.open(pathRAM, ofstream::app);
- fout4.close();
- ofstream fout5;
- fout5.open(pathPower_Supply, ofstream::app);
- fout5.close();
- ofstream fout6;
- fout6.open(pathCorps, ofstream::app);
- fout6.close();
- ofstream fout7;
- fout7.open(pathCooler, ofstream::app);
- fout7.close();
- ofstream fout8;
- fout8.open(pathSSD, ofstream::app);
- fout8.close();
- ofstream fout9;
- fout9.open(pathHDD, ofstream::app);
- fout9.close();
- }
- void add(vector <string>& box) {
- system("cls");
- cout << "Введите новый тип детали (с заглавной буквы)" << endl;
- string a;
- getline(cin, a);
- getline(cin, a);
- box.push_back(a);
- }
- bool startsWith(string s, string pattern) {
- for (int i = 0; i < pattern.size(); i++) {
- if (s[i] != pattern[i]) {
- return false;
- }
- }
- return true;
- }
- void sortirovka(int n, int m2, vector <string>& box, string pathCPU, string pathMotherboard, string pathGaphics_card, string pathRAM,
- string pathPower_Supply, string pathCorps, string pathCooler, string pathSSD, string pathHDD, CPU a,
- Motherboard b, Gaphics_card c, RAM d, Power_Supply e, Corps f, Cooler g, SSD h, HDD i) {
- int l;
- int k = 0;
- cout << "Сортировка по" << endl << "1. Алфавиту" << endl << "2. Производителю" << endl << "3. Назад" << endl;
- string m;
- cin >> l;
- switch (l)
- {
- case 1:
- system("cls");
- sort(box.begin(), box.end());
- cout << "Нас складе:" << box.size() - 1 << endl << endl;
- for (int i = 0; i < box.size(); i++)
- if (box[i] != "") {
- cout << " " << i + 1 << ". " << box[i] << endl;
- }
- break;
- case 2:
- system("cls");
- cout << "Выберите название производителя (с заглавной буквы)" << endl;
- cin >> m;
- system("cls");
- for (int i = 1; i < box.size(); i++) {
- if (startsWith(box[i], m)) {
- k++;
- cout << " " << k << ". " << box[i] << endl;
- }
- }
- if (k == 0)
- cout << "Детали по запросу не найдены" << endl;
- case 3:
- menu2(n, m2, box, pathCPU, pathMotherboard, pathGaphics_card, pathRAM,
- pathPower_Supply, pathCorps, pathCooler, pathSSD, pathHDD, a,
- b, c, d, e, f, g, h, i);
- break;
- }
- }
- void del(vector <string>& box) {
- int i;
- cout << endl << "Введите номер строки которую вы хотите удалить" << endl;
- cin >> i;
- box[i].erase();
- }
- void get(vector <string>& box) {
- int k = 0;
- cout << "На складе: " << box.size() - 1 << endl << endl;
- for (int i = 0; i < box.size(); i++)
- if (box[i] != "") {
- k++;
- cout << " " << i << ". " << box[i] << endl;
- }
- }
- void Sohrn(int n, int m2, vector <string>& box, string pathCPU, string pathMotherboard, string pathGaphics_card, string pathRAM,
- string pathPower_Supply, string pathCorps, string pathCooler, string pathSSD, string pathHDD) {
- ofstream fout;
- if (n == 1) {
- fout.open(pathCPU);
- if (m2 == 1) {
- fout << endl;
- };
- for (int i = 0; i < box.size(); i++) {
- if (box[i] != "") {
- if (i != box.size() - 1) {
- fout << box[i] << endl;
- }
- else
- fout << box[i];
- }
- }
- fout.close();
- }
- if (n == 2) {
- fout.open(pathMotherboard);
- if (m2 == 1) {
- fout << endl;
- }
- for (int i = 0; i < box.size(); i++) {
- if (box[i] != "") {
- if (i != box.size() - 1) {
- fout << box[i] << endl;
- }
- else
- fout << box[i];
- }
- }
- fout.close();
- }
- if (n == 3) {
- fout.open(pathGaphics_card);
- if (m2 == 1) {
- fout << endl;
- }
- for (int i = 0; i < box.size(); i++) {
- if (box[i] != "") {
- if (i != box.size() - 1) {
- fout << box[i] << endl;
- }
- else
- fout << box[i];
- }
- }
- fout.close();
- }
- if (n == 4) {
- fout.open(pathRAM);
- if (m2 == 1) {
- fout << endl;
- }
- for (int i = 0; i < box.size(); i++) {
- if (box[i] != "") {
- if (i != box.size() - 1) {
- fout << box[i] << endl;
- }
- else
- fout << box[i];
- }
- }
- fout.close();
- }
- if (n == 5) {
- fout.open(pathPower_Supply);
- if (m2 == 1) {
- fout << endl;
- }
- for (int i = 0; i < box.size(); i++) {
- if (box[i] != "") {
- if (i != box.size() - 1) {
- fout << box[i] << endl;
- }
- else
- fout << box[i];
- }
- }
- fout.close();
- }
- if (n == 6) {
- fout.open(pathCorps);
- if (m2 == 1) {
- fout << endl;
- }
- for (int i = 0; i < box.size(); i++) {
- if (box[i] != "") {
- if (i != box.size() - 1) {
- fout << box[i] << endl;
- }
- else
- fout << box[i];
- }
- }
- fout.close();
- }
- if (n == 7) {
- fout.open(pathCooler);
- if (m2 == 1) {
- fout << endl;
- }
- for (int i = 0; i < box.size(); i++) {
- if (box[i] != "") {
- if (i != box.size() - 1) {
- fout << box[i] << endl;
- }
- else
- fout << box[i];
- }
- }
- fout.close();
- }
- if (n == 8) {
- fout.open(pathSSD);
- if (m2 == 1) {
- fout << endl;
- }
- for (int i = 0; i < box.size(); i++) {
- if (box[i] != "") {
- if (i != box.size() - 1) {
- fout << box[i] << endl;
- }
- else
- fout << box[i];
- }
- }
- fout.close();
- }
- if (n == 9) {
- fout.open(pathHDD);
- if (m2 == 1) {
- fout << endl;
- }
- for (int i = 0; i < box.size(); i++) {
- if (box[i] != "") {
- if (i != box.size() - 1) {
- fout << box[i] << endl;
- }
- else
- fout << box[i];
- }
- }
- fout.close();
- }
- }
- void menu1(int m2, vector <string>& box, string pathCPU, string pathMotherboard, string pathGaphics_card, string pathRAM,
- string pathPower_Supply, string pathCorps, string pathCooler, string pathSSD, string pathHDD, CPU a,
- Motherboard b, Gaphics_card c, RAM d, Power_Supply e, Corps f, Cooler g, SSD h, HDD i) {
- int n = 0;
- while (true) {
- cout << "Выбери деталь" << endl << endl;
- cout << " 1. Центральный процессор" << endl;
- cout << " 2. Материнская плата" << endl;
- cout << " 3. Видеокарта" << endl;
- cout << " 4. Оперативная память" << endl;
- cout << " 5. Блок питания" << endl;
- cout << " 6. Корпус" << endl;
- cout << " 7. Охлаждение компьютера" << endl;
- cout << " 8. SSD" << endl;
- cout << " 9. HDD" << endl;
- cout << " 0. Выход" << endl << endl;
- cout << "Номер детали: ";
- cin >> n;
- switch (n)
- {
- case 1:
- box.clear();
- a.read(box, pathCPU);
- system("cls");
- get(box);
- break;
- case 2:
- box.clear();
- b.read(box, pathMotherboard);
- system("cls");
- get(box);
- break;
- case 3:
- box.clear();
- c.read(box, pathGaphics_card);
- system("cls");
- get(box);
- break;
- case 4:
- box.clear();
- d.read(box, pathRAM);
- system("cls");
- get(box);
- break;
- case 5:
- box.clear();
- e.read(box, pathPower_Supply);
- system("cls");
- get(box);
- break;
- case 6:
- box.clear();
- f.read(box, pathCorps);
- system("cls");
- get(box);
- break;
- case 7:
- box.clear();
- g.read(box, pathCooler);
- system("cls");
- get(box);
- break;
- case 8:
- box.clear();
- h.read(box, pathSSD);
- system("cls");
- get(box);
- break;
- case 9:
- box.clear();
- i.read(box, pathHDD);
- system("cls");
- get(box);
- break;
- case 0:
- exit(0);
- default:
- break;
- }
- menu2(n, m2, box, pathCPU, pathMotherboard, pathGaphics_card, pathRAM,
- pathPower_Supply, pathCorps, pathCooler, pathSSD, pathHDD, a,
- b, c, d, e, f, g, h, i);
- }
- }
- void menu2(int n, int& m2, vector <string>& box, string pathCPU, string pathMotherboard, string pathGaphics_card, string pathRAM,
- string pathPower_Supply, string pathCorps, string pathCooler, string pathSSD, string pathHDD, CPU a,
- Motherboard b, Gaphics_card c, RAM d, Power_Supply e, Corps f, Cooler g, SSD h, HDD i) {
- int m=1;
- while (true) {
- cout << endl << "//----------------------" << endl << "Выберите вариант действия: " << endl << endl << " 1. Добавить" << endl << " 2. Список деталей нa складе" << endl << " 3. Сортировка" << endl << " 4. Удалить деталь со склада" << endl << " 5. Назад" << endl << endl << "Действие: ";
- cin >> m;
- if (m == 1)
- m2 = m;
- switch (m)
- {
- case 1:
- add(box);
- break;
- case 2:
- system("cls");
- get(box);
- break;
- case 3:
- system("cls");
- sortirovka(n, m2, box, pathCPU, pathMotherboard, pathGaphics_card, pathRAM,
- pathPower_Supply, pathCorps, pathCooler, pathSSD, pathHDD, a,
- b, c, d, e, f, g, h, i);
- break;
- case 4:
- system("cls");
- get(box);
- del(box);
- break;
- case 5:
- Sohrn(n, m2, box, pathCPU, pathMotherboard, pathGaphics_card, pathRAM,
- pathPower_Supply, pathCorps, pathCooler, pathSSD, pathHDD);
- system("cls");
- return;
- default:
- system("cls");
- get(box);
- break;
- }
- }
- }
- int main() {
- //руссификация
- setlocale(LC_ALL, "ru");
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- string pathCPU = "CPU.txt";
- string pathMotherboard = "Motherboard.txt";
- string pathGaphics_card = "Gaphics_card.txt";
- string pathRAM = "RAM.txt";
- string pathPower_Supply = "Power_Supply.txt";
- string pathCorps = "Corps.txt";
- string pathCooler = "Cooler.txt";
- string pathSSD = "SSD.txt";
- string pathHDD = "HDD.txt";
- vector <string> box;
- CPU a;
- Motherboard b;
- Gaphics_card c;
- RAM d;
- Power_Supply e;
- Corps f;
- Cooler g;
- SSD h;
- HDD i;
- create(box, pathCPU, pathMotherboard, pathGaphics_card, pathRAM,
- pathPower_Supply, pathCorps, pathCooler, pathSSD, pathHDD);
- int m2 = 0;
- menu1(m2, box, pathCPU, pathMotherboard, pathGaphics_card, pathRAM,
- pathPower_Supply, pathCorps, pathCooler, pathSSD, pathHDD, a,
- b, c, d, e, f, g, h, i);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement