Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <algorithm>
- #include <vector>
- #include <filesystem>
- using namespace std;
- namespace fs = std::experimental::filesystem;
- struct Proekts
- {
- string nameproject;
- int costproject;
- };
- struct Kyrsi
- {
- int students;
- int costofeducation;
- int nomer;
- };
- class unit
- {
- protected:
- string name; //подразделение название
- string fio; //подразделение название руководителя (ФИО),
- int graduate, employee; // число аспирантов, число сотрудников
- public:
- unit() {}
- string getname() { return name; }
- string getfio() { return fio; }
- int getgraduate() { return graduate; }
- int getemployee() { return employee; }
- virtual void print() = 0;
- virtual int profit() = 0;
- virtual void zapic(string a, ofstream& n) = 0;
- virtual void otkrit(string a, ifstream& n) = 0;
- };
- class educational : public unit
- {
- private: //проекты(название, стоимость)
- int kolproject;
- vector <Proekts> proekti;
- public:
- educational()
- {
- cout << endl << "Vvedite nazvanei podrazdelenia ";
- cin >> name;
- cout << endl << "Vvedite FIO rykovoditelia ";
- cin >> fio;
- cout << endl << "Chislo aspirantov podrazdelenia ";
- cin >> graduate;
- cout << endl << "Chislo sotrydnikov podrazdelenia ";
- cin >> employee;
- cout << endl << "Kolichestvo proektov ";
- cin >> kolproject;
- proekti.reserve(kolproject);
- for (int i = 0; i < kolproject; i++)
- {
- Proekts tosha;
- cout << endl << "Nazvanie proekta ";
- cin >> tosha.nameproject;
- cout << endl << "Stoimost proekta ";
- cin >> tosha.costproject;
- cin.get();
- proekti.push_back(tosha);
- }
- }
- educational(int f)
- {}
- void print()
- {
- cout << endl << "Nazvanei podrazdelenia ";
- cout << name;
- cout << endl << "FIO rykovoditelia ";
- cout << fio;
- cout << endl << "Chislo aspirantov podrazdelenia ";
- cout << graduate;
- cout << endl << "Chislo sotrydnikov podrazdelenia ";
- cout << employee;
- cout << endl << "Kolichestvo proektov ";
- cout << kolproject;
- for (int i = 0; i < kolproject; i++)
- {
- cout << endl << "Nazvanie proekta ";
- cout << proekti[i].nameproject;
- cout << endl << "Stoimost proekta ";
- cout << proekti[i].costproject;
- }
- cout << endl;
- }
- int profit()
- {
- int otvet = 0;
- for (int i = 0; i < kolproject; i++)
- {
- otvet = otvet + proekti[i].costproject;
- }
- return otvet;
- }
- void zapic(string a, ofstream& pot)
- {
- pot << 1;
- pot << "\n";
- pot << name;
- pot << "\n";
- pot << fio;
- pot << "\n";
- pot << graduate;
- pot << "\n";
- pot << employee;
- pot << "\n";
- pot << kolproject;
- pot << "\n";
- for (int i = 0; i < kolproject; i++)
- {
- pot << proekti[i].nameproject;
- pot << "\n";
- pot << proekti[i].costproject;
- pot << "\n";
- }
- }
- void otkrit(string a, ifstream& pot)
- {
- cout << endl << "Nazvanei podrazdelenia ";
- pot >> name;
- cout << name;
- cout << endl << "FIO rykovoditelia ";
- pot >> fio;
- cout << fio;
- cout << endl << "Chislo aspirantov podrazdelenia ";
- pot >> graduate;
- cout << graduate;
- cout << endl << "Chislo sotrydnikov podrazdelenia ";
- pot >> employee;
- cout << employee;
- cout << endl << "Kolichestvo proektov ";
- pot >> kolproject;
- cout << kolproject;
- proekti.reserve(kolproject);
- for (int i = 0; i < kolproject; i++)
- {
- Proekts tosha;
- cout << endl << "Nazvanie proekta ";
- pot >> tosha.nameproject;
- cout << tosha.nameproject;
- cout << endl << "Stoimost proekta ";
- pot >> tosha.costproject;
- cout << tosha.costproject;
- proekti.push_back(tosha);
- }
- cout << endl;
- }
- };
- class science : public unit
- {
- private:
- vector <Kyrsi> kyrsis[6]; //число студентов и стоимость обучения одного студента , курс
- int sc = 0;
- public:
- science() :
- unit()
- {
- cout << endl << "Vvedite nazvanei podrazdelenia ";
- cin >> name;
- cout << endl << "Vvedite FIO rykovoditelia ";
- cin >> fio;
- cout << endl << "Chislo aspirantov podrazdelenia ";
- cin >> graduate;
- cout << endl << "Chislo sotrydnikov podrazdelenia ";
- cin >> employee;
- string flag;
- do
- {
- Kyrsi tosha;
- cout << endl << "Kakoe kyrs? ";
- cin >> tosha.nomer;
- tosha.students = 1;
- cout << endl << "Stoimost obychenia stydenta ";
- cin >> tosha.costofeducation;
- cin.get();
- kyrsis[tosha.nomer-1].push_back(tosha);
- sc++;
- cout << endl << "Prodolgit? (yes/no)" << endl;
- cin >> flag;
- } while (flag != "no");
- }
- science(int y)
- {}
- void print()
- {
- cout << endl << "Nazvanei podrazdelenia ";
- cout << name;
- cout << endl << "FIO rykovoditelia ";
- cout << fio;
- cout << endl << "Chislo aspirantov podrazdelenia ";
- cout << graduate;
- cout << endl << "Chislo sotrydnikov podrazdelenia ";
- cout << employee;
- for (int i = 0; i < 6; i++)
- {
- for (int j = 0; j < kyrsis[i].size(); j++)
- {
- cout << endl << "Kolichestvo ctydentov " << i + 1 << " kyrsa ";
- cout << kyrsis[i][j].students;
- cout << endl << "Stoimost obychenia stydenta " << i + 1 << " kyrsa ";
- cout << kyrsis[i][j].costofeducation;
- }
- }
- cout << endl;
- }
- int profit()
- {
- int otvet = 0;
- for (int i = 0; i < 6; i++)
- for (int j = 0; j< kyrsis[i].size();j++)
- otvet = otvet + kyrsis[i][j].students * kyrsis[i][j].costofeducation;
- return otvet;
- }
- void zapic(string a, ofstream& pot)
- {
- pot << 2;
- pot << "\n";
- pot << name;
- pot << "\n";
- pot << fio;
- pot << "\n";
- pot << graduate;
- pot << "\n";
- pot << employee;
- pot << '\n';
- pot << sc << '\n';
- for (int i = 0; i < 6; i++)
- {
- if (kyrsis[i].size()!=0)
- for (int j = 0; j < kyrsis[i].size(); j++)
- {
- pot << i + 1 << '\n';
- pot << kyrsis[i][j].costofeducation << '\n';
- }
- }
- }
- void otkrit(string a, ifstream& pot)
- {
- string str;
- cout << endl << "Nazvanei podrazdelenia ";
- pot >> name;
- cout << name;
- cout << endl << "FIO rykovoditelia ";
- pot >> fio;
- cout << fio;
- cout << endl << "Chislo aspirantov podrazdelenia ";
- pot >> graduate;
- cout << graduate;
- cout << endl << "Chislo sotrydnikov podrazdelenia ";
- pot >> employee;
- cout << employee;
- pot >> sc;
- for (int i = 0; i < sc;i++)
- {
- Kyrsi tosha;
- int n;
- pot >> n;
- cout << endl << "Odin stydent ";
- cout << endl << "Nomer kyrsa " << n ;
- //kyrsis[n-1].resize(1);
- pot >> tosha.costofeducation;
- cout << endl << "Stoimost obychenia " << tosha.costofeducation;
- tosha.nomer = n;
- tosha.students = 1;
- kyrsis[n-1].push_back(tosha);
- }
- cout << endl;
- }
- };
- bool p1(unit* a, unit* l)
- {
- return a->getname() > l->getname();
- }
- bool p2(unit* a, unit* l)
- {
- return a->getemployee() > l->getemployee();
- }
- class BD
- {
- public: vector <unit*> baza;
- void zapolnenie()
- {
- string flag; string vibor;
- do
- {
- cout << endl << "Kakoe predpriatie? 1) obrazovatelnoe (o) ; 2) nauchnoe (n) ";
- cin >> vibor;
- if (vibor == "o")
- {
- baza.push_back(new educational);
- }
- if (vibor == "n")
- {
- baza.push_back(new science);
- }
- if (vibor != "n" && vibor != "o") {
- cout << endl << "Nepravilni vvod\n" << endl;
- }
- cout << endl << "Prodolgit? (yes/no)" << endl;
- cin >> flag;
- } while (flag != "no");
- }
- void sortirovka1()
- {
- sort(baza.begin(), baza.end(), p1);
- for (int i = 0; i < baza.size(); i++)
- {
- baza[i]->print();
- }
- }
- void sortirovka2()
- {
- sort(baza.begin(), baza.end(), p2);
- for (int i = 0; i < baza.size(); i++)
- {
- baza[i]->print();
- }
- }
- void profit()
- {
- for (int i = 0; i < baza.size(); i++)
- {
- cout << endl << "Viruchka= ";
- cout << baza[i]->profit();
- }
- cout << endl;
- }
- void nach()
- {
- bool flag2 = 1;
- string a;
- cout << endl << "Vvedite FIO ";
- cin >> a;
- for (int i = 0; i < baza.size(); i++)
- {
- if (baza[i]->getfio() == a)
- {
- baza[i]->print();
- flag2 = 0;
- }
- else
- {
- baza.erase(baza.cbegin() + i);
- i--;
- flag2 = 0;
- }
- }
- if (flag2)
- {
- cout << endl << "Net takogo " << endl;
- }
- }
- void aspir()
- {
- bool flag2 = 1;
- int a;
- cout << endl << "Vvedite kolichestvo aspirantov ";
- cin >> a;
- for (int i = 0; i < baza.size(); i++)
- {
- if ((baza[i]->getemployee() / baza[i]->getgraduate()) < a || (baza[i]->getemployee() / baza[i]->getgraduate()) == a)
- {
- baza[i]->print();
- flag2 = 0;
- }
- if ((baza[i]->getemployee() / baza[i]->getgraduate()) > a )
- {
- baza.erase(baza.cbegin() + i);
- i--;
- flag2 = 0;
- }
- }
- if (flag2)
- {
- cout << endl << "Net takogo " << endl;
- }
- }
- void fail(string h)
- {
- string b = "C:\\Users\\Crazzy\\Desktop\\BDfail\\";
- b = b + h + ".txt";
- ofstream rewrite(b);
- rewrite.write("", 0);
- rewrite.close();
- int vel = baza.size();
- ofstream pot;
- pot.open(b, ofstream::app);
- pot << vel;
- pot << "\n";
- for (int i = 0; i < baza.size(); i++)
- {
- baza[i]->zapic(b, pot);
- }
- pot.close();
- }
- void fail()
- {
- string h;
- string b = "C:\\Users\\Crazzy\\Desktop\\BDfail\\";
- cout << "Vvedite nazvanio faila " << endl;
- cin >> h;
- b = b + h + ".txt";
- ofstream rewrite(b);
- rewrite.write("", 0);
- rewrite.close();
- int vel = baza.size();
- ofstream pot;
- pot.open(b, ofstream::app);
- pot << vel;
- pot << "\n"; //один раз открыть , один закрыть
- for (int i = 0; i < baza.size(); i++)
- {
- baza[i]->zapic(b, pot);
- }
- pot.close();
- }
- void udal()
- {
- bool flag2 = 1;
- string a;
- cout << endl << "Vvedite nazvanio podrazdelenia ";
- cin >> a;
- auto iter = baza.cbegin(); // указатель на первый элемент
- for (int i = 0; i < baza.size(); i++)
- {
- if (baza[i]->getname() == a)
- {
- baza.erase(iter + i);
- flag2 = 0;
- break;
- }
- }
- if (flag2)
- {
- cout << endl << "Net takogo " << endl;
- }
- for (int i = 0; i < baza.size(); i++)
- {
- baza[i]->print();
- }
- }
- void chtenie( string h)
- {
- int g1, g2 = 0;
- string b;
- while (true)
- {
- b = "C:\\Users\\Crazzy\\Desktop\\BDfail\\";
- b = b + h + ".txt";
- ifstream g;
- g.open(b);
- try
- {
- if (!g.is_open())
- {
- throw exception("Error: Takogo BD net\n");
- }
- else { break; }
- }
- catch (const std::exception& ex)
- {
- cout << ex.what() << endl;
- }
- }
- ifstream pot1;
- pot1.open(b);
- pot1 >> g1;
- for (int i = 0; i < g1; i++)
- {
- pot1 >> g2;
- if (g2 == 1)
- {
- baza.push_back(new educational(g2));
- baza[i]->otkrit(b, pot1);
- }
- else
- {
- baza.push_back(new science(g2));
- baza[i]->otkrit(b, pot1);
- }
- }
- pot1.close();
- cout << "____________________________________________________________";
- }
- void dobav(string h)
- {
- string b = "C:\\Users\\Crazzy\\Desktop\\BDfail//";
- b = b + h + ".txt";
- ofstream pot;
- pot.open(b, ofstream::app);
- for (int i = 0; i < baza.size(); i++)
- {
- baza[i]->zapic(b, pot);
- }
- pot.close();
- }
- };
- int main()
- {
- string flag2;
- do
- { while (true)
- {
- cout << "__________________________________________________________" << endl;
- cout << "Dobro pogalovat" << endl;
- cout << "Spisok komand: " << endl;
- cout << "1) Sozdat BD " << endl;
- cout << "2) Otkrit BD " << endl;
- cout << "3) Vivod spiska BD " << endl;
- cout << "4) Viborka " << endl;
- cout << "5) Izmenit BD " << endl;
- cout << "6) Dopolnitelnoe " << endl << endl;
- string vib, n, exo;
- do
- {
- n = cin.get();
- vib = vib + n;
- } while (cin.peek() != '<' && cin.peek() != '\n');
- n = cin.get();
- if ( n == "<")
- {
- int raz = vib.size();
- vib.erase(vib.begin() + raz - 1);
- do
- {
- n = cin.get();
- exo = exo + n;
- } while (cin.peek() != '>');
- n = cin.get();
- n = cin.get();
- }
- try
- {
- if (vib != "sozdat bd" && vib != "otkrit bd" && vib != "vivod spiska bd" && vib != "viborka" && vib != "izmenit bd" && vib != "dopolnitelnoe" && vib != "sozdat bd" && vib != "otkrit bd" && vib != "vivod spiska bd" && vib != "viborka" && vib != "izmenit bd" && vib != "dopolnitelnoe")
- {
- throw exception("Error: Nepravilnii vvod\n");
- }
- }
- catch (const std::exception& ex)
- {
- cout << ex.what() << endl;
- /*cin.clear();
- while (cin.get() != '\n');
- continue; */
- }
- if (vib == "vivod spiska bd")
- {
- for (auto& hen : fs::directory_iterator("C:\\Users\\Crazzy\\Desktop\\BDfail"))
- {
- cout << hen.path().filename() << endl;
- }
- }
- if (vib == "sozdat bd")
- {
- BD ann;
- ann.zapolnenie();
- string yes_no;
- cin.get();
- while (true)
- {
- cout << "Sohranit cozdannoe BD? yes/no ";
- try
- {
- getline(cin, yes_no);
- if (yes_no != "yes" && yes_no != "no")
- {
- throw exception("Error: Nepravilnii tip\n");
- }
- else { break; }
- }
- catch (const std::exception& ex)
- {
- cout << ex.what() << endl;
- /*cin.clear();
- while (cin.get() != '\n');
- continue;*/
- }
- }
- if (yes_no == "yes")
- {
- ann.fail(exo);
- }
- }
- if (vib == "izmenit bd")
- {
- string yes_no;
- while (true)
- {
- cout << endl << "Chto gelaete sdelat? 1) otsortirovat zapisi, (sort) 2) ydalit zapisi, (del) 3) dobavit " << endl;
- try
- {
- getline(cin, yes_no);
- if (yes_no != "sort" && yes_no != "del" && yes_no != "dobavit")
- {
- throw exception("Error: Nepravilnii vvod\n");
- }
- else { break; }
- }
- catch (const std::exception& ex)
- {
- cout << ex.what() << endl;
- /*cin.clear();
- while (cin.get() != '\n');
- continue;*/
- }
- }
- if (yes_no == "sort")
- {
- while (true)
- {
- cout << "1) po nazvaniy, 2) po chisly sotrudnikov ";
- try
- {
- getline(cin, yes_no);
- if (yes_no != "po nazvaniy" && yes_no != "po chisly sotrudnikov")
- {
- throw exception("Error: Nepravilnii vvod\n");
- }
- else { break; }
- }
- catch (const std::exception& ex)
- {
- cout << ex.what() << endl;
- /*cin.clear();
- while (cin.get() != '\n');
- continue;*/
- }
- }
- if (yes_no == "po nazvaniy")
- {
- BD ann;
- ann.chtenie(exo);
- ann.sortirovka1();
- string uy;
- while (true)
- {
- cout << endl << "Hotite sohranit? yes/no ";
- try
- {
- getline(cin, uy);
- if (uy != "yes" && uy != "no")
- {
- throw exception("Error: Nepravilnii vvod\n");
- }
- else { break; }
- }
- catch (const std::exception& ex)
- {
- cout << ex.what() << endl;
- /*cin.clear();
- while (cin.get() != '\n');
- continue;*/
- }
- }
- if (uy == "yes")
- {
- ann.fail();
- }
- }
- else
- {
- BD ann;
- ann.chtenie(exo);
- ann.sortirovka2();
- string uy;
- while (true)
- {
- cout << "Hotite sohranit? yes/no ";
- try
- {
- getline(cin, uy);
- if (uy != "no" && uy != "yes")
- {
- throw exception("Error: Nepravilnii vvod\n");
- }
- else { break; }
- }
- catch (const std::exception& ex)
- {
- cout << ex.what() << endl;
- /*cin.clear();
- while (cin.get() != '\n');
- continue;*/
- }
- }
- if (uy == "yes")
- {
- ann.fail();
- }
- }
- }
- if (yes_no == "del")
- {
- BD ann;
- ann.chtenie(exo);
- ann.udal();
- string uy;
- cin.get();
- while (true)
- {
- cout << "Hotite sohranit? yes/no ";
- try
- {
- getline(cin, uy);
- if (uy != "yes" && uy != "no")
- {
- throw exception("Error: Nepravilnii vvod\n");
- }
- else { break; }
- }
- catch (const std::exception& ex)
- {
- cout << ex.what() << endl;
- /*cin.clear();
- while (cin.get() != '\n');
- continue;*/
- }
- }
- if (uy == "yes")
- {
- ann.fail();
- }
- }
- if (yes_no == "dobavit")
- {
- BD ann;
- ann.chtenie(exo);
- ann.zapolnenie();
- ann.dobav(exo);
- string rar;
- while (true)
- {
- cout << "Sohranit izmenenia? yes / no ";
- try
- {
- cin >> rar;
- if (rar != "no" && rar != "yes")
- {
- throw exception("Error: Nepravilnii vvod\n");
- }
- else { break; }
- }
- catch (const std::exception& ex)
- {
- cout << ex.what() << endl;
- /*cin.clear();
- while (cin.get() != '\n');
- continue;*/
- }
- }
- if (rar == "yes")
- {
- ann.fail();
- cin.get();
- }
- }
- }
- if (vib == "dopolnitelnoe")
- {
- string y;
- while (true)
- {
- cout << endl << "1 - podschet pridili BD (pribil), 2 - poisk podrazdelenai vnytri BD po FIO (poisk po fio) " << endl;
- try
- {
- getline(cin, y);
- if (y != "pribil" && y != "poisk po fio")
- {
- throw exception("Error: Nepravilnii vvod\n");
- }
- else { break; }
- }
- catch (const std::exception& ex)
- {
- cout << ex.what() << endl;
- /*cin.clear();
- while (cin.get() != '\n');
- continue;*/
- }
- }
- {
- BD ann;
- ann.chtenie(exo);
- if (y == "pribil")
- {
- ann.profit();
- }
- else
- {
- ann.nach();
- }
- }
- }
- if (vib == "otkrit bd")
- {
- BD ann;
- ann.chtenie(exo);
- }
- if (vib == "viborka")
- {
- string vin;
- while (true)
- {
- cout << "Kakaia viborka? 1) po aspirantam, 2) po nachalniky ";
- try
- {
- getline(cin, vin);
- if (vin != "po aspirantam" && vin != "po nachalniky")
- {
- throw exception("Error: Nepravilnii vvod\n");
- }
- else { break; }
- }
- catch (const std::exception& ex)
- {
- cout << ex.what() << endl;
- /*cin.clear();
- while (cin.get() != '\n');
- continue;*/
- }
- }
- if (vin == "po aspirantam")
- {
- BD ann;
- ann.chtenie(exo);
- ann.aspir();
- ann.fail();
- }
- else
- {
- BD ann;
- ann.chtenie(exo);
- ann.nach();
- ann.fail();
- }
- }
- }
- while (true)
- {
- cout << endl << "Prodolgit? (yes/no)" << endl;
- try
- {
- getline(cin, flag2);
- if (flag2 != "no" && flag2 != "yes")
- {
- throw exception("Error: Oshibka vvoda");
- }
- else { break; }
- }
- catch (const std::exception& ex)
- {
- cout << ex.what() << endl;
- /*cin.clear();
- while (cin.get() != '\n');
- continue;*/
- }
- }
- } while (flag2 != "no");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement