Thursday 19 July 2012

Arrays of Objects in C++

#include<iostream>
#include<string>

using namespace std;

class Employee
{
private:
    char name[30];
    int age;
public:
    void setdata();
    void getdata();
};

void Employee::setdata()
{
    cout<<"\nEnter the name == ";
    cin>>name;

    cout<<"\nEnter the age == ";
    cin>>age;
}

void Employee::getdata()
{
    cout<<"\n\nThe name of employee is == "<<name;
    cout<<"\n\nThe age of employee is == "<<age;
}

const int size = 4;

int main()
{
    Employee supervisor[size];

    for(int i=1;i<=size;i++)
    {
        cout<<"\nDeatail of manager "<<i;
        supervisor[i].setdata();
    }
    cout<<"\n";
    for(int j=1;j<=size;j++)
    {
        cout<<"\n\nManager"<<j;
        supervisor[j].getdata();
    }
    getchar();
    return 0;
}

No comments:

Post a Comment