Wednesday 18 July 2012

OOP: Composition in C++

#include<iostream>
#include<string>

using namespace std;


class employee
{
private: string employee_name;
public: employee(string name)
        {
            employee_name=name;
        }
public: string get_employee_name()
        {
            return employee_name;
        }
public: void show_employee_name()
        {
            cout<<"The name of the employee of this organization is == "<<employee_name<<endl;
        }

};
class organization
{
private: string organization_name;
         employee *myemployee;
public: organization(string name_of_employee, string name_of_organization)
        {
            myemployee=new employee(name_of_employee);
            organization_name=name_of_organization;
        }
public: void show()
        {
            cout<<"The organization name is == "<<organization_name<<endl;
            myemployee->show_employee_name();
        }
};
int main()
{
    string org_name,employ_name;
    cout<<"This is the organization structure"<<endl;
    cout<<"Enter the organization name == ";
    getline(cin,org_name);
    cout<<"Enter the name of employee == "<<endl;
    getline(cin,employ_name);
    organization myorganization(employ_name,org_name);
    myorganization.show();



    getchar();
    getchar();
    return 0;
}

No comments:

Post a Comment