Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <string>
- #include <string.h>
- using namespace std;
- class Person
- {
- private:
- static int m_count;
- string m_name;
- int m_age;
- bool m_isMale;
- public:
- Person();
- Person(string name, int age, bool isMale);
- virtual ~Person();
- void SetName(string name);
- void SetAge(int age);
- void SetSex(bool isMale);
- virtual void GetAll() const;
- };
- int Person::m_count=0;
- class Player:public Person
- {
- private:
- int m_goals;
- public:
- Player();
- Player(string name, int age, bool isMale, int goals);
- ~Player();
- virtual void GetAll() const;
- };
- Person::Person()
- {
- m_count++;
- cout << "vytvoren objekt s cislem: " <<m_count << endl;
- m_name='\0';
- m_age=0;
- m_isMale=true;
- }
- Person::Person(string name, int age, bool isMale)
- {
- m_count++;
- cout << "vytvoren objekt s cislem: " <<m_count << endl;
- m_name=name;
- m_age=age;
- m_isMale=isMale;
- }
- Person::~Person()
- {
- }
- void Person::SetName(string name)
- {
- m_name=name;
- }
- void Person::SetAge(int age)
- {
- m_age=age;
- }
- void Person::SetSex(bool isMale)
- {
- m_isMale=isMale;
- }
- void Person::GetAll()const
- {
- cout << "name: " << m_name << endl;
- cout << "age: " << m_age << endl;
- cout << "sex: ";
- if (m_isMale==true)
- {
- cout << "male"<< endl;
- }
- else
- {
- cout << "female"<<endl;
- }
- }
- Player::Player() : Person()
- {
- m_goals=0;
- }
- Player::Player(string name, int age, bool isMale,int goals) : Person(name, age, isMale)
- {
- m_goals=goals;
- }
- Player::~Player()
- {
- }
- void Player::GetAll()const
- {
- Person::GetAll();
- cout << "goals: " << m_goals << endl;
- }
- int main()
- {
- Person a;
- a.GetAll();
- Person b("Mocek",20,true);
- b.GetAll();
- Player c;
- c.GetAll();
- Player d("Kloudova",19, false, 5);
- d.GetAll();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment