Tuesday, 27 November 2012

saving names of employee using structre


#include<iostream>
using namespace std;
#include<conio.h>
#include<string.h>
struct emp
{
        char m_name[50];
        int m_id;
        float m_hr;
        float m_payrate;
};
void main()
{
        emp e[20];
        int n,i;
        float monthlysal[20],overtime[20],totalsal[20];
        cout<<"\nenter the number of employees: ";
        cin>>n;
        for(i=0;i<n;i++)
        {
                cout<<"\n\nenter the name of the employee: ";
        cin>>e[i].m_name;
        cout<<"\nenter ID: ";
        cin>>e[i].m_id;
        cout<<"\nenter workload in hours: ";
        cin>>e[i].m_hr;
        e[i].m_payrate=10;
                if(e[i].m_hr>150)
                {
                        monthlysal[i]=150*e[i].m_payrate;
                        overtime[i]=(e[i].m_hr-150)*2*e[i].m_payrate;
                }
                else
                {
                        overtime[i]=0;
                        monthlysal[i]=e[i].m_hr*e[i].m_payrate;
                }
                totalsal[i]=monthlysal[i]+overtime[i];
        }
        cout<<"\nEmployee_Name Workload PayRate   Salary   Overtime Total_Salary\n\n";
        for(i=0;i<n;i++)
        {
                cout<<"     "<<e[i].m_name<<"      "<<e[i].m_hr<<"      "<<e[i].m_payrate;
                cout<<"      Rs."<<monthlysal[i];
                cout<<"     Rs."<<overtime[i]<<"     Rs."<<totalsal[i]<<"\n";
        }
        getch();
}





















Output:

enter the number of employees: 3


enter the name of the employee: rita

enter ID: 11

enter workload in hours: 140


enter the name of the employee: nita

enter ID: 22

enter workload in hours: 150


enter the name of the employee: sita

enter ID: 33

enter workload in hours: 260

Employee_Name Workload PayRate   Salary   Overtime Total_Salary

     rita      140      10      Rs.1400     Rs.0     Rs.1400
     nita      150      10      Rs.1500     Rs.0     Rs.1500
     sita      260      10      Rs.1500     Rs.2200     Rs.3700

No comments:

Post a Comment