SHARE
TWEET

Untitled

a guest Mar 26th, 2020 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <cstring>
  4. #include <time.h>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. class Skier
  10. {
  11. private:
  12.     char name[50];
  13.     int jersey;
  14.     double gate[50];
  15. public:
  16.     Skier();
  17.     Skier(char *name);
  18.     double total();
  19.     void info();
  20. };
  21. Skier::Skier()
  22. {
  23. }
  24.  
  25. Skier::Skier (char *name)
  26. {
  27.     strcpy(this->name,name);
  28.     this->jersey = rand()%99+1;
  29.     for(int i=0;i<50;i++)
  30.     {
  31.     this-> gate[i]=((rand())%299+1)/100;
  32.     }
  33. }
  34.  
  35. void Skier::info()
  36. {
  37.     cout<<"Skier jersey: "<< jersey << " name: " << name <<  " time: " << total() <<endl;
  38. }
  39.  
  40. double Skier::total()
  41. {
  42.  
  43.     double time=0;
  44.     for(int i=0;i<50;i++)
  45.     {
  46.         time+=gate[i];
  47.     }
  48.         return time;
  49. }
  50.  
  51. int main()
  52. {
  53.     srand(time (0));
  54.  
  55.     Skier *s;
  56.     s = new Skier[10];
  57.     char name[50];
  58.     float least=100;
  59.     int num;
  60.     for(int i=0;i<10;i++)
  61.     {
  62.         cout << "Enter the names of skier #: "<<i<<": ";
  63.         cin>>name;
  64.         s[i] = Skier(name);
  65.     }
  66.     cout << "\nResults:" << endl;
  67.     for(int i=0;i<10;i++)
  68.     {
  69.         if(s[i].total() < least)
  70.         {
  71.             least = s[i].total();
  72.             num=i;
  73.         }
  74.         s[i].info();
  75.     }
  76.  
  77. cout << "\nAnd the winner is: " << endl;
  78. s[num].info();
  79. delete []s;
  80. return 0;
  81. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top