Monday, 10 July 2017

/*12-C Prog-2 Define a struct employee to store employee code, employee name, address, phone no., salary. Create 5 objects of employee type read their values and print in ascending order of salary */

/*12-C Prog-2 Define a struct employee to store employee code, employee
name, address, phone no., salary.  Create 5 objects of employee type
read their values and print in ascending order of salary */

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>


struct employee
{
  int empcode;
  char empname[30];
  char adress[40];
  long phone;
  float salary;
};

void read(employee &E)
{
  cout<<"\n Enter employee code";
  cin>>E.empcode;
  cout<<"\n Enter employee name";
  gets(E.empname);
  cout<<"\n Enter employee's address";
  gets(E.adress);
  cout<<"\n Enter employee's phone no";
  cin>>E.phone;
  cout<<"\n Enter salary";
  cin>>E.salary;
}

void Arrange(employee E[], int size)
{
   int i,j;
   employee T;
   for(i=0;i<size;i++)
   {
     for(j=i+1;j<size;j++)
     {
       if(E[i].salary > E[j].salary)
       {
 T=E[i];
 E[i]=E[j];
 E[j]=T;
       }
     }
   }
}

void print(employee E)
{
  cout<<"\n Employee code"<<E.empcode;
  cout<<"\n Employee Name";
  puts(E.empname);
  cout<<"Employee Adress";
  puts(E.adress);
  cout<<"\n Employee Phone no"<<E.phone;
  cout<<"\n Employee salary"<<E.salary;
}

void main()
{
  clrscr();
  employee emp[5];
  cout<<"\n Enter details of Employee";
  for(int i=0; i<5; i++)
  {
    cout<<"\n Enter details of employee";
    read(emp[i]);
  }
  Arrange(emp,5);
  cout<<"\n Employees according to ascending order of salary\n";

  for(i=0;i<5;i++)
  {
     cout<<"\n Employee"<<i+1;
     print(emp[i]);
  }
 getch();
}

No comments:

Post a Comment