Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Sheet Questions

Question 27 page 139


Write C++ Program that read n employee data( id , first name, last name,
salary) and find employee name that has lagest salary.

Solution

#include <iostream.h>

#include <string.h>

struct emp {int id;

char first_name[20];

char last_name[20];

float salary;

};

int main () {

int n,max=0,r;

emp e[100];

cout<<"enter employees no \n";

cin>>n;

for(int i=0;i<n;i++)

cout<<"enter student id \n";


cin>>e[i].id;

cout<<"enter employee first name \n";

cin>>e[i].first_name;

cout<<"enter employee last name \n";

cin>>e[i].last_name;

cout<<"enter employee salary \n";

cin>>e[i].salary;

for ( i=0;i<n;i++)

if ( max< e[i].salary)

max=e[i].salary;

r=i;

cout<<
e[r].first_name<<"\t"<<e[r].last_name<<"has lagest
salary";

return 0;
}

You might also like