Question: (C++ Structured Data) Write a program to process arrays of structured data. The program must be written in accordance to the following plan: Define Data

(C++ Structured Data)

Write a program to process arrays of structured data.

The program must be written in accordance to the following plan:

Define Data Structures

Define a data structure named Sale. The structure has the following fields:

string itemName

int quantity

double unitPrice

double salePrice

Write Function Prototypes

Write a function prototype for the function named loadData. The function receives an array of Sale as the first parameter and an int as the second parameter. The second parameter is for the size of the array. The function does not have any value to return.

Write a function prototype for the function named processData. The function receives an array of Sale as the first parameter and an int as the second parameter. The second parameter is for the size of the array. The function returns a double.

Write a function prototype for the function named printData. The function receives an array of Sale as the first parameter and an int as the second parameter. The second parameter is for the size of the array. The function does not have any value to return.

Write The Main Function

Define an int constant named SALES_SIZE and initialize it to 5.

Define an array named salesData that contains 5 Sale item using the named constant defined above as the size.

Call loadData and pass the array and size defined above.

Call printData to print the sales information on the screen.

Write Function Definitions

Function loadData

Write the block comment that describes the function name, what the function does, the parameters and the return value. In this case, simply write there is no returned value.

In the function body, load these data into the array received through the parameters.

"Milk", 1, 5.85

"Whole Wheat Bread", 2, 3.75

"Napkin", 3, 2.35

"Paper Towel", 3, 2.95

"Soap", 1, 1.95

Function processData

Write the block comment that describes the function name, what the function does, the parameters and the return value.

In the function body, iterate through the array received through the parameters to calculate the total sale price for each item and update the salePrice fields of the data structures.

The function should return the total price of the sale items contained in the array.

Function printData

Write the block comment that describes the function name, what the function does, the parameters and the return value. In this case, simply write there is no returned value. You must use manipulators on cout to format the output.

In the function body, call processData and pass the array received through the parameters to update the sale price for each item and calculate the total sale price of all the sale items contained in the array.

Iterate through the array received through the parameters and print the data according to the required format.

Test The Program

The output should look exactly as follows.

Sales Item Qty Unit Amt ======================================== Milk 1 5.85 5.85 Whole Wheat Bread 2 3.75 7.50 Napkin 3 2.35 7.05 Paper Towel 3 2.95 8.85 Soap 1 1.95 1.95 Total 31.20 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!