Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Wite a C++ program to solve the problem described below ( one dimensional arrays

ID: 3686640 • Letter: W

Question

Wite a C++ program to solve the problem described below (one dimensional arrays, two dimensional arrays, parallel arrays, and strings and also with functions and file input/output operations)

A company hired N=10 workers who are paid hourly and you are given a data file that contains the last name of the employees, the number of hours each employee worked in a week, and the hourly pay rate of each employee. For instance, a sample data file may look like

smith    30    6.25
cooper  45   7.00
brown   40    8.00
hut       10    9.99

You are asked to write a program that computes each employee’s weekly pay and the average salary of all the workers. The program then outputs the weekly pay of each employee, the average weekly pay, and the names of all the employees whose pay is greater than or equal to the average pay. If the number of hours worked in a week is more than 40 hours, then the pay rate for the hours over 40 is 1.5 times the regular hourly rate.

Use two parallel arrays: a one- dimensional array to store the names of all the employees, and a two- dimensional array of 10 rows and 3 columns to store the number of hours an employee worked in a week, the hourly pay rate, and the weekly pay. Your program must contain at least the following functions:

a function to read the data from the file into the arrays -- call it readFromFiletoArrays()

a function to determine the weekly pay of all the employees -- call it calcWeeklyPay()

a function to output the names of all the employees whose pay is greater than or equal to the average weekly pay and also print the average salary -- call it printAboveAverageEmployees()

a function to output each employee’s data   (including the name, number of hours worked, hourly rate, and salary)-- call it printAllEmployees().

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

const int ROWS = 10;  

const int COLS = 3;      

void readFromFiletoArrays(ifstream& inf, string names[], double empData[][COLS], int &count);
void calcWeeklyPay(double empData[][COLS], const int count);
void printAllEmployees(const string names[], const double empData[][COLS], const int count);
void printAboveAverageEmployees(const string names[], const double empData[][COLS], const int count);
// if you need more functions write their declarations here
// ...

int main()
{
  
   string names[ROWS] = {""};
   double empData[ROWS][COLS] = {0.0} ;
   int count = 0;

// IMPORTANT NOTE: Do not change the declarations of the functions and the main data
   // structures, above. You can add more functions and variables if you need to.
   //
   // write your code for the main function below.
   //...

   system("pause");
   return 0;
}

void readFromFiletoArrays(ifstream& inf, string names[], double empData[][COLS], int &count)
{

}

void calcWeeklyPay(double empData[][COLS], const int count)
{
}

void printAllEmployees(const string names[], const double empData[][COLS], const int count)
{

}


void printAboveAverageEmployees(const string names[], const double empData[][COLS], const int count)
{

}

__________________________

Thank you for the help

Explanation / Answer

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

const int ROWS = 10;

const int COLS = 3;    

void readFromFiletoArrays(ifstream& inf, string names[], double empData[][COLS], int &count);
void calcWeeklyPay(double empData[][COLS], const int count);
void printAllEmployees(const string names[], const double empData[][COLS], const int count);
void printAboveAverageEmployees(const string names[], const double empData[][COLS], const int count);
double calcAverage(const double empData[][COLS], const int count);

int main()
{

   string names[ROWS] = {""};
   double empData[ROWS][COLS] = {0.0} ;
   int count = 0;

   //opening a file
   char fileName[20];
   cout<<"Enter input filename: ";
   cin>>fileName;
  
   ifstream input(fileName);
  
   //reading data
   readFromFiletoArrays(input, names, empData, count);
  
   //calculating weekly pay
   calcWeeklyPay(empData, count);
  
   printAllEmployees(names, empData, count);
  
   printAboveAverageEmployees(names, empData, count);
  
   system("pause");
   return 0;
}

void readFromFiletoArrays(ifstream& inf, string names[], double empData[][COLS], int &count)
{
   while(count<ROWS && (inf>>names[count]>>empData[count][0]>>empData[count][1]))
       count++;
}

void calcWeeklyPay(double empData[][COLS], const int count)
{
   int i=0;
   for(i=0; i<count; i++){
      
       if(empData[i][0] > 40){
           empData[i][2] = empData[i][1]*40 + (empData[i][0] - 40)*1.5*empData[i][1];
       }
       else
           empData[i][2] = empData[i][1]*empData[i][0];
   }
}

void printAllEmployees(const string names[], const double empData[][COLS], const int count)
{
   cout<<"Name"<<"       "<<"No. hrs"<<"       "<<"Rate"<<"       "<<"salary"<<endl;
   for(int i=0; i<count; i++){
       cout<<names[i]<<"       "<<empData[i][0]<<"       "<<empData[i][1]<<"       "<<empData[i][2]<<endl;
   }
}


void printAboveAverageEmployees(const string names[], const double empData[][COLS], const int count)
{
       double avg = calcAverage(empData, count);
      
       for(int i=0; i<count; i++){
           if(empData[i][2] >= avg)
               cout<<names[i]<<" ";
       }
       cout<<endl;
       cout<<"Average salary: "<<avg<<endl;

}

double calcAverage(const double empData[][COLS], const int count){
   double total = 0;
   for(int i=0; i<count; i++)
       total = total + empData[i][2];
   return total/count;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote