Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Language; neatly and organized please and thank you The putee of this assignment is to demonstrate how to work with pointers as function parameters,

image text in transcribed

image text in transcribed

image text in transcribed

C++ Language; neatly and organized please and thank you

The putee of this assignment is to demonstrate how to work with pointers as function parameters, and with the close relationship between pointers and arrays. Along with these assignment instructions you should find a UML diagram outlining the class members with details about the constructor and other member function definitions. Obiectives to be met: 1 Demonstrate how to declare functions with pointer parameters. 2 Demonstrate how to call functions with arguments passed to pointer parameters. 3 Demonstrate how to dereference pointers inside functions with pointer parameters. For this assignment, you will need to define a simple class that encapsulates a payroll object including hours worked, pay rate, and related functions including one to find the gross pay based on hours worked and pay rate. The main program will define an array of these objects and then simply calls two functions to first input data and store it in cach object in the array, and then output the gross pay for each object. In the process. You will demonstrate how to pass the array as an argument to functions using a pointer parameter to work with the payroll objects. The input function can use a FOR loop to read in the data either by a) prompting and reading from the keyboard or 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: The input function will need two double variables to read the input and then use the next Payroll object (array element) to call the member functions that store the data in that object The output function will need to call the member function for each object that calculates and returns the gross pay as it loops through the array. The employee numbers shown in the output example can be printed by adding to the loop control variable as it iterates through the array, Because of the close relationship between pointers and arrays, both functions can use array notation to select cach object in the array and the dot operator to call the appropriate member function. Or, you can use pointer arithmetic and the operator to dereference an address and select the function With Requirements, when you pass a pointer to a function there are 4 different ways to indicate how a constant might be applied Parameter declaration constant data constant pointer Datatyperpte DataTypeconst ptr yes const Datatype* PLE const DataType Const str no ye 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 Given this set of input data Sample program output Hours Pay Rate Employee Gross pay 33 38.5 16.0 22. 43.0 10.00 9.50 7.50 9.50 8.00 8.00 $ 400.00 $365.75 5 120.00 $ 213.75 $ 356.00 $ 304.00 $ 427.50 38.0 6: UML Diagram Specification for Payroll class Payroll - hours : double - payRate : double + Payrollo + set Hours (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 if hours is more than 40 then overtime is remaining hours (0.5 * payRate) . add overtime to gross pay o return gross pay

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions