Advertisement
Brollylssj

Napisz funkcję wyszukującą wszystkich studentów ze średnią

Nov 26th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. /*Mając dane N elementów, z których każdy zawiera następujące informacje:
  2. • nazwisko studenta,
  3. • średnią ocen studenta.
  4. Napisz funkcję wyszukującą wszystkich studentów ze średnią powyżej podane wartości (średnia
  5. podawana z klawiatury). Implementacja optymalna.
  6. */
  7.  
  8.  
  9. #include<iostream>
  10. #include <string>
  11. #include<iomanip>
  12.  
  13. using namespace std;
  14. int const size =10;
  15. struct student
  16. {
  17.     string name;
  18.     double average;
  19.  
  20.  
  21.     student()
  22.     {
  23.  
  24.     }
  25.  
  26.  
  27.     student(string name_,double average_)
  28.     {
  29.        name = name_;
  30.        average = average_;
  31.     }
  32. };
  33.  
  34.  
  35. void show(student *tab)
  36. {
  37.     for (int i =0;i<size;i++)
  38.     {
  39.         cout<<setw(5)<<tab[i].average<<" "<<tab[i].name<<endl;
  40.  
  41.     }
  42.  
  43.     cout<<endl;
  44. }
  45.  
  46. void search(student *tab)
  47. {
  48.     double x_srednia;
  49.     cout<<"Podaj srednia "<<endl;
  50.     cin>>x_srednia;
  51.  
  52.     cout<<"Osoby z wyzsza srednia niz "<<x_srednia<<" to:"<<endl;
  53.  
  54.     for(int i = 0; i<size ; i++)
  55.     {
  56.         if(x_srednia<tab[i].average)
  57.             cout<<setw(4)<<tab[i].average<<" "<<tab[i].name<<endl;
  58.  
  59.  
  60.     }
  61.  
  62. }
  63.  
  64.  
  65.  
  66. int main()
  67. {
  68.     struct student tab[size];
  69.  
  70.     struct student person1("Katowicki",3.0);
  71.     struct student person2("Nyski",4.5);
  72.     struct student person3("Augustowski",4.5);
  73.     struct student person4("Krakowski",5.0);
  74.     struct student person5("Opolski",3.5);
  75.     struct student person6("Wroclawski",4.0);
  76.     struct student person7("Poznanski",4.0);
  77.     struct student person8("Krakowski",4.5);
  78.     struct student person9("Radomski",3.5);
  79.     struct student person10("Katowicki",4.0);
  80.    
  81.  
  82.     tab[0] = person1;
  83.     tab[1] = person2;
  84.     tab[2] = person3;
  85.     tab[3] = person4;
  86.     tab[4] = person5;
  87.     tab[5] = person6;
  88.     tab[6] = person7;
  89.     tab[7] = person8;
  90.     tab[8] = person9;
  91.     tab[9] = person10;
  92.  
  93.     show(tab);
  94.  
  95.     search(tab);
  96.  
  97.  
  98.     system("PAUSE");
  99.     return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement