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, opcja2;
- class osoba
- {
- private:
- public:
- string imie, nazwisko , status;
- int pesel;
- //int wiek;
- //int obecnosc;
- osoba()
- {};
- };
- class student : public osoba
- {
- public:
- student(int i)
- {
- status = "student";//wywołać konstruktor
- pesel = 0;
- cout << "podaj imie" << endl;
- cin >> imie >> nazwisko;
- };
- student() {};
- };
- class nauczyciel : public osoba
- {
- };
- vector <student>* studenci = new vector <student>;
- vector <osoba>* osoby = new vector <osoba>;
- vector <nauczyciel>* nauczyciele = new vector <nauczyciel>;
- 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 << "4. Sortuj nauczycieli" << endl;
- cout << "5. Sortuj osoby" << 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;
- opcja2 = _getch();
- }
- vector <student> sortuj_imie(vector <student> tab, int indeks_dolny, int indeks_gorny) { //sortowanie po imieniu studenta
- int srodek = (indeks_dolny + indeks_gorny) / 2;
- student piwot = tab[indeks_gorny];
- swap(piwot, tab[srodek]);
- int j = indeks_dolny;
- student zm;
- for (int i = indeks_dolny; i < indeks_gorny; i++)
- {
- zm = tab[i];
- if (zm.imie < piwot.imie) // imieniu studenta
- {
- swap(tab[i], tab[j]);
- j++;
- }
- }
- tab[indeks_gorny] = tab[j];
- tab[j] = piwot;
- if (indeks_dolny < j - 1)
- {
- sortuj_imie(tab, indeks_dolny, j-1 );
- }
- if (j + 1 < indeks_gorny)
- {
- sortuj_imie(tab, j + 1, indeks_gorny);
- }
- return tab;
- }
- vector <student> sortuj_nazwisko(vector <student> tab, int indeks_dolny, int indeks_gorny) { //sortowanie po nazwisku studenta
- int srodek = (indeks_dolny + indeks_gorny) / 2;
- student piwot = tab[indeks_gorny];
- swap(piwot, tab[srodek]);
- int j = indeks_dolny;
- student zm;
- for (int i = indeks_dolny; i < indeks_gorny; i++)
- {
- zm = tab[i];
- if (zm.nazwisko < piwot.nazwisko) // nazwisko studenta
- {
- swap(tab[i], tab[j]);
- j++;
- }
- }
- tab[indeks_gorny] = tab[j];
- tab[j] = piwot;
- if (indeks_dolny < j - 1)
- {
- sortuj_nazwisko(tab, indeks_dolny, j - 1);
- }
- if (j + 1 < indeks_gorny)
- {
- sortuj_nazwisko(tab, j + 1, indeks_gorny);
- }
- return tab;
- }
- void wyswietl(vector <student> tab)
- {
- for (int i = 0; i < tab.size(); i++)
- {
- cout << tab[i].imie << endl;
- }
- }
- void wyswietl(vector <osoba> tab)
- {
- for (int i = 0; i < tab.size(); i++)
- {
- cout << tab[i].imie << endl;
- }
- }
- student zmnienna ;
- int main()
- {
- int opcja1, wielkosc;
- while (1)
- {
- menu();
- switch (opcja)
- {
- case 27: //wyjscie
- exit(0);
- break;
- case 49: //dodaj osobe
- zmnienna = student(0);
- studenci->push_back(zmnienna);
- osoby->push_back(zmnienna);
- break;
- case 50: //wyswietl liste wszystkich
- wyswietl(*osoby);
- system("pause");
- break;
- case 51: //sortuj studentow
- submenu1();
- switch (opcja2) {
- case 49: { //po imieniu
- *studenci = sortuj_imie(*studenci, 0, studenci->size() - 1);
- *studenci = sortuj_imie(*studenci, 0, studenci->size() - 1);
- wyswietl(*studenci);
- system("pause");
- }
- break;
- case 50: //po nazwisku
- *studenci = sortuj_nazwisko(*studenci, 0, studenci->size() - 1);
- *studenci = sortuj_nazwisko(*studenci, 0, studenci->size() - 1);
- wyswietl(*studenci);
- system("pause");
- break;
- default: {}break;
- break;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement