/*
    CRerference1.cpp
*/

#include <iostream>

using std::cout;
using std::endl;

class Person
{
public :
    void Sleep() const
    {
        cout<<"Sleep"<<endl;
    }
};

class Student : public Person
{
public :
    void Study() const
    {
        cout<<"Study"<<endl;
    }
};

class PartTimeStd : public Student
{
public :
    void Work() const
    {
        cout<<"Work"<<endl;
    }
};

int main(void)
{
    PartTimeStd p;
    Student& ref1 = p;
    Person&  ref2 = p;

    p.Sleep();
    ref1.Sleep();
    ref2.Sleep();

    return 0;
}

 

반응형

'C, C++, Java' 카테고리의 다른 글

Overriding1.cpp  (0) 2014.05.02
CReference2.cpp  (0) 2014.05.02
CPointer2.cpp  (0) 2014.05.02
EmployeeManager3.cpp  (0) 2014.05.02
Person.cpp  (0) 2014.04.30

 결국 뭐 좀 해볼려고 하면, 결국에는 포인터로 귀결이 되는구나.

 

/*
    CPointer2.cpp
*/

#include <iostream>
#include <string.h>

using std::cout;
using std::endl;

class Person
{
public :
    void Sleep()
    {
        cout<<"Sleep"<<endl;
    }
};

class Student : public Peson
{
public :
    void Study()
    {
        cout<<"Study"<<endl;
    }
};

class PartTimeStd : public Student
{
public :
    void Work()
    {
        cout<<"Work"<<endl;
    }
};

int main(void)
{
    Person* p3 = new PartTimeStd;

    p3->Sleep();

    return 0;
}

반응형

'C, C++, Java' 카테고리의 다른 글

CReference2.cpp  (0) 2014.05.02
P304.cpp  (0) 2014.05.02
EmployeeManager3.cpp  (0) 2014.05.02
Person.cpp  (0) 2014.04.30
P256.cpp  (0) 2014.04.30

/*
 EmployeeManager3.cpp
*/

#include <iostream>
#include <string.h>

using std::cout;
using std::endl;

/*=======================================*/
/*           */
/*    Employee Class    */
/*           */
/*=======================================*/

class Employee
{
protected :
    char name[20];

public :
    Employee(const char* _name);
    const char* GetName() const;
};

Employee::Employee(const char* _name)
{
    strcpy(name, _name);
}

const char* Employee::GetName() const
{
    return name;
}


/*=======================================*/
/*           */
/*        Permanent Class           */
/*           */
/*=======================================*/

class Permanent : public Employee
{
private :
    int salary;

public :
    Permanent(const char* _name, int sal);
    int GetPay() const;
};

Permanent::Permanent(const char* _name, int sal) : Employee(_name)
{
    salary = sal;
}

int Permanent::GetPay() const
{
    return salary;
}

/*=======================================*/
/*           */
/*        Temporary Class            */
/*           */
/*=======================================*/
class Temporary : public Employee
{
private :
    int time;
    int pay;

public :
    Temporary(const char* _name, int _time, int _pay);
    int GetPay() const;
};

Temporary::Temporary(const char *_name, int _time, int _pay) : Employee(_name)
{
    time = _time;
    pay  = _pay;
}

int Temporary::GetPay() const
{
    return time * pay;
}

/*=======================================*/
/*           */
/*        Department Class           */
/*           */
/*=======================================*/
class Department
{
private :
    Employee* empList[100];
    int index;

public :
    Department() : index(0) {};
    void AddEmployee(Employee* emp);
    void ShowList() const;
};

void Department::AddEmployee(Employee *emp)
{
    empList[index++] = emp;
}

void Department::ShowList() const
{
    for(int i = 0; i < index; i++)
    {
        cout<<"name   : "<<empList[i]->GetName()<<endl;
        //cout<<"salary : "<<empList[i]->GetPay()<<endl;
        cout<<endl;
    }
}

/*=======================================*/
/*           */
/*         Main Function             */
/*           */
/*=======================================*/
int main(void)
{
    Department dept;

    //직원등록
    dept.AddEmployee(new Permanent("KIM", 1000));
    dept.AddEmployee(new Permanent("PARK", 1500));

    dept.AddEmployee(new Temporary("HAN", 10, 200));
    dept.AddEmployee(new Temporary("JANG", 12, 300));

    dept.ShowList();

    return 0;
}

반응형

'C, C++, Java' 카테고리의 다른 글

P304.cpp  (0) 2014.05.02
CPointer2.cpp  (0) 2014.05.02
Person.cpp  (0) 2014.04.30
P256.cpp  (0) 2014.04.30
Student.cpp  (0) 2014.04.30

#include <iostream>
#include <string.h>

using std::cout;
using std::endl;

class Person
{
 char name[20];
 int  age;

public :
 int GetAge() const
 {
  return age;
 }

 const char* GetName() const
 {
  return name;
 }

 Person(const char* _name, int _age)
 {
  age = _age;
  strcpy(name, _name);
 }

 void ShowData() const
 {
  cout<<"Name : "<<name<<endl;
  cout<<"Age  : "<<age<<endl;
 }
};

int main(void)
{
 Person KJ("KJPark", 37);
 KJ.ShowData();

 return 0;
}

반응형

'C, C++, Java' 카테고리의 다른 글

CPointer2.cpp  (0) 2014.05.02
EmployeeManager3.cpp  (0) 2014.05.02
P256.cpp  (0) 2014.04.30
Student.cpp  (0) 2014.04.30
C++ 초보자를 위한 좋은 사이트  (0) 2013.06.25

/*
 P256.cpp
*/

#include <iostream>

using std::endl;
using std::cout;

class AAA
{
public :
 AAA()
 {
  cout<<"AAA() call!"<<endl;
 }
 ~AAA()
 {
  cout<<"~AAA() call!"<<endl;
 }
};

class BBB : public AAA
{
public :
 BBB()
 {
  cout<<"BBB() call!"<<endl;
 }
 ~BBB()
 {
  cout<<"~BBB() call!"<<endl;
 }
};

int main(void)
{
 BBB bbb;
 return 0;
}

 

반응형

'C, C++, Java' 카테고리의 다른 글

EmployeeManager3.cpp  (0) 2014.05.02
Person.cpp  (0) 2014.04.30
Student.cpp  (0) 2014.04.30
C++ 초보자를 위한 좋은 사이트  (0) 2013.06.25
출퇴근 하면서 짬짬이 취미로 볼려고 열혈강의 C책을 다시 펴봤다.  (0) 2013.01.13

#include <iostream>
#include <string.h>

using std::cout;
using std::endl;

class Person
{
 char name[20];
 int  age;

public :
 int GetAge() const
 {
  return age;
 }

 const char* GetName() const
 {
  return name;
 }

 Person(const char* _name, int _age)
 {
  age = _age;
  strcpy(name, _name);
 }

};

class Student:public Person
{
 char major[20];

public :

 Student(const char* _name, int _age, const char* _major) : Person(_name, _age)
 {
  strcpy(major, _major);
 }

 const char* GetMajor() const
 {
  return major;
 }


 void ShowData() const
 {
  cout<<"Name  : "<<GetName()<<endl;
  cout<<"Age   : "<<GetAge()<<endl;
  cout<<"Major : "<<GetMajor()<<endl;
 }
};


int main(void)
{
 Student KJ("KJPark", 37, "BA");
 KJ.ShowData();

 Student YH("YH.Ahn", 39, "GI");
 YH.ShowData();
 return 0;
}

반응형

'C, C++, Java' 카테고리의 다른 글

Person.cpp  (0) 2014.04.30
P256.cpp  (0) 2014.04.30
C++ 초보자를 위한 좋은 사이트  (0) 2013.06.25
출퇴근 하면서 짬짬이 취미로 볼려고 열혈강의 C책을 다시 펴봤다.  (0) 2013.01.13
웹에서 Compile  (0) 2013.01.09

+ Recent posts