Advertisement
Guest User

dziennik_klasy

a guest
Jun 17th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.55 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;
  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()
  26.     {
  27.         status = "student";//wywołać konstruktor
  28.         cout << "podaj imie"<<endl;
  29.         cin >> imie >> nazwisko >> pesel >> wiek >> obecnosc;
  30.  
  31.     };
  32. };
  33. class nauczyciel : public osoba
  34. {
  35.    
  36. };
  37. vector <student> studenci;
  38. vector <osoba> osoby;
  39. vector <nauczyciel> nauczyciele;
  40.  
  41. void menu()
  42. {
  43.     system("cls");
  44.     cout << "--------DZIENNIK--------" << endl;
  45.     cout << "------------------------" << endl;
  46.     cout << "1. Dodaj osobe" << endl;
  47.     cout << "2. Wyswietl liste osob" << endl;
  48.     cout << "3. Sortuj studentow" << endl;
  49.     cout << "a. po imieniu" << endl;
  50.     cout << "4. Sortuj nauczycieli" << endl;
  51.    
  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.     opcja = _getch();
  67. }
  68.  
  69. osoba *sortuj_pesel(vector <osoba> tab, int indeks_dolny, int indeks_gorny) {  //sortowanie po indeksie studenta
  70.     int srodek = (indeks_dolny + indeks_gorny) / 2;
  71.     osoba piwot;
  72.     piwot = tab[indeks_gorny];
  73.     swap(piwot, tab[srodek]);
  74.     int j = indeks_dolny;
  75.     osoba zm;
  76.     for (int i = indeks_dolny; i < indeks_gorny; i++)
  77.     {
  78.         zm = tab[i];
  79.         if (zm.pesel < piwot.pesel)  // indeks studenta
  80.         {
  81.             swap(tab[i], tab[j]);
  82.             j++;
  83.         }
  84.     }
  85.     tab[indeks_gorny] = tab[j];
  86.     tab[j] = piwot;
  87.     if (indeks_dolny < j - 1)
  88.     {
  89.         sortuj_pesel(tab, indeks_dolny, j - 1);
  90.     }
  91.     if (j + 1 < indeks_gorny)
  92.     {
  93.         sortuj_pesel(tab, j + 1, indeks_gorny);
  94.     }
  95.     osoba *tabstudentow = new osoba[indeks_gorny]; //studenci?
  96.         for (int i = 0; i < indeks_gorny - 1; i++)
  97.         {
  98.             tabstudentow[i] = tab[i];
  99.         }
  100.     return tabstudentow;
  101. }
  102. student *sortuj_pesel(vector <student> tab, int indeks_dolny, int indeks_gorny) {  //sortowanie po indeksie studenta
  103.     int srodek = (indeks_dolny + indeks_gorny) / 2;
  104.     student piwot= tab[indeks_gorny];
  105.     //piwot = tab[indeks_gorny];
  106.     swap(piwot, tab[srodek]);
  107.     int j = indeks_dolny;
  108.     student zm = tab[indeks_dolny];
  109.     for (int i = indeks_dolny; i < indeks_gorny; i++)
  110.     {
  111.         zm = tab[i];
  112.         if (zm.pesel < piwot.pesel)  // indeks studenta
  113.         {
  114.             swap(tab[i], tab[j]);
  115.             j++;
  116.         }
  117.     }
  118.     tab[indeks_gorny] = tab[j];
  119.     tab[j] = piwot;
  120.     if (indeks_dolny < j - 1)
  121.     {
  122.         sortuj_pesel(tab, indeks_dolny, j - 1);
  123.     }
  124.     if (j + 1 < indeks_gorny)
  125.     {
  126.         sortuj_pesel(tab, j + 1, indeks_gorny);
  127.     }
  128.     student *tabstudentow = new student[indeks_gorny]; //studenci?
  129.     for (int i = 0; i < indeks_gorny - 1; i++)
  130.     {
  131.         tabstudentow[i] = tab[i];
  132.     }
  133.     return tabstudentow;
  134. }
  135.  
  136. nauczyciel *sortuj_pesel(vector <nauczyciel> tab, int indeks_dolny, int indeks_gorny) {  //sortowanie po indeksie studenta
  137.     int srodek = (indeks_dolny + indeks_gorny) / 2;
  138.     nauczyciel piwot;
  139.     piwot = tab[indeks_gorny];
  140.     swap(piwot, tab[srodek]);
  141.     int j = indeks_dolny;
  142.     nauczyciel zm;
  143.     for (int i = indeks_dolny; i < indeks_gorny; i++)
  144.     {
  145.         zm = tab[i];
  146.         if (zm.pesel < piwot.pesel)  // indeks studenta
  147.         {
  148.             swap(tab[i], tab[j]);
  149.             j++;
  150.         }
  151.     }
  152.     tab[indeks_gorny] = tab[j];
  153.     tab[j] = piwot;
  154.     if (indeks_dolny < j - 1)
  155.     {
  156.         sortuj_pesel(tab, indeks_dolny, j - 1);
  157.     }
  158.     if (j + 1 < indeks_gorny)
  159.     {
  160.         sortuj_pesel(tab, j + 1, indeks_gorny);
  161.     }
  162.     nauczyciel *tabstudentow = new nauczyciel[indeks_gorny]; //nauczyciele
  163.     for (int i = 0; i < indeks_gorny - 1; i++)
  164.     {
  165.         tabstudentow[i] = tab[i];
  166.     }
  167.     return tabstudentow;
  168. }
  169.  
  170.  
  171. student *wsk_studtab_sort;
  172. osoba *wsk_osobatab_sort;
  173. nauczyciel *wsk_naucztab_sort;
  174.  
  175. int main() {
  176.     int zm = 1;
  177.     while (1)
  178.     {
  179.         student zmnienna = student();
  180.         studenci.push_back (zmnienna);
  181.        
  182.         //osoby.push_back = studenci[studenci.size];
  183.        
  184.         cout << "czy chcesz dodac koljnego studenta [t/n]" << endl;
  185.         opcja = _getch();
  186.         if (opcja = 110) {
  187.             break; //wyjscie z while
  188.         }
  189.     }
  190.    
  191.  
  192.     int wielkosc = studenci.size();
  193.     wsk_studtab_sort=  sortuj_pesel(studenci, 0, wielkosc - 1);  //przypisanie wskaznikowi posortowanej tablicy
  194.     for (int i = 0;i < wielkosc;i++)  //posortowanie tablicy z wskaznika
  195.     {
  196.  
  197.         cout << wsk_studtab_sort->imie[i] << wsk_studtab_sort->nazwisko[i]<< wsk_studtab_sort->status[i] << endl;
  198.     }
  199.     osoba tab11[1];
  200.     student tab1[1];
  201.     tab11[0] = tab1[0];
  202.     system("pause");
  203.     return 0;
  204.  
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement