Suppose the weekly hours for all employees are stored in a t
Solution
I have used an array of 3 employees with 7 days working. You can change same value of 3 and keep it how many employees you want.
#include<iostream.h>
#include<conio.h>
#include<string>
int main()
{
int a[3][7],temp[3][7], sum[3]={0,0,0},sum2[3]={0,0,0};
int i,j,k,tt,s=0;
string emp[3];
string t;
cout <<\"Enter name of first employee \";
cin >> emp[0];
cout <<\"Enter name of second employee \";
cin >> emp[1];
cout <<\"Enter name of tird employee \";
cin >> emp[2];
cout<<\"Enter Working Hours of of 3 Employee for 7 Days\ \";
for(i=0;i<3;i++)
for(j=0;j<7;j++)
cin>>a[i][j];
cout<<\"Matrix Entered By you is \ \";
for(i=0;i<3;i++)
{for(j=0;j<7;j++)
cout<<a[i][j]<<\" \";
cout<<endl;
}
for(i=0;i<3;i++)
{for(j=0;j<7;j++)
sum[i]=sum[i]+a[i][j];
cout<<endl;
}
for(i=0;i<3;i++)
{
cout<<\"Sum of total hours of employee \"<<emp[i]<<\" is \"<<sum[i]<<endl;
}
for (j = 0; j < 7; ++j)
{
for (i = 0; i < 3; ++i)
{
for (k = i + 1; k < 3; ++k)
{
if (sum[i] < sum[i+1])
{
tt = a[i][j];
a[i][j] = a[k][j];
a[k][j] = tt;
t= emp[k];
emp[k]=emp[i];
emp[i]=t;
}
}
}
}
for(i=0;i<3;i++)
{for(j=0;j<7;j++)
sum2[i]=sum2[i]+a[i][j];
cout<<endl;
}
for(i=0;i<3;i++)
{
cout<<\"Sum of total hours of employees After Sorting is \"<<emp[i]<<\": \"<<sum2[i]<<endl;
}
//getch();
}
