Advertisement
kirill_76rus

university_2

Sep 18th, 2019
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<vector>
  4. #include<algorithm>
  5. using namespace std;
  6. class student{
  7. public:
  8.     string name;
  9.     string group;
  10.     vector <int> points;
  11.     student();
  12.     student(string name_new, string group_new, vector <int> news){
  13.         name=name_new;
  14.         group=group_new;
  15.         points=news;
  16.     }
  17.     void enter_marks(int tmp){
  18.         points.push_back(tmp);
  19.     }
  20.     double average(){
  21.         int sum=0;
  22.         int size=points.size();
  23.         for(auto&s:points){
  24.             sum=+s;
  25.         }
  26.         double avr=(sum/size);
  27.         return avr;
  28.     }
  29.     void print(){
  30.         cout<<"name: "<<name<<"\n"<<"group: "<<group<<"\n";
  31.         cout<<"points ";
  32.         for(auto& s:points){
  33.             cout<<s<<" ";
  34.         }
  35.         cout<<endl;
  36.     }
  37.     void sorted(){
  38.         sort(begin(points), end(points));
  39.     }
  40.     void maximum(){
  41.     int max=0;
  42.     for(auto s:points){
  43.         if (s>max){
  44.             max=s;
  45.         }
  46.     }
  47.     cout<<"maximum points: "<<max<<endl;
  48.     }
  49.     void count_maximum(){
  50.         int max=0;
  51.             for(auto s:points){
  52.                 if (s>max){
  53.                     max=s;
  54.                 }
  55.             }
  56.             int counter=0;
  57.         for(auto j:points){
  58.             if(max==j){
  59.                 ++counter;
  60.             }
  61.         }
  62.         cout<<"number of maximum points: "<<counter<<endl;
  63.     }
  64. };
  65. int main(){
  66.     vector <int> tmp={5,5,3,4};
  67.     student first={"name","surname",tmp};
  68.     first.print();
  69.     student second={"name_2","surname_2",tmp};
  70.     second.print();
  71.     first.sorted();
  72.     first.print();
  73.     first.enter_marks(3);
  74.     first.print();
  75.     first.maximum();
  76.     first.count_maximum();
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement