Sofe1204

Untitled

Mar 22nd, 2022 (edited)
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <time.h>      
  5.  
  6. using namespace std;
  7.  
  8. class Jumper {
  9.     private:
  10.        char name[50];
  11.        int jersey;
  12.        double trial[3];
  13.     public:
  14.        Jumper() {}
  15.        
  16.        Jumper(char* name, int jersey, double trial[]) {
  17.           strcpy(this -> name, name);
  18.           this -> jersey = jersey;
  19.           for (int i=0; i<3; i++) {
  20.               (this -> trial)[i] = trial[i];
  21.           }
  22.        }
  23.        
  24.        double total() {
  25.            return trial[0] + trial[1] + trial[2];
  26.        }
  27.        
  28.        void info() {
  29.            cout << "jersey: " << jersey << " name: " << name << " length: " << total();
  30.        }
  31.        
  32. };
  33.  
  34.  
  35. int main()
  36. {
  37.     srand (time(NULL));
  38.    
  39.     Jumper jumpers[10];
  40.    
  41.     for (int i=0; i<10; i++) {
  42.         char* name;
  43.         cin >> name;
  44.         int rndJersey = rand() % 99 + 1;
  45.        
  46.         int trial1 = rand() % (250 - 200 + 1) + 200;
  47.         int trial2 = rand() % (250 - 200 + 1) + 200;
  48.         int trial3 = rand() % (250 - 200 + 1) + 200;
  49.        
  50.         double trial[] = {trial1, trial2, trial3};
  51.         Jumper* j = new Jumper(name, rndJersey, trial);
  52.         jumpers[i] = *j;
  53.         delete j;
  54.     }
  55.    
  56.     for (int i=0; i<10; i++) {
  57.        jumpers[i].info();
  58.     }
  59.    
  60.     double max = -99999;
  61.     int index = -1;
  62.    
  63.     for (int i=0; i<10; i++) {
  64.         max = max < jumpers[i].total() ? jumpers[i].total() : max;  
  65.         index = i;
  66.     }
  67.    
  68.     cout << endl;
  69.    
  70.     cout << "Winner jumper with length: " << max << " info: ";
  71.     jumpers[index].info();
  72.     cout << endl;
  73.  
  74.     return 0;
  75. }
Add Comment
Please, Sign In to add comment