Question

In: Computer Science

C++ This exercise will provide practice with working with structures and arrays. Although there might be...

C++

This exercise will provide practice with working with structures and arrays. Although there might be many ways of doing the assignment, to get full credit, it must be done exactly as specified here(for purpose of practice)

Write a program that will record information about employees and will compute their paychecks. Each employee must be represented by a struct containing the last name, hours worked each day of the week, the hourly rate, and the pay for the week.

Hours worked each day of the week must be and array storing 5 values for the hours from Monday to Friday( The company is not open on Saturday or Sunday). This array will be inside the structure.

There will also be an array of the employees; array of structures. There must be at least four (4) employees. The array must be declared in the main function of the program. Then the entire array must be passed to a function called 'initialize'. This function will ask the user to enter values for every field of every structure, except for the pay for that week. ( the pay will be computed in a different function)

A loop for processing the array of employees must be set up in the main function. Inside the loop, a single employee will be past to the function called 'compute', which will calculate the check for that employee. If the employee worked longer than 40 hours, overpay of 1.5 times the hourly rate is to be used for each hour worked over the 40 hours. For example, an employee who worked a total of 50 hours for $10.00 an hour would make $550.00. Don't pass the entire array of employees into the 'compute'; the employees will be passed one at a time into the function, until all of their paychecks have been calculated, at which time the loop will terminate. The employee will need to be passed by reference.

A single employee must be passed into the result function, which will output the last name of the employee. Do not pass the entire array of employees to the 'result' function. Each employee must be passed through call by value, one at a time, until all of the paycheck amount have been output at which time the loop in the main function will terminate. Then the program will end.

Solutions

Expert Solution

Screenshot

-------------------------------------------------------------------------------------

Program

//Header files
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
//Create a structure for employee
struct Employee {
   string lastName;
   double hoursWorked[5];
   double hourlyRate;
   double payment;
};
//Function prototypes
void compute(Employee &employee);
void initialize(Employee *employee,int size);
void result(Employee employee);
//Test
int main()
{
   //Create an employee struct array of size 4
   Employee emp[4];
   //Get employee details
   initialize(emp,4);
   //Compute their week payment
   for (int i = 0; i < 4; i++) {
       compute(emp[i]);
   }
   //Display result
   for (int i = 0; i < 4; i++) {
       result(emp[i]);
   }
    return 0;
}
/*
//Method to initialize employee details
//Employee array and it's size as parameters
//Set employee details otherthan payment
*/
void initialize(Employee *employee, int size) {
   for (int i = 0; i < size; i++) {
       Employee emp;
       cout << "Enter the last name of employee: ";
       cin >> employee[i].lastName;
       for (int j = 0; j < 5; j++) {
           cout << "Enter " << employee[i].lastName << "'s working hour Day"<<(j+1)<<": ";
           cin >> employee[i].hoursWorked[j];
       }
       cout << "Enter " << employee[i].lastName << "'s hourly rate: ";
       cin >> employee[i].hourlyRate;
   }
}
/*
//Method to comput payment
//Take each employee's details as parameter as reference
//Then find total working hours
//Then calculate payment and set
*/
void compute(Employee &employee) {
   employee.payment = 0.0;
   double hrsWorked = 0;;
   for (int i = 0; i < 5; i++) {
       hrsWorked += employee.hoursWorked[i];
   }
   if (hrsWorked <= 40) {
       employee.payment += hrsWorked* employee.hourlyRate;
   }
   else {
       employee.payment += (40 * employee.hourlyRate) + ((hrsWorked - 40)*(1.5*employee.hourlyRate));
   }
}
/*
//Method to display each employee's payment details
//Take employee as parameter as value
//Display last name and pay check amount in 2 decimal places.
*/
void result(Employee employee) {
   cout << fixed << setprecision(2);
   cout << "LastName: " << employee.lastName << "     PayCheck: $" << employee.payment << endl;
}

------------------------------------------------------------------------

Output

Enter Milan's working hour Day3: 8
Enter Milan's working hour Day4: 7
Enter Milan's working hour Day5: 6
Enter Milan's hourly rate: 10
Enter the last name of employee: Moke
Enter Moke's working hour Day1: 10
Enter Moke's working hour Day2: 9
Enter Moke's working hour Day3: 10
Enter Moke's working hour Day4: 9
Enter Moke's working hour Day5: 10
Enter Moke's hourly rate: 15
Enter the last name of employee: Albert
Enter Albert's working hour Day1: 9
Enter Albert's working hour Day2: 8
Enter Albert's working hour Day3: 9
Enter Albert's working hour Day4: 8
Enter Albert's working hour Day5: 9
Enter Albert's hourly rate: 12
Enter the last name of employee: Mayer
Enter Mayer's working hour Day1: 12
Enter Mayer's working hour Day2: 10
Enter Mayer's working hour Day3: 9
Enter Mayer's working hour Day4: 9
Enter Mayer's working hour Day5: 7
Enter Mayer's hourly rate: 11
LastName: Milan     PayCheck: $400.00
LastName: Moke     PayCheck: $780.00
LastName: Albert     PayCheck: $534.00
LastName: Mayer     PayCheck: $555.50
Press any key to continue . . .


