Thursday, March 9, 2017

Input and display employee data of 100 employees using array of objects

Problem

Create a class called employee that contains a name (an object of class string) and an employee number (type long). Include a member function called getdata() to get data from the user for insertion into the object, and another function called putdata() to display the data. Assume the name has no embedded blanks.
Write a main() program to exercise this class. It should create an array of type employee, and then invite the user to input data for up to 100 employees. Finally, it should print out the data for all the employees.

Code

#include "stdafx.h"
#include<conio.h>
#include<iostream>
#include<string.h>
using namespace std;

class employee
{
private:
char name[50];
long no;

public:
employee():no(0)
{ }

void getdata()
{
fflush(stdin);
cout<<"\nEnter Employee Data:\n";
cout<<"Enter Name: ";
cin.get(name,50);
fflush(stdin);
cout<<"Enter Number: ";
cin>>no;
fflush(stdin);
}

void putdata()
{
cout<<"\n\nName= "<<name<<"\nE.number = "<<no<<endl;
}

};

int main()
{
int array_length = 3;
employee e1[array_length];

for(int i=0;i<array_length;i++){
e1[i].getdata();
fflush(stdin);
}

for(int i=0;i<array_length;i++){
e1[i].putdata();
}

cout<<"\n\nPress any key to close.";
getch();
return 0;
}

Output


Input and display employee data of 100 employees using array of objects

1 comment :

Note: Only a member of this blog may post a comment.

Copyright 2017. All Rights Reserved. Privacy Policy / Terms And Conditions / Sitemap / Contact