Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstring>
- using std::cout;
- using std::endl;
- using std::cin;
- class Card
- {
- enum{ red, white, black, green };
- enum{ pika, buba, tref, cherv };
- int suit;
- int back;
- public:
- Card() { srand((unsigned)time(NULL)); suit = rand() % 4 + 1; back = rand() % 4 + 1; };
- Card(int s, int b) { suit = s; back = b; };
- Card Draw()const { return *this; };
- void Show()const { cout << "Suit: " << suit << endl << "Back: " << back << endl; }
- };
- class Person
- {
- char * name;
- char * second_name;
- protected:
- virtual void Data()const = 0;
- public:
- Person();
- Person(char * nm, char * scnd_nm = "none");
- Person(const Person & obj);
- Person & operator=(const Person & obj);
- virtual void Show()const = 0;
- virtual ~Person() = 0;
- };
- class Gunslinger : virtual /*public*/ Person
- {
- double time;
- int notches;
- protected:
- void Data()const;
- public:
- Gunslinger();
- Gunslinger(double tm, int ntchs, char * nm = "none", char * scnd_nm = "none");
- Gunslinger(double tm , int ntchs, const Person & obj);
- Gunslinger(const Gunslinger & obj);
- Gunslinger & operator=(const Gunslinger & obj);
- Gunslinger & oprtr(const Gunslinger & obj);
- double Draw()const { cout << "Time: "; return time; }
- void Show()const;
- virtual ~Gunslinger(){};
- };
- class PokerPlayer : virtual /*public*/ Person
- {
- Card card;
- protected:
- void Data()const;
- public:
- PokerPlayer();
- PokerPlayer(char * nm, char * scnd_nm = "none");
- PokerPlayer(const Person & obj);
- PokerPlayer(const PokerPlayer & obj);
- PokerPlayer & operator=(const PokerPlayer & obj);
- PokerPlayer & oprtr(const PokerPlayer & obj);
- Card Draw()const { card.Show(); return card; }
- void Show()const{ Person::Show(); card.Show(); };
- virtual ~PokerPlayer(){};
- };
- class BadDude : public Gunslinger, public PokerPlayer
- {
- protected:
- void Data()const{};
- public:
- BadDude();
- BadDude(double tm, int ntchs, char * nm = "none", char * scnd_nm = "none");
- BadDude(double tm, int ntchs, const ::Person & obj);
- BadDude(const BadDude & obj);
- BadDude & operator=(const BadDude & obj);
- Card Cdraw()const { return PokerPlayer::Draw(); }
- double Gdraw()const { return Gunslinger::Draw(); }
- void Show()const;
- virtual ~BadDude(){};
- };
- /////////////////////////////////////////////////////////////SOURCE FILE////////////////////////////////////////////////////
- #include "person.h"
- void Person::Data()const
- {
- cout << "Name: " << name << "\n";
- cout << "Second name: " << second_name << "\n";
- }
- Person::Person()
- {
- name = new char[strlen("none") + 1];
- second_name = new char[strlen("none") + 1];
- strcpy_s(name, strlen("none") + 1 * sizeof(char), "none");
- strcpy_s(second_name, strlen("none") + 1 * sizeof(char), "none");
- }
- Person::Person(char * nm, char * scnd_nm)
- {
- name = new char[strlen(nm) + 1];
- second_name = new char[strlen(scnd_nm) + 1];
- strcpy_s(name, strlen(nm) + 1 * sizeof(char), nm);
- strcpy_s(second_name, strlen(scnd_nm) + 1 * sizeof(char), scnd_nm);
- }
- Person::Person(const Person & obj)
- {
- name = new char[strlen(obj.name) + 1];
- second_name = new char[strlen(obj.second_name) + 1];
- strcpy_s(name, strlen(obj.name) + 1 * sizeof(char), obj.name);
- strcpy_s(second_name, strlen(obj.second_name) + 1 * sizeof(char), obj.second_name);
- }
- Person & Person::operator=(const Person & obj)
- {
- if (this == & obj)
- return *this;
- delete[]name;
- delete[]second_name;
- name = new char[strlen(obj.name) + 1];
- second_name = new char[strlen(obj.second_name) + 1];
- strcpy_s(name, strlen(obj.name) + 1 * sizeof(char), obj.name);
- strcpy_s(second_name, strlen(obj.second_name) + 1 * sizeof(char), obj.second_name);
- return *this;
- }
- void Person::Show()const
- {
- cout << "Name: " << name << "\n";
- cout << "Second name: " << second_name << "\n";
- }
- Person::~Person()
- {
- delete[]name;
- delete[]second_name;
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////
- void Gunslinger::Data()const
- {
- cout << "Time: " << time << "\n";
- cout << "Notches: " << notches << "\n";
- }
- Gunslinger::Gunslinger() : Person()
- {
- time = 0;
- notches = 0;
- }
- Gunslinger::Gunslinger(double tm, int ntchs, char * nm, char * scnd_nm) : Person(nm, scnd_nm)
- {
- time = tm;
- notches = ntchs;
- }
- Gunslinger::Gunslinger(double tm, int ntchs, const Person & obj) : Person(obj)
- {
- time = tm;
- notches = ntchs;
- }
- Gunslinger::Gunslinger(const Gunslinger & obj) : Person(obj)
- {
- time = obj.time;
- notches = obj.notches;
- }
- Gunslinger & Gunslinger::operator=(const Gunslinger & obj)
- {
- if (this == &obj)
- return *this;
- Person::operator=(obj);
- time = obj.time;
- notches = obj.notches;
- return *this;
- }
- Gunslinger & Gunslinger::oprtr(const Gunslinger & obj)
- {
- if (this == &obj)
- return *this;
- time = obj.time;
- notches = obj.notches;
- return *this;
- }
- void Gunslinger::Show()const
- {
- Person::Data();
- cout << "Time: " << time << "\n";
- cout << "Notches: " << notches << "\n";
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////
- void PokerPlayer::Data()const
- {
- card.Show();
- }
- PokerPlayer::PokerPlayer() : Person(), card(){}
- PokerPlayer::PokerPlayer(char * nm, char * scnd_nm) : Person(nm, scnd_nm) {}
- PokerPlayer::PokerPlayer(const Person & obj) : Person(obj), card() {}
- PokerPlayer::PokerPlayer(const PokerPlayer & obj) : Person(obj)
- {
- card = obj.card;
- }
- PokerPlayer & PokerPlayer::operator=(const PokerPlayer & obj)
- {
- if (this == &obj)
- return *this;
- Person::operator=(obj);
- card = obj.card;
- return *this;
- }
- PokerPlayer & PokerPlayer::oprtr(const PokerPlayer & obj)
- {
- if (this == &obj)
- return *this;
- card = obj.card;
- return *this;
- }
- ///////////////////////////////////////////////////////////////////////////////////////////
- BadDude::BadDude() : Person::Person(), Gunslinger(), PokerPlayer() {}
- BadDude::BadDude(double tm, int ntchs, char * nm, char * scnd_nm)
- : Person::Person(nm, scnd_nm), Gunslinger(tm, ntchs, nm, scnd_nm), PokerPlayer(nm, scnd_nm) {}
- BadDude::BadDude(double tm, int ntchs, const ::Person & obj)
- : Person::Person(obj), Gunslinger(tm, ntchs, obj), PokerPlayer(obj) {}
- BadDude::BadDude(const BadDude & obj) : Person::Person(obj), PokerPlayer(obj), Gunslinger(obj) {}
- BadDude & BadDude::operator=(const BadDude & obj)
- {
- if (this == &obj)
- return *this;
- Person::operator=(obj);
- PokerPlayer::oprtr(obj);
- Gunslinger::oprtr(obj);
- return *this;
- }
- void BadDude::Show()const
- {
- Person::Data();
- Gunslinger::Data();
- PokerPlayer::Data();
- }
- /////////////////////////////////////////////////////////main file////////////////////////////////////////////////////////
- #include "person.h"
- #include "vld.h"
- void main()
- {
- const int size=3;
- Person *data[size];
- Gunslinger gun;
- BadDude obj2(11.2, 23, "Ricky", "Rud");
- BadDude obj1 = obj2;
- for (int i = 0; i < size;)
- {
- int choose = 0;
- cout << "Enter 1: gun, 2: poker, 3:baddude => ";
- cin >> choose;
- switch (choose)
- {
- case 1:
- data[i] = new Gunslinger(25.5, 15, "Jonh", "Travolta");
- i++;
- break;
- case 2:
- data[i] = new PokerPlayer("Jimmi", "Bgood");
- i++;
- break;
- case 3:
- data[i] = new BadDude(6.6, 2, "Billy", "Bobby");
- i++;
- break;
- }
- }
- //gun = (Gunslinger)*data[0];
- gun.Show();
- cout << "!!!!!!!!!!!!!!!!!!!!!!!\n";
- /*obj1 = obj2;
- obj2.Show();
- obj1.Show();*/
- for (int i = 0; i < size; i++)
- {
- data[i]->Show();
- cout << "!!!!!!!!!!!!!!!!!!!!!!!\n";
- }
- for (int i = 0; i < size; i++)
- delete data[i];
- cout << "Bye\n";
- }
Add Comment
Please, Sign In to add comment