Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The purpose of this assignment is to demonstrate how to work with pointers as function parameters, and with the close relationship between pointers and array.

The purpose of this assignment is to demonstrate how to work with pointers as function parameters, and with the close relationship between pointers and array. Along with these assignment instructions you should find a UML diagram outlining the class members with details about the constructor and other member function definition. Objectives 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 pay roll 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 each 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 pay roll objects. The input function can use a FOR loop to read in the data either by

a)

prompti

ng 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 requir

ement

:

1

Follow the

Payr

oll

UML diagram specifications and implementation details.

Use separate

files for Payroll.h and Payr

oll.cpp

2

In the programs main() fun

ction, define an array of 7 Payr

oll objects

.

3

Declare, call, and define an

input

function that will loop to read the hours and pay rate for 7

employees, storing each

set of data in each of the Payr

oll objects

.

This is a void fu

nction with

2 parameters: a Payr

oll pointer, and an int for the array size.

4

Declare, call, and define an

output

function that will print the gross pay for 7 employees. This

is a

nother

void fu

nction with 2 parameters: a Payr

oll pointer, and an int for the array size.

5

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 Pay

r

oll

data cannot be a

constant. With the output function, both the pointer and Pay

r

oll data, and the size all should

be constant parameters.

(

Hint

: the Payr

oll class will need to declare

one of its

member

function

s as a constant function

.

)

6

Revise the a

rray 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

.

7

Revise the

private data members in the Payr

oll 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 me

mbers.

Considerations:

The input function will need two double variables to read the

input and then use the next Payr

oll

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 1 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 each 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.

W

ith

Requirement

#

5

, w

hen you pass a pointer to a function there are 4 different ways to indicate how

a constant might be applied

:

Param

eter declaration

constant data

constant pointer

DataType* ptr

no

no

DataType* const ptr

no

yes

const DataType* ptr

yes

no

const DataType* const ptr

yes

yes

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 main program file as a comment.

Compress

and

submit your project folder as a single

.zip file.

If you need help with making a .zip file, use the

Discussion Board for assistance.

All source, header, and data files

(if any)

mus

t be inside the project

folder.

Before you compress (zip) your completed project, you can open the

Build

menu and execute the

Clean Solution

command to remove some unnecessary files, and then close Visual Studio and compress

the project f

older.

Be sure you submit the single

compressed (zip) file containing the project folder and

Files.

Given this set

of input data

Sample program output

Hours

Pay Rate

40.0 10.00

38.5 9.50

16.0 7.50

22.5 9.50

43.0 8.00

38.0 8.00

45.0 9.00

Employee Gross pay

======== =========

1: $ 400.00

2: $ 365.75

3: $ 120.00

4: $ 213.75

5: $ 356.00

6: $ 304.00

7: $ 427.50

UML Diagram Specification for Payroll class

Payroll

-hours: double

-payRate: double

+PayRoll ()

+setHours(h:double):void

+setPayRate(p:double):void

+ getGrossPay():double

Implementation Details

Constructor:Initialize a Payroll object to default zero values for data members

Transformers(setXXXmutatorfunctions): Assign parameter value to requested data member

Additional observer function member: Return gross pay calculated as follows gross

pay is assigned hours * payRate if hours is more than 40 then overtime is remaining hours * (0.5 * payRate) add overtime to gross pay 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

Successful Keyword Searching Initiating Research On Popular Topics Using Electronic Databases

Authors: Randall MacDonald, Susan MacDonald

1st Edition

0313306761, 978-0313306761

More Books

Students also viewed these Databases questions