QuestionQuestion

Using file I/O, arrays and functions
Program Description: In this program you will need to read from a file 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 calculated and then the employees are sorted into descending order based on their total hours.

Task Details:
-Create a 50x8 int array to hold the employee’s data, and a size 50 string array to hold the employee names.
-Read all the employee data into the arrays
-Total number of hours worked in the week and store it in the int array at location
-Create a const variable to make it obvious that your 7th position is being used to hold the total hours worked. Example: hour[ i ] [ TTL_HRS ] = total;
-Sort the employees by the total number of hours they worked for the week. The sort should be in descending order (most hours to least)
-Write out the information to the console

Miscellaneous:
You should create and use a function to do each of the following task:

-open and read the file into the arrays and add the total hours worked for each employee (this can be added to the array (total of 8 elements for each employee)
-sort the arrays based on the total hours
-write out the output

You want main to be like an outline of the program. Each function should do one thing well, and be able to fit on one screen. If a function is taking two screens, think of how you can break it down. You can have additional functions if you think it will help make your program clearer.

Make sure you display the data in a nice looking format.

Since you don\'t know how many employees you will have when you create the arrays, you can just use a size of 50 and then only use part of them

The data is in a text file called empdata.txt

Your program does not require any interaction with the user. If the input file is found no messages will be sent to the user; instead the program will read and fill the array, make the calculations and write the output to the screen. Otherwise, if you can\'t open the file, then you should send a message to the screen.

The input file will be in the following format:

5
Jones,Frank 2 3 8 3 6 3 5
Smith,Tiny 8 8 3 0 8 2 0
Turk,Tom 9 10 4 7 0 0 0
Jackson,Jim 5 6 5 6 5 6 5
Catan,Doug 7 3 8 7 2 5 7

It is a text file. The first line of the input file is the number of employees. You can use this number to control the loops that will do your reading. Then each line after that will include the employees name and seven integers for the number of hours that the employee worked for the week. The employee's name will not include any spaces and so it can be read as a string. Each of the numbers will have a space between them. Since an array can only hold one type of data, you will need to use two different arrays; one for the names and one for the work hours.

The input files are found in the Files Section of “Canvas\Course Resource\Program 5” folder. There are two files that you need to run your program on for turning in. To do this, you would run your program 2 times; once for each input file. For turn in, you need to use empdata3.txt and empdata4.txt.

For sorting the array, you must use bubble sort (passing through the array comparing two elements at a time, and swapping if needed; and then making only as many passes as needed to sort all the numbers). Here is an example of the Bubble Sort algorithm (Links to an external site.). Remember as you are sorting, you will need to also be moving the names in their array.

Your output should look like this:

Employee Weekly Hours:
Name: S M T W T F S TTL
Kirk,James 10 10 0 10 12 0 0 42
McCoy,Lenard 0 4 0 8 4 0 2 18
Scott,Annis 1 6 2 0 0 1 0 10

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

/*
This program is used to read employee data (how many hours each employee worked for a week) and display the data in
descending order based on employees' total working hours for the week.
*/

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

// 7th index of relavent array stores employee's total working hours
const int TTL_HRS = 7;

// This function reads in employee data from a given file to employeeHours and employeeNames arrays.
// It returns the number of employees that were read from the file.
int readFileDataToArrays(string fileName, int employeeHours[50][8], string employeeNames[50]);

// This function sorts the two arrays employeeHours and employeeNames in descending order based on
// employee total working hours for week (i.e. employeeHours[i][TTL_HRS])
void sortArraysByTotalHours(int employeeHours[50][8], string employeeNames[50], int noOfEmployees);

// This function prints out the information about employeeHours and employeeNames to console
void printOutput(int employeeHours[50][8], string employeeNames[50], int noOfEmployees);


int main() {
    int employeeHours[50][8];
    string employeeNames[50];

    string fileName = "E:\\24Hours\\Project 19\\test_files\\empdata4.txt";...

By purchasing this solution you'll be able to access the following files:
EmployeeTracker.cpp.

$30.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats