Showing posts with label OOP implementation. Show all posts
Showing posts with label OOP implementation. Show all posts

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;
}

Saturday, 14 July 2012

OOP : Aggregation in C++

#include<string>
#include<iostream>

using namespace std;

class Mobile
{
public: string IMEI_NO;
public: string Model;
public: Mobile(string im_no,string model)
        {
            IMEI_NO=im_no;
            Model=model;
        }
public: void show()
        {
            cout<<"IMEI no is == "<<IMEI_NO<<endl;
            cout<<"Model of your mobile is == "<<Model<<endl;
        }
};


class Person
{
    Mobile *mymobile;
public: string name;
public: string CNIC;
public: Person(string n , string c)
        {
            name=n;
            CNIC=c;
        }
public: void show()
        {
            cout<<"The name of the person is == "<<name<<endl;
            cout<<"The CNIC of a particular person is == "<<CNIC<<endl;
            mymobile->show();       
        }
public:void setmobile(Mobile * m1)
        {
            mymobile=m1;
        }
};

int main()
{
    Mobile *mob;
    mob=new Mobile("12589874458580","nokia 3310");
    Person myperson("Anonymous","37405-58925986-5");

    myperson.setmobile(mob);
    myperson.show();

    getchar();
    return 0;
}