Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include<fstream>
  4. #include<sstream>
  5. #include<vector>
  6. #include <conio.h>
  7.  
  8. using namespace std;
  9. int opcja, opcja2;
  10.  
  11. class osoba
  12. {
  13. private:
  14. public:
  15.     string imie, nazwisko , status;
  16.     int pesel;
  17.     //int wiek;
  18.     //int obecnosc;
  19.     osoba(){};
  20.     osoba(int i)
  21.     {
  22.         status = "osoba";//wywołać konstruktor
  23.         pesel = 0;
  24.         cout << "podaj imie" << endl;
  25.         cin >> imie >> nazwisko;
  26.     };
  27. };
  28. class student : public osoba
  29. {
  30. public:
  31.     student(int i)
  32.     {
  33.         status = "student";//wywołać konstruktor
  34.         pesel = 0;
  35.         cout << "podaj imie" << endl;
  36.         cin >> imie >> nazwisko;
  37.     };
  38.     student() {};
  39. };
  40. class nauczyciel : public osoba
  41. {
  42.     public:
  43.         nauczyciel() {};
  44.         nauczyciel(int i)
  45.         {
  46.             status = "nauczyciel";
  47.             pesel = 0;
  48.             cout << "podaj imie" << endl;
  49.             cin >> imie >> nazwisko;
  50.         };
  51. };
  52. vector <student>* studenci = new vector <student>;
  53. vector <osoba>* osoby = new vector <osoba>;
  54. vector <nauczyciel>* nauczyciele = new vector <nauczyciel>;
  55.  
  56. void menu()
  57. {
  58.     system("cls");
  59.     cout << "--------DZIENNIK--------" << endl;
  60.     cout << "------------------------" << endl;
  61.     cout << "1. Dodaj osobe" << endl;
  62.     cout << "2. Wyswietl liste osob" << endl;
  63.     cout << "3. Sortuj studentow" << endl;
  64.     cout << "4. Sortuj nauczycieli" << endl;
  65.     cout << "5. Sortuj osoby" << endl;
  66.     cout << "6. Sortuj po peselu" << endl;
  67.     cout << "ESC - Wyjscie" << endl;
  68.  
  69.     opcja = _getch();
  70. }
  71. void submenu_sortujstud()
  72. {
  73.     system("cls");
  74.     cout << "sortuj studentow po:" << endl;
  75.     cout << "1. Sortuj po imieniu" << endl;
  76.     cout << "2. Sortuj po nazwisku" << endl;
  77.  
  78.     cout << "ESC - cofnij" << endl;
  79.  
  80.     opcja2 = _getch();
  81. }
  82. void submenu_dodajosobe()
  83. {
  84.     system("cls");
  85.     cout << "1. dodaj studenta" << endl;
  86.     cout << "2. dodaj nauczyciela" << endl;
  87.     cout << "3. dodaj osobe" << endl;
  88.  
  89.     cout << "ESC - cofnij" << endl;
  90.  
  91.     opcja2 = _getch();
  92. }
  93.  
  94. vector <student> sortuj_imie(vector <student> tab, int indeks_dolny, int indeks_gorny) {  //sortowanie po imieniu studenta
  95.     int srodek = (indeks_dolny + indeks_gorny) / 2;
  96.     student piwot = tab[indeks_gorny];
  97.     swap(piwot, tab[srodek]);
  98.     int j = indeks_dolny;
  99.     student zm;
  100.     for (int i = indeks_dolny; i < indeks_gorny; i++)
  101.     {
  102.         zm = tab[i];
  103.         if (zm.imie < piwot.imie)  // imieniu studenta
  104.         {
  105.             swap(tab[i], tab[j]);
  106.             j++;
  107.         }
  108.     }
  109.     tab[indeks_gorny] = tab[j];
  110.     tab[j] = piwot;
  111.     if (indeks_dolny < j - 1)
  112.     {
  113.         sortuj_imie(tab, indeks_dolny, j-1 );
  114.     }
  115.     if (j + 1 < indeks_gorny)
  116.     {
  117.         sortuj_imie(tab, j + 1, indeks_gorny);
  118.     }
  119.     return tab;
  120. }
  121. vector <student> sortuj_nazwisko(vector <student> tab, int indeks_dolny, int indeks_gorny) {  //sortowanie po nazwisku studenta
  122.     int srodek = (indeks_dolny + indeks_gorny) / 2;
  123.     student piwot = tab[indeks_gorny];
  124.     swap(piwot, tab[srodek]);
  125.     int j = indeks_dolny;
  126.     student zm;
  127.     for (int i = indeks_dolny; i < indeks_gorny; i++)
  128.     {
  129.         zm = tab[i];
  130.         if (zm.nazwisko < piwot.nazwisko)  // nazwisko studenta
  131.         {
  132.             swap(tab[i], tab[j]);
  133.             j++;
  134.         }
  135.     }
  136.     tab[indeks_gorny] = tab[j];
  137.     tab[j] = piwot;
  138.     if (indeks_dolny < j - 1)
  139.     {
  140.         sortuj_nazwisko(tab, indeks_dolny, j - 1);
  141.     }
  142.     if (j + 1 < indeks_gorny)
  143.     {
  144.         sortuj_nazwisko(tab, j + 1, indeks_gorny);
  145.     }
  146.     return tab;
  147. }
  148.  
  149.  
  150. void wyswietl(vector <student> tab)
  151. {
  152.     for (int i = 0; i < tab.size(); i++)
  153.     {
  154.         cout << tab[i].imie << endl;
  155.  
  156.     }
  157. }
  158. void wyswietl(vector <osoba> tab)
  159. {
  160.     for (int i = 0; i < tab.size(); i++)
  161.     {
  162.         cout << tab[i].imie << endl;
  163.  
  164.     }
  165. }
  166.  
  167. student zmienna_stud ;
  168. nauczyciel zmienna_naucz;
  169. osoba zmienna_os;
  170. int main()
  171. {
  172.     int opcja1, wielkosc;
  173.     while (1)
  174.     {
  175.         menu();
  176.         switch (opcja)
  177.         {
  178.         case 27:                                        //wyjscie
  179.             exit(0);
  180.             break;
  181.  
  182.  
  183.         case 49:                                        //dodaj osobe
  184.             submenu_dodajosobe();
  185.             switch (opcja2)
  186.             {
  187.             case 49:        //student
  188.                 zmienna_stud = student(0);
  189.                 studenci->push_back(zmienna_stud);
  190.                 osoby->push_back(zmienna_stud);
  191.                 break;
  192.             case 50:        //nauczyciel
  193.                 zmienna_naucz = nauczyciel(0);
  194.                 nauczyciele->push_back(zmienna_naucz);
  195.                 osoby->push_back(zmienna_naucz);
  196.                 break;
  197.             case 51:        //osoba
  198.                 zmienna_os = osoba(0);
  199.                 osoby->push_back(zmienna_os);
  200.                 break;
  201.             default:
  202.                 break;
  203.             }
  204.            
  205.             break;
  206.         case 50:                                    //wyswietl liste wszystkich
  207.             wyswietl(*osoby);
  208.  
  209.             system("pause");
  210.             break;
  211.  
  212.         case 51:                                    //sortuj studentow
  213.             submenu_sortujstud();
  214.             switch (opcja2) {
  215.             case 49: {                              //po imieniu
  216.                
  217.                 *studenci = sortuj_imie(*studenci, 0, studenci->size() - 1);
  218.                 *studenci = sortuj_imie(*studenci, 0, studenci->size() - 1);
  219.                 wyswietl(*studenci);
  220.                 system("pause");
  221.                
  222.                     }
  223.                      break;
  224.             case 50:                                    //po nazwisku
  225.                 *studenci = sortuj_nazwisko(*studenci, 0, studenci->size() - 1);
  226.                 *studenci = sortuj_nazwisko(*studenci, 0, studenci->size() - 1);
  227.                 wyswietl(*studenci);
  228.                 system("pause");
  229.                 break;
  230.  
  231.             default: {}break;
  232.  
  233.                 break;
  234.  
  235.             }
  236.         }
  237.     }
  238.     return 0;
  239.  
  240. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement