Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program 2B Given that storeMonthlySales[NUM_STORES][NUM_MONTHS][NUM_DEPTS] is a three-dimensional array of float-point type. Write a C++ function, printMonthlySales , to calculate and print the total value

Program 2B

Given that storeMonthlySales[NUM_STORES][NUM_MONTHS][NUM_DEPTS] is a three-dimensional array of float-point type. Write a C++ function, printMonthlySales, to calculate and print the total value of sales during a specific month by each department and in each store plus totals by store and department and overall sales. The return type of the function is void and the function should have 2 input parameters: Sales array and the month the user specified (edit for correct value for month!). The constants NUM_STORES, NUM_MONTHS, and NUM_DEPTS must be accessed globally by defining the following global variables:

#define NUM_DEPTS 2

#define NUM_STORES 2

#define NUM_MONTHS 12

The array Sales is initialized by the following statement in your main():

float storeMonthlySales[NUM_STORES][NUM_MONTHS][NUM_DEPTS] =

{ 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2,

2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2,

3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 4.1, 4.2,

2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2

};

Output: Sales for month of value (where value represents January, March, etc.)

Dept # Dept # Store Total

Store # value value row value sum

Store # value value row value sum

Dept Total col value sum col value sum total overall sales

User enters a new month as many times as they wish and run printMonthlySales against the new month value.

Be sure to check for valid input (y or n) when asking if the user wants to enter a new month to print.

Then read in from a data file inFilePgm2B.dat additional data scenarios for testing .. a value of -1 indicates the end of the data for that test.

Be sure to account for all the standard file checks (file doesnt exist, file empty (should always contain at least a -1)) and handle the issues of not enough or too much data for the array, a complete (right number of data values) but array contains a negative number - still print the array but print an error message.

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

More Books

Students also viewed these Databases questions

Question

10. Describe the relationship between communication and power.

Answered: 1 week ago