Advertisement
Guest User

Zadanie

a guest
Dec 7th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <time.h>
  5. #include <iomanip>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10. int a, b, pom_semestr, pom_ocena;
  11. float pom_max;
  12.  
  13. struct Student
  14.     {
  15.         string imie, nazwisko;
  16.         unsigned long long indeks, pesel;
  17.         vector<float> oceny;
  18.         float max_semestr;
  19.     };
  20.  
  21. float random(float min, float max)
  22. {
  23.     float range = (max - min);
  24.     float div = RAND_MAX / range;
  25.    
  26.     return min + (rand() / div);
  27. }
  28.    
  29. bool pom_nazwisko(const Student &a, const Student &b)
  30. {
  31.    return a.nazwisko < b.nazwisko;
  32. }
  33.  
  34. bool pom_imie(const Student &a, const Student &b)
  35. {
  36.     return a.imie < b.imie;    
  37. }
  38.  
  39. bool pom_pesel(const Student &a, const Student &b)
  40. {
  41.     return a.pesel < b.pesel;
  42. }
  43.  
  44. bool pom_indeks(const Student &a, const Student &b)
  45. {
  46.     return a.indeks < b.indeks;
  47. }
  48.  
  49. bool pom_max_semestr(const Student &a, const Student &b)
  50. {
  51.     return a.max_semestr > b.max_semestr;
  52. }
  53.  
  54. int main()
  55. {  
  56.     srand(time(NULL));
  57.    
  58.     cout << "Podaj liczbe studentow: ";
  59.     cin >> a;
  60.     cout << endl;
  61.    
  62.     vector<Student> tab(a);
  63.    
  64.     for(int i = 0; i < a; i++)
  65.     {
  66.         cout << "Podaj imie studenta: ";
  67.         cin >> tab[i].imie;
  68.         cout << endl;
  69.        
  70.         cout << "Podaj nazwisko studenta: ";
  71.         cin >> tab[i].nazwisko;
  72.         cout << endl;
  73.  
  74.         cout << "Podaj numer indeksu: ";
  75.         cin >> tab[i].indeks;
  76.         cout << endl;
  77.        
  78.         cout << "Podaj pesel: ";
  79.         cin >> tab[i].pesel;
  80.         cout << endl;
  81.        
  82.         cout << "Podaj liczbe semestrow: ";
  83.         cin >> pom_semestr;
  84.         cout << endl;
  85.        
  86.         for(int j = 0; j < pom_semestr; j++)
  87.             tab[i].oceny.push_back(random(2.0, 4.0));
  88.        
  89.         pom_max = tab[i].oceny[0];
  90.        
  91.         for(int j = 1; j < pom_semestr; j++)
  92.            {
  93.                 if(pom_max < tab[i].oceny[j])
  94.                    pom_max = tab[i].oceny[j];
  95.            }
  96.        
  97.         tab[i].max_semestr = pom_max;
  98.        
  99.       }
  100.          while(0==0)
  101.         {
  102.          cout << "Wybierz metode sortowania: " << endl;
  103.          cout << "1. Po nazwisku" << endl;
  104.          cout << "2. Po imieniu" << endl;
  105.          cout << "3. Po indeksie" << endl;
  106.          cout << "4. Po peselu" << endl;
  107.          cout << "5. Po maksymalnej sredniej" << endl;
  108.          cin >> b;
  109.          cout << endl;
  110.    
  111.          switch(b)
  112.          {
  113.              case 1:
  114.                     sort(tab.begin(), tab.end(), pom_nazwisko);
  115.                     break;
  116.              case 2:
  117.                     sort(tab.begin(), tab.end(), pom_imie);
  118.                     break;
  119.              case 3:
  120.                     sort(tab.begin(), tab.end(), pom_indeks);
  121.                     break;
  122.              case 4:
  123.                     sort(tab.begin(), tab.end(), pom_pesel);
  124.                     break;
  125.              case 5:
  126.                     sort(tab.begin(), tab.end(), pom_max_semestr);
  127.                     break;
  128.          }
  129.        
  130.         for(int i = 0; i < a; i++)
  131.            {
  132.                 cout << "Imie studenta: " << tab[i].imie << endl;
  133.                 cout << "Nazwisko student: " << tab[i].nazwisko << endl;
  134.                 cout << "Indeks studenta: " << tab[i].indeks << endl;
  135.                 cout << "Pesel student: " << tab[i].pesel << endl;
  136.                 cout << "Oceny: ";
  137.                 for(int j = 0; j < pom_semestr; j++)
  138.                    {
  139.                         cout << setprecision(3);
  140.                         cout << tab[i].oceny[j] << " ";
  141.                    }
  142.                
  143.                 cout << endl << endl;
  144.            }
  145.        
  146.     }
  147.    
  148.    return 0;
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement