Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Language c++ sample program output shown below UML Diagram Specification for Payroll class Payroll hours : double - payRate : double + Payroll) + setHours

image text in transcribed

image text in transcribed

image text in transcribed

Language c++

sample program output shown below

UML Diagram Specification for Payroll class Payroll hours : double - payRate : double + Payroll) + setHours (h: double) : void + setPayRate (p: double) : void + getGross Pay() : double Implementation Details Constructor: Initialize a Payroll object to default zero values for data members Transformers (set xxx mutator functions): Assign parameter value to requested data member Additional observer function member: Return gross pay calculated as follows o gross pay is assigned hours * pay Rate o if hours is more than 40 then . overtime is remaining hours * (0.5 * payRate) . add overtime to gross pay o return gross pay purpose of this assignment is to demonstrate how ASSIGNMENT 2 20 points gnment is to demonstrate how to work with pointers as function parameters, and between pointers and arrays. Along with these assignment instructions you am outlining the class members with details about the constructor and other with the close relationship between should find a UML diagram outlin member function definitions. long with these ass e tructor and other Demonstrate how to declare functions with po 2 Objectives to be met: o declare functions with pointer parameters. ate how to call functions with arguments passed to pointer parameters. Demonstrate how to dereference pointers inside functions with P reference pointers inside functions with pointer parameters. Demonstrate how to call For this assignment, you will need hours worked, pay rate, and relat ent, you will need to define a simple class that encapsulates a payroll object including and pay rate Them ed, pay rate, and related functions including one to find the gross pay based on hours worked program will define an array of these objects and then simply calls two functions tuata and store it in each object in the array, and then output the gross pay for each object. In you will demonstrate how to pass the array as an argument to functions using a pointer parameter to work with the pay roll objects. to first input data and store it in each the process, you will demonstrate how to pass ne mput function can use a FOR loop to read in the data either by a) prompting and reading from the Doard of b) simply read directly from an input file. The output function also can use a FOR loop to write the gross pay to the screen for each one. (See sample data and output at the end of these instructions.) Minimum requirement: Follow the Payroll UML diagram specifications and implementation details. Use separate files for Payroll.h and Payroll.cpp 2 In the program's main() function, define an array of 7 Payroll objects. Declare, call, and define an input function that will loop to read the hours and pay rate for 7 3 employees, storing each set of data in each of the Payroll objects. This is a void function with 2 parameters: a Payroll pointer, and an int for the array size. Declare, call, and define an output function that will print the gross pay for 7 employees. This is another void function with 2 parameters: a Payroll pointer, and an int for the array size. Revise the declarations and headings in both functions to use const parameters. With the input function, the pointer and size should be constants but the Payroll data cannot be a constant. With the output function, both the pointer and Payroll data, and the size all should be constant parameters. (Hint: the Payroll class will need to declare one of its member functions as a constant function.) Revise the array definition inside main() to dynamically allocate the array, and at the end of the program just before the return statement, release the dynamically allocated memory, you will need to store that address in a pointer variable and then decide whether or not anything else must be modified. Revise the private data members in the Payroll class to be pointers. In the constructor you should initialize the pointers with dynamically allocated memory. Add a destructor that will release the dynamically allocated memory. Finally, modify all the other member functions as necessary to dereference the pointer data members. Considerations: ction will need two double variables to read the input and then use the next Payroll array element) to call the member functions that store the data in that object on will a l l the member function for each object that calculates and returns gross pay as it loops through the array. The employee numbers shown in the output example can inted by adding 1 to the loop control variable as it iterates through the array. of the close relationship between pointers and arrays, both functions can use array [1 select each object in the array and the dot operator to call the appropriate member Or, you can use pointer arithmetic and the -> operator to dereference an address and select Because of the close relationship be notation to select each object in the an the function. quirement #5, when you pass a pointer to a function there are 4 different ways to indicate how a constant might be applied: constant pointer Parameter declaration constant data no no DataType* ptr no yes DataType* const ptr no yes const DataType* ptr yes yes const Data Type* const ptr Choose the appropriate form of declaration based on the instructions for that recommendation. With Requirement #6, remember to use the correct syntax when using delete at the end of the program to release all the dynamic memory allocated for the array. (Review section 10.9 - Dynamic Memory Allocation) Additional Requirements: Include your name, course, section (CSC240) at the top of the EVERY program file as a comment. Submit all.cpp and .h files that you either created or modified. Any files that were provided that did NOT have changes do NOT need to be submitted. Sample program output Given this set of input data Hours Pay Rate 40.0 38.5 Employee Gross pay ====== ========= $ 400.00 $ 365.75 $ 120.00 $ 213.75 $ 356.00 $ 304.00 $ 427.50 16.0 10.00 9.50 7.50 9.50 8.00 8.00 9.00 22.5 43.0 38.0 45.0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

friendliness and sincerity;

Answered: 1 week ago