Code:
#include<iostream.h>
#include<conio.h>
struct employee
{
int id;
char name[80];
char designation[40];
char address[80];
float basic;
}e[10];
int main()
{
int x,i;
//clrscr();
for(i=0;i<2;i++)
{
cout<<"Employee "<<i+1;
cout<<"\nEnter employee ID: ";
cin>>e[i].id;
cin.ignore(1,'\0');
cout<<"\nEnter name: ";
cin.getline(e[i].name, 50);
cout<<"\nEnter designation: ";
cin.getline(e[i].designation,50);
cout<<"\nEnter address: ";
cin.getline(e[i].address,80);
cout<<"\nEnter Basic Pay: ";
cin>>e[i].basic;
cout<<"\n\n";
}
cout<<"Enter the ID to be searched for: ";
cin>>x;
for(i=0;i<2;i++)
{
if(e[i].id==x)
{
cout<<"\nDisplaying..";
cout<<"\nEmployee ID: "<<e[i].id;
cout<<"\nName: "<<e[i].name;
cout<<"\nDesignation: "<<e[i].designation;
cout<<"\nAddress: "<<e[i].address;
cout<<"\nBasic Pay: "<<e[i].basic;
break;
}
else
{
cout<<"\nEmployee not found!";
}
}
cout<<"\n\nExiting... Press 'any key' to continue... ;-)";
getch();
return 0;
}
Output:
Employee 1
Enter employee ID: <some num>
Enter name: <john doe>
Enter designation: <desig>
Enter address: <any addr>
Enter Basic Pay: <random num>
Employee 2
Enter employee ID: <some num 2>
Enter name: <john doe 2>
Enter designation: <desig 2>
Enter address: <any addr 2 >
Enter Basic Pay: <random num 2>
Enter the ID to be searched for: <any id>
Displaying..
Employee ID: <corresp. id>
Name: <corresp. name>
Designation: <corresp. desig>
Address: <corresp. addr>
Basic Pay: <corresp. basic>
Exiting... Press 'any key' to continue... ;-)