Search This Blog

Tuesday 2 February 2016

Array of classes

#include<iostream>
#include<iomanip>

using namespace std;

class EMPLOYEE
{
string name;
int age;
public:
void getdata();
void putdata();
};

void EMPLOYEE::getdata()
{
cout << "\t\tEnter name of the employee;";
cin >> name;
cout << "\n\t\tEnter age of the employee:";
cin >> age;
}

void EMPLOYEE::putdata()
{
cout << "\t\t-------------------------" << endl;
cout << "\t\t" << setw(15) << left << "Name - " << name << endl;
cout << "\t\t" << setw(15) << left << "Age - " << age << endl;
cout << "\t\t-------------------------" << endl;
}

int main()
{
int n;
cout << "\t\tEnter no. of employees:";
cin >> n;
EMPLOYEE emp[n];
for(int i=0;i<n;i++)
emp[i].getdata();
for(int i=0;i<n;i++)
emp[i].putdata();
return 0;
}

No comments:

Post a Comment