SnapTimes

News In A Snap!!

C++ Programs: Employee Records using Class Objects

June 2, 2015

C++_Main

Code


/* Employee Records using class Objects */
#include <iostream.h>
#include <string.h>
#include<conio.h>
class Employee {
private:
 int id;
 char name[20], designation[20];
 float salary;
public:
 void getData() {
 cout << "--Enter Employee Data" << endl;
 cout << "ID? : ";
 cin >> id;
 cout << "Name? : ";
 cin >> name;
 cout << "Designation? : ";
 cin >> designation;
 cout << "Salary? : ";
 cin >> salary;
 cout << "--------------------" << endl << endl;
 }

void showData() {
 cout << "ID : " << id << endl;
 cout << "Name : " << name << endl;
 cout << "Designation: " << designation << endl;
 cout << "Salary: " << salary << endl;
 cout << "--------------------" << endl << endl;
 }
};

int main() {
 clrscr();
 int i;
 cout << "How many employees? (Max:100): ";
 cin >> i;
 const int n =i;
 Employee emp[100];
 for (i=0; i<n; i++) {
 cout << "Entry no " << i+1 << "/" << n << endl;
 emp[i].getData();
 }
 cout << endl;
 cout << "==OUTPUT==" << endl;
 for (i=0; i<n; i++)
 emp[i].showData();
 getch();
 return 0;
}

Output:

co


SnapTimes.in | Get Tech Addicted...
About Us | Contact Us | ©2017