Search This Blog

Wednesday 24 February 2016

Create a class called EMPLOYEE that has separate member data for name(s tring) and age(int).Include the following member functions: getdata( )to get these values from the user putdata( ) to display these values. Create array of object for class EMPLOYEE and use gedata() and putdata() to display all employee information.

Practical 13


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



output:

enter num of employees
2

enter the name of employee : karan
enter the age of employee  :  19

enter the name of employee : gajjar
enter the age of employee  :  18


name               karan
age                  19

name              gajjar
age                 18

No comments:

Post a Comment