Related Solutions

This assignment is to give you practice using struts, arrays, and sorting. (Objective C++ and please...
This assignment is to give you practice using struts, arrays, and sorting. (Objective C++ and please have a screenshot of output) In competitive diving, each diver makes dives of varying degrees of difficulty. Nine judges score each dive from 0 through 10 in steps of 0.5. The difficulty is a floating-point value between 1.0 and 3.0 that represents how complex the dive is to perform. The total score is obtained by discarding the lowest and highest of the judges’ scores,...
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists...
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists of values stored in an array. Write a modular program. Sort an array. Requirements to meet: Write a program that asks the user to enter 5 numbers. The numbers will be stored in an array. The program should then display the numbers back to the user, sorted in ascending order. Include in your program the following functions: fillArray() - accepts an array and it's...
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists...
This is a C++ assignment The necessary implementations: Use arrays. Write some functions. Practice processing lists of values stored in an array. Write a modular program. Sort an array. Requirements to meet: Write a program that asks the user to enter 5 numbers. The numbers will be stored in an array. The program should then display the numbers back to the user, sorted in ascending order. Include in your program the following functions: fillArray() - accepts an array and it's...
1.Write a C++ program using control structures, arrays, functions to calculate the number of dollars, quarters,...
1.Write a C++ program using control structures, arrays, functions to calculate the number of dollars, quarters, dimes, nickels, and pennies in a given amount of money. The input should be a floating-point value representing a decimal value. Example: 63.87 à 63 [dollars and 87 cents] should output 63 dollars, 3 quarters, 1 dime, 0 nickels, and 2 pennies. 2. In trigonometry the cosine function can be calculated using cos(x) = 1 – x 2 /2! + x 4 /4!- x...
Can you provide an example on how a decision tree might be used in practice?
Can you provide an example on how a decision tree might be used in practice?
Objectives: Practice using selection structures within a complete C++ program to solve a problem. Be able...
Objectives: Practice using selection structures within a complete C++ program to solve a problem. Be able to understand and use linear interpolation in a program. Modify/Extend an existing program. Problem Description: Linear Interpolation There are two credit levels for this assignment. Completing the “B” level correctly is worth 16/20 points, completing the “A” level is worth 20/20. You are encouraged to get the code for the “B” level working first and then complete the “A” level if you have time/interest....
Project 1 - Arrays - Grader The purpose of this assignment is to practice dealing with...
Project 1 - Arrays - Grader The purpose of this assignment is to practice dealing with arrays and array parameters. Arrays are neither classes nor objects. As a result, they have their own way of being passed as a parameter and they also do not support the dot operator ( .), so you cannot determine how full they are. This results in some pain and suffering when coding with arrays. It is this awareness that I am trying to get...
C++ PROGRAM Programming Exercise 11 in Chapter 8explains how to add large integers using arrays. However,...
C++ PROGRAM Programming Exercise 11 in Chapter 8explains how to add large integers using arrays. However, in that exercise, the program could add only integers of, at most, 20 digits. This chapter explains how to work with dynamic integers. Design a class named largeIntegers such that an object of this class can store an integer of any number of digits. Add operations to add, subtract, multiply, and compare integers stored in two objects. Also add constructors to properly initialize objects...
Objective: The goal of this lab is to practice (ragged) 2D arrays and simple recursion (in...
Objective: The goal of this lab is to practice (ragged) 2D arrays and simple recursion (in two separate parts). You are not allowed to use any of the built-in classes for this lab. If you find yourself needing to import anything at the top of your class, you are doing it wrong. Part A a) Create a class method called printArray2D that accepts a 2D integer array and prints out the values formatted such that each value occupies 4 spaces...
Working on a c++ data structures assignment.   Linked List add node. I have the head case...
Working on a c++ data structures assignment.   Linked List add node. I have the head case and the tail case working but the middle/general case I can not get to work for the life of me. I have included the header file and the data struct file below   #ifndef LINKEDLIST_H #define LINKEDLIST_H #include "data.h" #include <iostream>   //take this out using std::cout; class LinkedList{     public:         LinkedList();         ~LinkedList();         bool addNode(int, string);         bool deleteNode(int);         bool getNode(int, Data*);         void printList(bool = false);         int getCount();         void...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT