2017년 4월 6일 목요일

[C++] Source codes we did on April 6

Actually, it is not easy to understand the object-oriented concept at the first time.
Next week, let me review what we did today.
Have a nice weekend!!












#include <iostream>
#include <string>

using namespace std;

// Golobal !!
class Human
{
private:
    // Data attributes: States
    int    Age;
    string Name;
    string DOB;
    string POB; // place of birth

public:
    // Constructor
    /*
    Human() {
        cout << " I am alive not zombie!!" << endl;
    }
    */
    // Default construct for Age
    Human(string SetName = "BaBo" , int SetAge = 25) {
        Name = SetName;
        Age = SetAge;
        cout << " I am alive and my name is " << Name << endl;
        cout << " I am " << Age << " years old" << endl;
    }

    /*
    Human(string SetName) {
        Name = SetName;
        cout << " I am alive and my name is " << Name << endl;
    }
    */
    // Destructor
    ~Human() {
        cout << "I am dead and zombie !!" << endl;
    }

    // Setter
    void SetDOB(string HumanDOB)
    {
        DOB = HumanDOB;
    }

    // Getter
    string GetDOB()
    {
        return DOB;
    }
    // Behaviors
    void Talk(string TextToTalk)
    {
        cout << "Message: + " << TextToTalk << endl;
    }

    void IntroduceSelf()
    {
        cout << "My name is " << Name <<endl;
    }
};

int main()
{
    cout << "Hello world!" << endl;

    Human Tom;

    Tom.Talk("Ha Ha");

    Tom.SetDOB("2017-04-06");
    cout << Tom.GetDOB() << endl;

    Human* pTom = new Human();
    //(*pTom).SetDOB("2016-04-06");
    pTom->SetDOB("2016-04-05");
    // cout << (*pTom).GetDOB() << endl;
    cout << pTom->GetDOB() << endl;

    pTom = &Tom;
    cout << pTom->GetDOB() << endl;

    Human Jane("Jane");
    Jane.IntroduceSelf();

    delete pTom;

    return 0;
}