Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <algorithm>
- #include <iterator>
- #include <iomanip>
- #include <stdio.h>
- #include <fstream>
- #include <string>
- #define N 100
- using namespace std;
- class Fio {
- char *name; //имя
- char *surname; //фамилия
- char *patronymic; //отчество
- friend class Poly;
- public:
- int static Num_of_fio;
- char *Get_name()
- {
- return name;
- }
- char *Get_surname()
- {
- return surname;
- }
- char *Get_patronymic()
- {
- return patronymic;
- }
- };
- int Fio::Num_of_fio = 0;
- class Poly {
- public:
- int static Num_of_Pep;
- private:
- Fio _fio;
- int count;
- int specialty;
- int qualification;
- public:
- void Print_list();
- void Print_Database(Poly*);
- void Filter_Base(Poly*);
- void Delete(Poly*&);
- void Set(Poly &object)
- {
- this->Num_of_Pep = object.Num_of_Pep;
- this->_fio.Num_of_fio = object._fio.Num_of_fio;
- this->_fio.name = new char[N];
- strcpy(this->_fio.name, object._fio.name);
- this->_fio.surname = new char[N];
- strcpy(this->_fio.surname, object._fio.surname);
- this->_fio.patronymic = new char[N];
- strcpy(this->_fio.patronymic, object._fio.patronymic);
- this->specialty = object.specialty;
- this->qualification = object.qualification;
- }
- Poly* database_buff(Poly **&, Poly*, int);
- Poly* Add_humans(Poly *);
- ///////////////////////
- void Read_File(Poly*&);
- void Write_File(Poly*);
- /////////////////////
- void Sort_by_Name(Poly *);
- friend void Find_Name(Poly *);
- ///////////////////////
- Poly(int i) : count(i)
- {
- Fio::Num_of_fio++;
- cout << "\nФИО №" << i + 1 << endl;
- cout << "\nВведите имя:" << endl;
- _fio.name = new char[N];
- cin >> _fio.name;
- cout << "\nВведите фамилию:" << endl;
- _fio.surname = new char[N];
- cin >> _fio.surname;
- cout << "\nВведите отчество:" << endl;
- _fio.patronymic = new char[N];
- cin >> _fio.patronymic;
- cout << "\nспециальность(1-терапевт, 2-кардиолог, 3- стоматолог)\t";
- cin >> specialty;
- cout << "\nквалификация (0-высшая, 1- первая, 2- вторая)\t";
- cin >> qualification;
- }
- Poly() {}
- ~Poly()
- {
- delete[] _fio.name;
- delete[] _fio.surname;
- delete[] _fio.patronymic;
- }
- Poly(const Poly ©)
- {
- this->Num_of_Pep = copy.Num_of_Pep;
- this->_fio.Num_of_fio = copy._fio.Num_of_fio;
- this->_fio.name = new char[N];
- strcpy(this->_fio.name, copy._fio.name);
- this->_fio.surname = new char[N];
- strcpy(this->_fio.surname, copy._fio.surname);
- this->_fio.patronymic = new char[N];
- strcpy(this->_fio.patronymic, copy._fio.patronymic);
- this->specialty = copy.specialty;
- this->qualification = copy.qualification;
- }
- Poly(int i, int peps)
- {
- ifstream fin;
- fin.open("file.txt");
- if (!fin.is_open())
- {
- cout << "file no open";
- }
- else
- {
- int trash;
- for (int i = 1; i <= Fio::Num_of_fio; i++)
- fin >> trash;
- fin.get();
- _fio.name = new char[N];
- fin.getline(_fio.name, N);
- Fio::Num_of_fio++;
- _fio.surname = new char[N];
- fin.getline(_fio.surname, N);
- Fio::Num_of_fio++;
- _fio.patronymic = new char[N];
- fin.getline(_fio.patronymic, N);
- Fio::Num_of_fio++;
- fin >> specialty;
- Fio::Num_of_fio++;
- fin >> qualification;
- Fio::Num_of_fio++;
- fin.get();
- fin.close();
- }
- }
- };
- int Poly::Num_of_Pep = 0;
- void cap()
- {
- cout << '\n' << setw(60) << "База дынных \"Поликлиника\"" << endl;
- cout << "ФИО врача" << setw(45) << "Специальность" << setw(55) << "Квалификация" << endl;
- cout.fill('.');
- cout << setw(160) << endl;
- }
- int main()
- {
- setlocale(LC_ALL, "russian");
- Poly *Arr_hum = 0;
- Arr_hum->Read_File(Arr_hum);
- while (true)
- {
- Arr_hum->Print_list();
- char def;
- cin >> def;
- switch (def)
- {
- case '1': Arr_hum = Arr_hum->Add_humans(Arr_hum); break;
- case '2': cap(); Arr_hum->Print_Database(Arr_hum); break;
- case '3': Find_Name(Arr_hum); break;
- case '4': Arr_hum->Filter_Base(Arr_hum); break;
- case '5': Arr_hum->Sort_by_Name(Arr_hum); break;
- case '6': Arr_hum->Delete(Arr_hum); break;
- case '0': break;
- }
- if (def == '0')
- {
- break;
- }
- }
- Arr_hum->Write_File(Arr_hum);
- delete[] Arr_hum;
- system("pause");
- return 0;
- }
- ////////////////////////////////
- void Poly::Read_File(Poly*&Arr_hum)
- {
- ifstream fin;
- fin.open("file.txt");
- if (!fin.is_open())
- {
- cout << "file no open";
- }
- else
- {
- Fio::Num_of_fio = 1;
- int peps;
- fin >> peps;
- fin.get();
- fin.close();
- Poly **humans = new Poly*[peps];
- for (int i = 0; i < peps; i++)
- humans[i] = new Poly(i, peps);
- Arr_hum = database_buff(humans, Arr_hum, peps);
- Poly::Num_of_Pep += peps;
- delete[] humans;
- }
- }
- void Poly::Write_File(Poly* Arr_hum)
- {
- ofstream fout;
- fout.open("file.txt", ofstream::out | ofstream::trunc);
- if (!fout.is_open())
- {
- cout << "Not write";
- }
- else
- {
- fout << Poly::Num_of_Pep << endl;
- for (int i = 0; i < Poly::Num_of_Pep; i++)
- {
- fout << Arr_hum[i]._fio.name << endl;
- fout << Arr_hum[i]._fio.surname << endl;
- fout << Arr_hum[i]._fio.patronymic << endl;
- fout << Arr_hum[i].specialty << endl;
- fout << Arr_hum[i].qualification << endl;
- }
- fout.close();
- }
- }
- ////////////////////////////////
- void Poly::Print_Database(Poly* Arr_hum)
- {
- for (int i = 0; i < Poly::Num_of_Pep; i++)
- {
- cout.fill(' ');
- cout << '\n' << Arr_hum[i]._fio.name << ' '
- << Arr_hum[i]._fio.surname << ' '
- << Arr_hum[i]._fio.patronymic << setw(40);
- switch (Arr_hum[i].specialty)
- {
- case 1: cout << "Терапевт" << setw(60); break;
- case 2: cout << "Кардиолог" << setw(60); break;
- case 3: cout << "Стоматолог" << setw(60); break;
- }
- switch (Arr_hum[i].qualification)
- {
- case 0: cout << "Высшая" << endl; break;
- case 1: cout << "Первая" << endl; break;
- case 2: cout << "Вторая" << endl; break;
- }
- cout.fill('.');
- cout << setw(160) << endl;
- }
- }
- void Poly::Filter_Base(Poly* Arr_hum)
- {
- int filterS, filterQ = 0;
- cout << "\nВведите номер специальности\n";
- cin >> filterS;
- cout << "\nВведите номер квалификации\n";
- cin >> filterQ;
- cout << '\n' << setw(60) << "База дынных \"Поликлиника\"" << endl;
- cout << "ФИО врача" << setw(45) << "Специальность" << setw(55) << "Квалификация" << endl;
- cout.fill('.');
- cout << setw(160) << endl;
- for (int i = 0; i < Poly::Num_of_Pep; i++)
- {
- if ((Arr_hum[i].specialty == filterS) && (Arr_hum[i].qualification == filterQ))
- {
- cout.fill(' ');
- cout << '\n' << Arr_hum[i]._fio.name
- << Arr_hum[i]._fio.surname
- << Arr_hum[i]._fio.patronymic << setw(40);
- switch (Arr_hum[i].specialty)
- {
- case 1: cout << "Терапевт" << setw(60); break;
- case 2: cout << "Кардиолог" << setw(60); break;
- case 3: cout << "Стоматолог" << setw(60); break;
- }
- switch (Arr_hum[i].qualification)
- {
- case 0: cout << "Высшая" << endl; break;
- case 1: cout << "Первая" << endl; break;
- case 2: cout << "Вторая" << endl; break;
- }
- cout.fill('.');
- cout << setw(160) << endl;
- }
- }
- }
- void Find_Name(Poly *Arr_hum)
- {
- //sort(Arr_hum, (Arr_hum + Poly::Num_of_Pep), comp);
- cout << "\nВведите поисковое ФИО\t";
- char *find_n = new char[N];
- char *find_s = new char[N];
- char *find_p = new char[N];
- cin >> find_n >> find_s >> find_p;
- int rez = 0;
- for (int i = 0; i < Poly::Num_of_Pep; i++)
- {
- if ((strcmp((Arr_hum + i)->_fio.Get_name(), find_n) == 0) &&
- (strcmp((Arr_hum + i)->_fio.Get_surname(), find_s) == 0) &&
- (strcmp((Arr_hum + i)->_fio.Get_patronymic(), find_p) == 0))
- {
- cout << "Поисковое ФИО:\t" << setw(45) << "Специальность" << setw(55) << "Квалификация" << endl;
- cout.fill('.');
- cout << setw(140) << endl;
- cout << "\n" << Arr_hum[i]._fio.Get_name() << ' '
- << Arr_hum[i]._fio.Get_surname()
- << ' ' << Arr_hum[i]._fio.Get_patronymic() << setw(40);
- switch (Arr_hum[i].specialty)
- {
- case 1: cout << "Терапевт" << setw(60); break;
- case 2: cout << "Кардиолог" << setw(60); break;
- case 3: cout << "Стоматолог" << setw(60); break;
- }
- switch (Arr_hum[i].qualification)
- {
- case 0: cout << "Высшая" << endl; break;
- case 1: cout << "Первая" << endl; break;
- case 2: cout << "Вторая" << endl; break;
- }
- cout.fill('.');
- cout << setw(160) << endl;
- rez = 1;
- }
- }
- if (rez == 0)
- cout << "\nДанного человека нет в базе";
- delete[] find_n;
- delete[] find_s;
- delete[] find_p;
- }
- void Poly::Sort_by_Name(Poly *Arr_hum)
- {
- for (int i = 0; i < Poly::Num_of_Pep; i++)
- {
- for (int j = 0; j < (Poly::Num_of_Pep - 1); j++)
- {
- if (strcmp(Arr_hum[j]._fio.Get_name(), Arr_hum[j + 1]._fio.Get_name()) > 0) // name
- {
- Poly buff(Arr_hum[j]);
- Arr_hum[j].Set(Arr_hum[j + 1]);
- Arr_hum[j + 1].Set(buff);
- }
- if (strcmp(Arr_hum[j]._fio.Get_name(), Arr_hum[j + 1]._fio.Get_name()) == 0) //if name1==name2
- {
- if (strcmp(Arr_hum[j]._fio.Get_surname(), Arr_hum[j + 1]._fio.Get_surname()) > 0) //surname
- {
- Poly buff(Arr_hum[j]);
- Arr_hum[j].Set(Arr_hum[j + 1]);
- Arr_hum[j + 1].Set(buff);
- }
- if (strcmp(Arr_hum[j]._fio.Get_surname(), Arr_hum[j + 1]._fio.Get_surname()) == 0) //if surname1==surname2
- {
- if (strcmp(Arr_hum[j]._fio.Get_patronymic(), Arr_hum[j + 1]._fio.Get_patronymic()) > 0)//patronymic
- {
- Poly buff(Arr_hum[j]);
- Arr_hum[j].Set(Arr_hum[j + 1]);
- Arr_hum[j + 1].Set(buff);
- }
- }
- }
- }
- }
- //sort(Arr_hum, (Arr_hum + Poly::Num_of_Pep), comp);
- for (int i = 0; i < Poly::Num_of_Pep; i++)
- {
- cout << '\n' << Arr_hum[i]._fio.name
- << Arr_hum[i]._fio.surname
- << Arr_hum[i]._fio.patronymic << setw(40);
- switch (Arr_hum[i].specialty)
- {
- case 1: cout << "Терапевт" << setw(60); break;
- case 2: cout << "Кардиолог" << setw(60); break;
- case 3: cout << "Стоматолог" << setw(60); break;
- }
- switch (Arr_hum[i].qualification)
- {
- case 0: cout << "Высшая" << endl; break;
- case 1: cout << "Первая" << endl; break;
- case 2: cout << "Вторая" << endl; break;
- }
- cout.fill('.');
- cout << setw(160) << endl;
- }
- }
- void Poly::Print_list()
- {
- cout << "\nДобавить нового человека ....................1";
- cout << "\nРаспечатать базу поликлиники................ 2";
- cout << "\nПоиск человека по имени .....................3";
- cout << "\nФильтр по квалификации .....................4";
- cout << "\nСортировать по алфавиту ....................5";
- cout << "\nУдалить эелемент.............................6";
- cout << "\nВыход из программы ..........................0";
- cout << "\n..............................................";
- cout << "\nВведите номер функции\n";
- }
- Poly* Poly::Add_humans(Poly *Arr_hum)
- {
- int peps;
- cout << "\nhow many people you want to create?\t";
- cin >> peps;
- int a = 0;
- Poly **humans = new Poly*[peps];
- for (int i = 0; i < peps; i++)
- humans[i] = new Poly(i);
- Arr_hum = database_buff(humans, Arr_hum, peps);
- Poly::Num_of_Pep += peps;
- /////
- for (int i = 0; i < peps; i++)
- delete humans[i];
- delete[] humans;
- return Arr_hum;
- }
- void Poly::Delete(Poly *&Arr_hum)
- {
- //sort(Arr_hum, (Arr_hum + Poly::Num_of_Pep), comp);
- cout << "\nВведите поисковое ФИО\t";
- char *find_n = new char[N];
- char *find_s = new char[N];
- char *find_p = new char[N];
- cin >> find_n >> find_s >> find_p;
- int rez = 0;
- for (int i = 0; i < Poly::Num_of_Pep; i++)
- {
- if ((strcmp((Arr_hum + i)->_fio.Get_name(), find_n) == 0) &&
- (strcmp((Arr_hum + i)->_fio.Get_surname(), find_s) == 0) &&
- (strcmp((Arr_hum + i)->_fio.Get_patronymic(), find_p) == 0))
- {
- Poly buff(Arr_hum[i]);
- Arr_hum[i].Set(Arr_hum[Poly::Num_of_Pep - 1]);
- Arr_hum[Poly::Num_of_Pep - 1].Set(buff);
- Poly *Arr_buff = new Poly[Poly::Num_of_Pep-1];
- for (int j = 0; j < Poly::Num_of_Pep - 1; j++)
- {
- Poly buff2(Arr_hum[j]);
- Arr_buff[j].Set(buff2);
- }
- delete[] Arr_hum;
- Arr_hum = Arr_buff;
- break;
- }
- }
- Poly::Num_of_Pep -= 1;
- }
- Poly* Poly::database_buff(Poly **&humans, Poly *Arr_hum, int peps)
- {
- Poly *Arr_hum_buff = new Poly[peps];
- //copy(humans, humans + peps, Arr_hum_buff);
- for (int i = 0; i < peps; i++)
- {
- Poly buff(humans[i][0]);
- Arr_hum_buff[i].Set(buff);
- }
- if (Poly::Num_of_Pep == 0)
- {
- Arr_hum = new Poly[peps];
- for (int i = 0; i < peps; i++)
- {
- Poly buff(Arr_hum_buff[i]);
- Arr_hum[i].Set(buff);
- }
- }
- if (Poly::Num_of_Pep != 0)
- {
- { //изменение размера Arr_hum
- Poly *small_buff = new Poly[Poly::Num_of_Pep + peps];
- for (int i = 0; i < Poly::Num_of_Pep; i++)
- {
- Poly buff(Arr_hum[i]);
- small_buff[i].Set(buff);
- }
- //copy(Arr_hum, Arr_hum + Poly::Num_of_Pep, small_buff);
- delete[] Arr_hum;
- Arr_hum = small_buff;
- }
- for (int i = 0; i < peps; )
- {
- for (int j = Poly::Num_of_Pep; j < Poly::Num_of_Pep + peps; j++)
- {
- Poly buff(Arr_hum_buff[i]);
- Arr_hum[j].Set(buff);
- i++;
- }
- }
- //copy(Arr_hum_buff, Arr_hum_buff + peps, Arr_hum + Poly::Num_of_Pep);
- }
- delete[] Arr_hum_buff; // при заходе >0 buff будет другим
- return Arr_hum;
- }
- //bool comp(Poly A, Poly B)
- //{
- // if (strcmp(A._fio.Get_name(), B._fio.Get_name()) < 0)
- // return true;
- // else return false;
- //
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement