Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.93 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.     {};
  21. };
  22. class student : public osoba
  23. {
  24. public:
  25.     student(int i)
  26.     {
  27.         status = "student";//wywołać konstruktor
  28.         pesel = 0;
  29.         cout << "podaj imie" << endl;
  30.         cin >> imie >> nazwisko;
  31.     };
  32.     student() {};
  33. };
  34. class nauczyciel : public osoba
  35. {
  36.  
  37. };
  38. vector <student>* studenci = new vector <student>;
  39. vector <osoba>* osoby = new vector <osoba>;
  40. vector <nauczyciel>* nauczyciele = new vector <nauczyciel>;
  41.  
  42. void menu()
  43. {
  44.     system("cls");
  45.     cout << "--------DZIENNIK--------" << endl;
  46.     cout << "------------------------" << endl;
  47.     cout << "1. Dodaj osobe" << endl;
  48.     cout << "2. Wyswietl liste osob" << endl;
  49.     cout << "3. Sortuj studentow" << endl;
  50.     cout << "4. Sortuj nauczycieli" << endl;
  51.     cout << "5. Sortuj osoby" << endl;
  52.     cout << "6. Sortuj po peselu" << endl;
  53.     cout << "ESC - Wyjscie" << endl;
  54.  
  55.     opcja = _getch();
  56. }
  57. void submenu1()
  58. {
  59.     system("cls");
  60.     cout << "sortuj studentow po:" << endl;
  61.     cout << "1. Sortuj po imieniu" << endl;
  62.     cout << "2. Sortuj po nazwisku" << endl;
  63.  
  64.     cout << "ESC - cofnij" << endl;
  65.  
  66.     opcja2 = _getch();
  67. }
  68.  
  69. vector <student> sortuj_imie(vector <student> tab, int indeks_dolny, int indeks_gorny) {  //sortowanie po imieniu studenta
  70.     int srodek = (indeks_dolny + indeks_gorny) / 2;
  71.     student piwot = tab[indeks_gorny];
  72.     swap(piwot, tab[srodek]);
  73.     int j = indeks_dolny;
  74.     student zm;
  75.     for (int i = indeks_dolny; i < indeks_gorny; i++)
  76.     {
  77.         zm = tab[i];
  78.         if (zm.imie < piwot.imie)  // imieniu studenta
  79.         {
  80.             swap(tab[i], tab[j]);
  81.             j++;
  82.         }
  83.     }
  84.     tab[indeks_gorny] = tab[j];
  85.     tab[j] = piwot;
  86.     if (indeks_dolny < j - 1)
  87.     {
  88.         sortuj_imie(tab, indeks_dolny, j-1 );
  89.     }
  90.     if (j + 1 < indeks_gorny)
  91.     {
  92.         sortuj_imie(tab, j + 1, indeks_gorny);
  93.     }
  94.     return tab;
  95. }
  96. vector <student> sortuj_nazwisko(vector <student> tab, int indeks_dolny, int indeks_gorny) {  //sortowanie po nazwisku studenta
  97.     int srodek = (indeks_dolny + indeks_gorny) / 2;
  98.     student piwot = tab[indeks_gorny];
  99.     swap(piwot, tab[srodek]);
  100.     int j = indeks_dolny;
  101.     student zm;
  102.     for (int i = indeks_dolny; i < indeks_gorny; i++)
  103.     {
  104.         zm = tab[i];
  105.         if (zm.nazwisko < piwot.nazwisko)  // nazwisko studenta
  106.         {
  107.             swap(tab[i], tab[j]);
  108.             j++;
  109.         }
  110.     }
  111.     tab[indeks_gorny] = tab[j];
  112.     tab[j] = piwot;
  113.     if (indeks_dolny < j - 1)
  114.     {
  115.         sortuj_nazwisko(tab, indeks_dolny, j - 1);
  116.     }
  117.     if (j + 1 < indeks_gorny)
  118.     {
  119.         sortuj_nazwisko(tab, j + 1, indeks_gorny);
  120.     }
  121.     return tab;
  122. }
  123.  
  124.  
  125. void wyswietl(vector <student> tab)
  126. {
  127.     for (int i = 0; i < tab.size(); i++)
  128.     {
  129.         cout << tab[i].imie << endl;
  130.  
  131.     }
  132. }
  133. void wyswietl(vector <osoba> tab)
  134. {
  135.     for (int i = 0; i < tab.size(); i++)
  136.     {
  137.         cout << tab[i].imie << endl;
  138.  
  139.     }
  140. }
  141.  
  142. student zmnienna ;
  143. int main()
  144. {
  145.     int opcja1, wielkosc;
  146.     while (1)
  147.     {
  148.         menu();
  149.         switch (opcja)
  150.         {
  151.         case 27:                                        //wyjscie
  152.             exit(0);
  153.             break;
  154.  
  155.  
  156.         case 49:                                        //dodaj osobe
  157.  
  158.             zmnienna = student(0);
  159.             studenci->push_back(zmnienna);
  160.             osoby->push_back(zmnienna);
  161.             break;
  162.         case 50:                                    //wyswietl liste wszystkich
  163.             wyswietl(*osoby);
  164.  
  165.             system("pause");
  166.             break;
  167.  
  168.         case 51:                                    //sortuj studentow
  169.             submenu1();
  170.             switch (opcja2) {
  171.             case 49: {                              //po imieniu
  172.                
  173.                 *studenci = sortuj_imie(*studenci, 0, studenci->size() - 1);
  174.                 *studenci = sortuj_imie(*studenci, 0, studenci->size() - 1);
  175.                 wyswietl(*studenci);
  176.                 system("pause");
  177.                
  178.                     }
  179.                      break;
  180.             case 50:                                    //po nazwisku
  181.                 *studenci = sortuj_nazwisko(*studenci, 0, studenci->size() - 1);
  182.                 *studenci = sortuj_nazwisko(*studenci, 0, studenci->size() - 1);
  183.                 wyswietl(*studenci);
  184.                 system("pause");
  185.                 break;
  186.  
  187.             default: {}break;
  188.  
  189.                 break;
  190.  
  191.             }
  192.         }
  193.     }
  194.     return 0;
  195.  
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement