Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include<fstream>
- #include<sstream>
- #include<vector>
- #include <conio.h>
- using namespace std;
- int opcja;
- class osoba
- {
- private:
- public:
- string imie, nazwisko, status;
- int pesel;
- int wiek;
- int obecnosc;
- osoba()
- {};
- };
- class student : public osoba
- {
- public:
- student()
- {
- status = "student";//wywołać konstruktor
- cout << "podaj imie"<<endl;
- cin >> imie >> nazwisko >> pesel >> wiek >> obecnosc;
- };
- };
- class nauczyciel : public osoba
- {
- };
- vector <student> studenci;
- vector <osoba> osoby;
- vector <nauczyciel> nauczyciele;
- void menu()
- {
- system("cls");
- cout << "--------DZIENNIK--------" << endl;
- cout << "------------------------" << endl;
- cout << "1. Dodaj osobe" << endl;
- cout << "2. Wyswietl liste osob" << endl;
- cout << "3. Sortuj studentow" << endl;
- cout << "a. po imieniu" << endl;
- cout << "4. Sortuj nauczycieli" << endl;
- cout << "6. Sortuj po peselu" << endl;
- cout << "ESC - Wyjscie" << endl;
- opcja = _getch();
- }
- void submenu1()
- {
- system("cls");
- cout << "sortuj studentow po:" << endl;
- cout << "1. Sortuj po imieniu" << endl;
- cout << "2. Sortuj po nazwisku" << endl;
- cout << "ESC - cofnij" << endl;
- opcja = _getch();
- }
- osoba *sortuj_pesel(vector <osoba> tab, int indeks_dolny, int indeks_gorny) { //sortowanie po indeksie studenta
- int srodek = (indeks_dolny + indeks_gorny) / 2;
- osoba piwot;
- piwot = tab[indeks_gorny];
- swap(piwot, tab[srodek]);
- int j = indeks_dolny;
- osoba zm;
- for (int i = indeks_dolny; i < indeks_gorny; i++)
- {
- zm = tab[i];
- if (zm.pesel < piwot.pesel) // indeks studenta
- {
- swap(tab[i], tab[j]);
- j++;
- }
- }
- tab[indeks_gorny] = tab[j];
- tab[j] = piwot;
- if (indeks_dolny < j - 1)
- {
- sortuj_pesel(tab, indeks_dolny, j - 1);
- }
- if (j + 1 < indeks_gorny)
- {
- sortuj_pesel(tab, j + 1, indeks_gorny);
- }
- osoba *tabstudentow = new osoba[indeks_gorny]; //studenci?
- for (int i = 0; i < indeks_gorny - 1; i++)
- {
- tabstudentow[i] = tab[i];
- }
- return tabstudentow;
- }
- student *sortuj_pesel(vector <student> tab, int indeks_dolny, int indeks_gorny) { //sortowanie po indeksie studenta
- int srodek = (indeks_dolny + indeks_gorny) / 2;
- student piwot= tab[indeks_gorny];
- //piwot = tab[indeks_gorny];
- swap(piwot, tab[srodek]);
- int j = indeks_dolny;
- student zm = tab[indeks_dolny];
- for (int i = indeks_dolny; i < indeks_gorny; i++)
- {
- zm = tab[i];
- if (zm.pesel < piwot.pesel) // indeks studenta
- {
- swap(tab[i], tab[j]);
- j++;
- }
- }
- tab[indeks_gorny] = tab[j];
- tab[j] = piwot;
- if (indeks_dolny < j - 1)
- {
- sortuj_pesel(tab, indeks_dolny, j - 1);
- }
- if (j + 1 < indeks_gorny)
- {
- sortuj_pesel(tab, j + 1, indeks_gorny);
- }
- student *tabstudentow = new student[indeks_gorny]; //studenci?
- for (int i = 0; i < indeks_gorny - 1; i++)
- {
- tabstudentow[i] = tab[i];
- }
- return tabstudentow;
- }
- nauczyciel *sortuj_pesel(vector <nauczyciel> tab, int indeks_dolny, int indeks_gorny) { //sortowanie po indeksie studenta
- int srodek = (indeks_dolny + indeks_gorny) / 2;
- nauczyciel piwot;
- piwot = tab[indeks_gorny];
- swap(piwot, tab[srodek]);
- int j = indeks_dolny;
- nauczyciel zm;
- for (int i = indeks_dolny; i < indeks_gorny; i++)
- {
- zm = tab[i];
- if (zm.pesel < piwot.pesel) // indeks studenta
- {
- swap(tab[i], tab[j]);
- j++;
- }
- }
- tab[indeks_gorny] = tab[j];
- tab[j] = piwot;
- if (indeks_dolny < j - 1)
- {
- sortuj_pesel(tab, indeks_dolny, j - 1);
- }
- if (j + 1 < indeks_gorny)
- {
- sortuj_pesel(tab, j + 1, indeks_gorny);
- }
- nauczyciel *tabstudentow = new nauczyciel[indeks_gorny]; //nauczyciele
- for (int i = 0; i < indeks_gorny - 1; i++)
- {
- tabstudentow[i] = tab[i];
- }
- return tabstudentow;
- }
- student *wsk_studtab_sort;
- osoba *wsk_osobatab_sort;
- nauczyciel *wsk_naucztab_sort;
- int main() {
- int zm = 1;
- while (1)
- {
- student zmnienna = student();
- studenci.push_back (zmnienna);
- //osoby.push_back = studenci[studenci.size];
- cout << "czy chcesz dodac koljnego studenta [t/n]" << endl;
- opcja = _getch();
- if (opcja = 110) {
- break; //wyjscie z while
- }
- }
- int wielkosc = studenci.size();
- wsk_studtab_sort= sortuj_pesel(studenci, 0, wielkosc - 1); //przypisanie wskaznikowi posortowanej tablicy
- for (int i = 0;i < wielkosc;i++) //posortowanie tablicy z wskaznika
- {
- cout << wsk_studtab_sort->imie[i] << wsk_studtab_sort->nazwisko[i]<< wsk_studtab_sort->status[i] << endl;
- }
- osoba tab11[1];
- student tab1[1];
- tab11[0] = tab1[0];
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement