Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class Parent
- {
- int val;
- protected:
- int nums[2]{ 10,20 };
- //int x{10};
- //int y{20};
- int protVal{555};
- public:
- Parent() : val{ 333 } { std::cout << "Parent DEFAULT ctor\n"; }
- Parent(int valP) : val{ valP } { std::cout << "Parent ctor valP\n"; }
- Parent(char symbP) : val{ symbP - 'A'} { std::cout << "Parent ctor symbP\n"; }
- int getVal() const { return val; }
- int getX() const { return nums[0]; }
- int getY() const { return nums[1]; }
- virtual void info() { std::cout << "I'm Parent!\n"; }
- void greeting() { std::cout << "Hello, let me introduce myself, "; info(); }
- ~Parent() { std::cout << "Parent dtor\n"; }
- };
- class Child : public Parent
- {
- // super private:
- // int val;
- protected:
- char symb;
- public:
- Child() : symb {'A' } { std::cout << "Child DEFAULT ctor\n"; }
- Child(char symbP) : Parent{symbP}, symb { symbP } { std::cout << "Child ctor symbP\n"; }
- char getSymb() const { return symb; }
- void childInfo()const
- {
- std::cout << "Child: symb = " <<
- symb << " val = " <<
- getVal() << " protVal = " <<
- protVal << "\n x = " << getX() << " y = " << getY() << '\n';
- }
- void info()
- {
- //std::cout << "Info from Parent - > \n\n"; Parent::info();
- /*std::cout << "Info from Child - > \n\n"; */std::cout << "I'm Child!\n";
- }
- ~Child() { std::cout << "Child dtor\n"; }
- };
- class AParent
- {
- };
- class BParent
- {
- };
- class child : public AParent, public BParent
- {
- };
- class GrandChild : public Child
- {
- bool flag;
- using Child::childInfo;
- public:
- GrandChild(bool flagP) : flag{ flagP } { std::cout << "GrandChild ctor flagP\n"; }
- void grandChildInfo()const { std::cout << "GrandChild: symb = " << symb << " val = " << getVal() << " protVal = " << protVal << '\n'; }
- void info()
- {
- std::cout << "I'm GrandChild!\n";
- }
- ~GrandChild() { std::cout << "GrandChild dtor\n"; }
- };
- class Date
- {
- uint16_t year;
- uint8_t month;
- uint8_t day;
- uint8_t checkMonth(uint8_t monthP)
- {
- if (monthP < 1) return 1;
- if (monthP > 12) return 12;
- return monthP;
- }
- uint8_t checkDay(uint8_t dayP, uint8_t monthP, uint16_t yearP)
- {
- const uint8_t maxDays{ Date::daysInMonth(monthP, yearP) };
- if (dayP < 1) return 1;
- if (dayP > maxDays) return maxDays;
- return dayP;
- }
- public:
- static uint8_t daysInMonth(uint8_t month, uint16_t year)
- {
- return 30 + (((month < 8) and (month % 2 != 0)) or ((month >= 8) and (month % 2 == 0))) + ((month == 2) * (-2) + isLeapYear(year));
- }
- static bool isLeapYear(uint16_t year)
- {
- return year % 400 == 0 or year % 4 == 0 and year % 100 != 0;
- }
- static const uint8_t maxMonth{ 12 };
- Date() : Date(1, 1, 1970) {}
- Date(uint8_t dayP, uint8_t monthP, uint16_t yearP)
- : year{ yearP }, month{ checkMonth(monthP) }, day{ checkDay(dayP,month,yearP) } {}
- Date& setDay(uint8_t dayP) { day = checkDay(dayP, month, year); return *this; }
- Date& setMonth(uint8_t monthP) { month = checkMonth(monthP); day = checkDay(day, month, year); return *this; }
- Date& setYear(uint16_t yearP) { year = yearP; return *this; }
- uint8_t getDay() const { return day; }
- uint8_t getMonth() const { return month; }
- uint16_t getYear() const { return year; }
- Date& print() { std::cout << +day << '.' << +month << '.' << year << '\n'; return *this; }
- };
- class Human
- {
- std::string fname;
- std::string sname;
- uint8_t age;
- uint8_t weight;
- uint8_t height;
- protected:
- Date bDate;
- public:
- Human() : Human("John", "Doe", 39, 42, 150, { 1,1,1981 }) {}
- Human(const std::string& fnameP, const std::string& snameP, uint8_t ageP, uint8_t weightP, uint8_t heightP, const Date& bDateP)
- : fname{ fnameP }, sname{ snameP }, age{ ageP }, weight{ weightP }, height{heightP}, bDate{bDateP}
- { std::cout << "Human constructed\n"; }
- uint8_t getAge()const { return age; }
- Human& setAge(uint8_t ageP) { age = ageP; return *this; }
- ~Human() { std::cout << "Human Destructed\n"; }
- // further Human class implementation..
- };
- class Student : public Human
- {
- std::string uName;
- double avgGrade;
- public:
- // further student impementation
- Date& getStudentBDate() { return bDate; }
- //uint8_t getStudentWeight() { return weight; }
- };
- class Employee : public Human
- {
- std::string orgName;
- float salary;
- uint32_t socialId;
- public:
- // further Employee imp.
- };
- int main()
- {
- // Human h1{};
- // Student s1{};
- // std::cout << "Human" << + h1.getAge() << '\n';
- // std::cout << "Student" << + s1.getAge() << '\n';
- // std::cout << "Student "; s1.getStudentBDate().print();
- //return 0;
- //Parent parent;
- //parent.greeting();
- //parent.info();
- //Child child;
- //child.greeting();
- //child.info();
- //child.childInfo();
- //child.childInfo();
- GrandChild gChild{true};
- gChild.greeting();
- //gChild.info();
- //gChild.childInfo();
- //gChild.grandChildInfo();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement