Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- #include <cstdlib>
- using namespace std;
- class Runner{
- private:
- char *name;
- int jersey; //random jerzi random sekundi
- int sec;
- public:
- Runner(const char *name="",int sec=0, int jersey=0)
- {
- this->name=new char[strlen(name)+1];
- strcpy(this->name,name);
- this->sec=sec;
- this->jersey=jersey;
- }
- Runner(const Runner &r)
- {
- this->name=new char[strlen(r.name)+1];
- strcpy(this->name,r.name);
- this->sec=r.sec;
- this->jersey=r.jersey;
- }
- ~Runner(){
- delete [] name;
- }
- friend ostream& operator<<(ostream &out,const Runner &r)
- {
- out<<"Here are the results:"<<endl;
- out<<"Runner #"<<r.jersey<<". "<<r.name<<" "<<"has run 100 meters in "<<r.sec<<" "<<"seconds."<<endl;
- return out;
- }
- };
- int main() {
- int n=7;
- char name[50];
- int seconds;
- int jersey;
- for (int i=0; i < n; ++i) {
- cout<<"Enter the name of runner #"<<i;
- cin >> name;
- seconds= rand() % 10;
- jersey= rand() % 50;
- Runner r = Runner(name,seconds,jersey);
- }
- cout << Runner();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement