Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Mając dane N elementów, z których każdy zawiera następujące informacje:
- • nazwisko studenta,
- • średnią ocen studenta.
- Napisz funkcję wyszukującą wszystkich studentów ze średnią powyżej podane wartości (średnia
- podawana z klawiatury). Implementacja optymalna.
- */
- #include<iostream>
- #include <string>
- #include<iomanip>
- using namespace std;
- int const size =10;
- struct student
- {
- string name;
- double average;
- student()
- {
- }
- student(string name_,double average_)
- {
- name = name_;
- average = average_;
- }
- };
- void show(student *tab)
- {
- for (int i =0;i<size;i++)
- {
- cout<<setw(5)<<tab[i].average<<" "<<tab[i].name<<endl;
- }
- cout<<endl;
- }
- void search(student *tab)
- {
- double x_srednia;
- cout<<"Podaj srednia "<<endl;
- cin>>x_srednia;
- cout<<"Osoby z wyzsza srednia niz "<<x_srednia<<" to:"<<endl;
- for(int i = 0; i<size ; i++)
- {
- if(x_srednia<tab[i].average)
- cout<<setw(4)<<tab[i].average<<" "<<tab[i].name<<endl;
- }
- }
- int main()
- {
- struct student tab[size];
- struct student person1("Katowicki",3.0);
- struct student person2("Nyski",4.5);
- struct student person3("Augustowski",4.5);
- struct student person4("Krakowski",5.0);
- struct student person5("Opolski",3.5);
- struct student person6("Wroclawski",4.0);
- struct student person7("Poznanski",4.0);
- struct student person8("Krakowski",4.5);
- struct student person9("Radomski",3.5);
- struct student person10("Katowicki",4.0);
- tab[0] = person1;
- tab[1] = person2;
- tab[2] = person3;
- tab[3] = person4;
- tab[4] = person5;
- tab[5] = person6;
- tab[6] = person7;
- tab[7] = person8;
- tab[8] = person9;
- tab[9] = person10;
- show(tab);
- search(tab);
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement