Define a class Employee with data member as name,emp_id,age. Wrie a programm to write the data of three employee's using class object. Read the records of employee and print them to console
#include<iostream>
#include <string>
using namespace std;
class Employee {
private:
string name;
int emp_id;
int age;
public :
// user input
Employee() {
cout << "Enter employee information :"<<endl;
cout << "Name: ";
cin >> name;
cout << "ID: ";
cin >> emp_id;
cout << "Age: ";
cin >> age;
cout<<endl;
}
void display();
};
void Employee::display() {
cout <<"===============================" << endl
<<"Employee name " << name <<endl
<<"Employee ID "<< emp_id << endl
<<"Age "<<age << endl<<endl;
}
int main() {
// Write the data of three employee's using class object
Employee EmpA;
Employee EmpB;
Employee EmpC;
// Read the records of employee and print them to console
EmpA.display();
EmpB.display();
EmpC.display();
return 0;
}
Comments
Dear Prashant pal, sure
Is it right answer
Leave a comment