Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <time.h>
- #include <iomanip>
- #include <string>
- using namespace std;
- int a, b, pom_semestr, pom_ocena;
- float pom_max;
- struct Student
- {
- string imie, nazwisko;
- unsigned long long indeks, pesel;
- vector<float> oceny;
- float max_semestr;
- };
- float random(float min, float max)
- {
- float range = (max - min);
- float div = RAND_MAX / range;
- return min + (rand() / div);
- }
- bool pom_nazwisko(const Student &a, const Student &b)
- {
- return a.nazwisko < b.nazwisko;
- }
- bool pom_imie(const Student &a, const Student &b)
- {
- return a.imie < b.imie;
- }
- bool pom_pesel(const Student &a, const Student &b)
- {
- return a.pesel < b.pesel;
- }
- bool pom_indeks(const Student &a, const Student &b)
- {
- return a.indeks < b.indeks;
- }
- bool pom_max_semestr(const Student &a, const Student &b)
- {
- return a.max_semestr > b.max_semestr;
- }
- int main()
- {
- srand(time(NULL));
- cout << "Podaj liczbe studentow: ";
- cin >> a;
- cout << endl;
- vector<Student> tab(a);
- for(int i = 0; i < a; i++)
- {
- cout << "Podaj imie studenta: ";
- cin >> tab[i].imie;
- cout << endl;
- cout << "Podaj nazwisko studenta: ";
- cin >> tab[i].nazwisko;
- cout << endl;
- cout << "Podaj numer indeksu: ";
- cin >> tab[i].indeks;
- cout << endl;
- cout << "Podaj pesel: ";
- cin >> tab[i].pesel;
- cout << endl;
- cout << "Podaj liczbe semestrow: ";
- cin >> pom_semestr;
- cout << endl;
- for(int j = 0; j < pom_semestr; j++)
- tab[i].oceny.push_back(random(2.0, 4.0));
- pom_max = tab[i].oceny[0];
- for(int j = 1; j < pom_semestr; j++)
- {
- if(pom_max < tab[i].oceny[j])
- pom_max = tab[i].oceny[j];
- }
- tab[i].max_semestr = pom_max;
- }
- while(0==0)
- {
- cout << "Wybierz metode sortowania: " << endl;
- cout << "1. Po nazwisku" << endl;
- cout << "2. Po imieniu" << endl;
- cout << "3. Po indeksie" << endl;
- cout << "4. Po peselu" << endl;
- cout << "5. Po maksymalnej sredniej" << endl;
- cin >> b;
- cout << endl;
- switch(b)
- {
- case 1:
- sort(tab.begin(), tab.end(), pom_nazwisko);
- break;
- case 2:
- sort(tab.begin(), tab.end(), pom_imie);
- break;
- case 3:
- sort(tab.begin(), tab.end(), pom_indeks);
- break;
- case 4:
- sort(tab.begin(), tab.end(), pom_pesel);
- break;
- case 5:
- sort(tab.begin(), tab.end(), pom_max_semestr);
- break;
- }
- for(int i = 0; i < a; i++)
- {
- cout << "Imie studenta: " << tab[i].imie << endl;
- cout << "Nazwisko student: " << tab[i].nazwisko << endl;
- cout << "Indeks studenta: " << tab[i].indeks << endl;
- cout << "Pesel student: " << tab[i].pesel << endl;
- cout << "Oceny: ";
- for(int j = 0; j < pom_semestr; j++)
- {
- cout << setprecision(3);
- cout << tab[i].oceny[j] << " ";
- }
- cout << endl << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement