SHARE
TWEET

Untitled

a guest Mar 26th, 2020 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<cstring>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. class Runner{
  7. private:
  8.     char *name;
  9.     int jersey; //random jerzi random sekundi
  10.     int sec;
  11.  
  12. public:
  13.     Runner(const char *name="",int sec=0, int jersey=0)
  14.     {
  15.         this->name=new char[strlen(name)+1];
  16.         strcpy(this->name,name);
  17.         this->sec=sec;
  18.         this->jersey=jersey;
  19.     }
  20.     Runner(const Runner &r)
  21.     {
  22.         this->name=new char[strlen(r.name)+1];
  23.         strcpy(this->name,r.name);
  24.         this->sec=r.sec;
  25.         this->jersey=r.jersey;
  26.     }
  27.  
  28.     ~Runner(){
  29.         delete [] name;
  30.     }
  31.  
  32.     friend ostream& operator<<(ostream &out,const Runner &r)
  33.     {
  34.         out<<"Here are the results:"<<endl;c
  35.         out<<"Runner #"<<r.jersey<<". "<<r.name<<" "<<"has run 100 meters in "<<r.sec<<" "<<"seconds."<<endl;
  36.         return out;
  37.     }
  38. };
  39.  
  40.  
  41. int main() {
  42.  
  43. int n=7;
  44. char name[50];
  45. int seconds;
  46. int jersey;
  47. for (int i=0; i < n; ++i) {
  48.   cout<<"Enter the name of runner #"<<i;
  49.   cin >> name;
  50.   seconds= rand() % 10;
  51.   jersey= rand() % 50;
  52.   Runner r = Runner(name,seconds,jersey);
  53.   cout << Runner();
  54. }
  55.  
  56.  
  57.  
  58. }
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