# Answered Essay: Jones,Frank 2 3 8 3635 Smith, Tiny 883082 Turk, Tom 9104700 e Jackson,Jim 5 6 56 5 6 5 Catan,Doug 7 387257

Write a C++ program that will need to read from a file of employee data for how many hours each employee worked for a week. Then for each of the employees, a total of the hours worked is made and then the employees are sorted into descending order based on their total hours using bubble sort. Cannot use structures or vectors.

There needs be 3 function calls total in main that:

Open and read the file into the array and add the total hours worked for each employee

Sort the array based on the total hours

Write out the output

Input file looks like this:

Output should look something similar to this:

Jones,Frank 2 3 8 3635 Smith, Tiny 883082 Turk, Tom 9104700 e Jackson,Jim 5 6 56 5 6 5 Catan,Doug 7 387257

/* This is the old one

Here is your code try and get the logic

#include <iostream>
#include <fstream>
using namespace std;
int main()
{

int c;
int sa[20][6];
int i,j,n;
char name[20][20];

ifstream myfile;
myfile>>n;
int sum[2][n];           // we create a two dimensional array to store one is for total hour and another for person
// ie sum[0][n] is for saving TTL
// and sum[1][n] is for link we use it for sorting
for(i=0;i<n;i++)    // geting form file
{
sum[0][i]=0;
sum[1][i]=i;
myfile>>name[i];
for(j=0;j<6;j++)
{
myfile>>sa[i][j];
sum[0][i]+=sa[i][j];

}

}

for (i = 0; i < n; ++i)    // sorting according to the sum that is total working hours
{
for (j = 0; j < n-i-1; ++j)
{
// Comparing consecutive data and switching values if value at j < j+1.
if (sum[0][j] < sum[0][j+1])
{
sum[0][j] = sum[0][j]+sum[0][j+1];
sum[0][j+1] = sum[0][j]-sum[0][j + 1];
sum[0][j] = sum[0][j]-sum[0][j + 1];

sum[1][j] = sum[1][j]+sum[1][j+1];             // this will set the link or swap link too
sum[1][j+1] = sum[1][j]-sum[1][j + 1];
sum[1][j] = sum[1][j]-sum[1][j + 1];

}
}

}

//display

cout<<“Employee Weekly Hours:n”;
cout<<“Name:ttMtTtWtTtFtStTTLn”;

for(i=0;i<n;i++)         // we have sorted sum so
{
c=sum[1][i];         // here c will hold the link who has the larger value, ie sum[0][i] will have high value
cout<<name[c]<<“t”;   // print using c
for(j=0;j<6;j++)
{
cout<<sa[c][j]<<“t”;
}
cout<<sum[0][i]<<“n”;
}

myfile.close();

return 0;
}

*/

Here is the new code the old one is also there

#include <iostream>
#include <fstream>
using namespace std;

int sa[20][6];
char name[20][20];
const int m=2;

void bubble_sort(int sum[][m],int n)
{
int i,j;

for (i = 0; i < n; ++i)    // sorting according to the sum that is total working hours
{
for (j = 0; j < n-i-1; ++j)
{
// Comparing consecutive data and switching values if value at j < j+1.
if (sum[j][0] < sum[j+1][0])
{
sum[j][0] = sum[j][0]+sum[j+1][0];
sum[j+1][0] = sum[j][0]-sum[j + 1][0];
sum[j][0] = sum[j][0]-sum[j + 1][0];

sum[j][1] = sum[j][1]+sum[j+1][1];             // this will set the link or swap link too
sum[j+1][1] = sum[j][1]-sum[j + 1][1];
sum[j][1] = sum[j][1]-sum[j + 1][1];

}
}
}
}

int total_working_hr(int sa[20][6],int n)
{
int sum=0,i;
for(i=0;i<6;i++)
{
sum+=sa[n][i];
}

return sum;
}
{
int n,i,j;
ifstream myfile;
myfile>>n;
for(i=0;i<n;i++)    // geting form file
{

myfile>>name[i];
for(j=0;j<6;j++)
{
myfile>>sa[i][j];
//sum[i][0]+=sa[i][j];

}

}
myfile.close();
return n;
}

int main()
{
int i,j,n,c;
n=readfile();        // Calling the first function
int sum[n][2];           // we create a two dimensional array to store one is for total hour and another for person
// ie sum[0][n] is for saving TTL
// and sum[1][n] is for link we use it for sorting

sum[i][1]=i;

for(i=0;i<n;i++)
{
sum[i][0]=total_working_hr(sa,i);       // Calling the second function
}
bubble_sort(sum,n);     // Calling the 3 rd function
//display

cout<<“Employee Weekly Hours:n”;
cout<<“Name:ttMtTtWtTtFtStTTLn”;

for(i=0;i<n;i++)         // we have sorted sum so
{
c=sum[i][1];         // here c will hold the link who has the larger value, ie sum[0][i] will have high value
cout<<name[c]<<“t”;   // print using c
for(j=0;j<6;j++)
{
cout<<sa[c][j]<<“t”;
}
cout<<sum[i][0]<<“n”;
}

return 0;
}

The o/p is same

the file.txt

the out put

Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

Try it now!

## Calculate the price of your order

Total price:
\$0.00

How it works?

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.