Write a program that lets the user enter four quarterly sales figures for three
ID: 3633577 • Letter: W
Question
Write a program that lets the user enter four quarterly sales figures for three divisions of a company. The figures should be stored in a two-dimensional array. Once the figures are entered, the program should display the following data for each quarter:• A list of the sales figures by division
• The total sales for the quarter
• The average sales for all divisions that quarter
• The division with the highest sales for that quarter
The program should be modular, with functions that calculate the statistics above. Use the following sales table to test the program
Input Validation: Do not accept negative numbers for sales figures.
SALES:
Quarter 1 Quarter 2 Quarter 3 Quarter 4
Division 1 34 42 22 43
Division 2 33 33 40 28
Division 3 29 27 30 35
Explanation / Answer
The two-dimensional array will have the form sales[period][division] to represent the sales in a particular period from a particular division. We use the generic term period instead of the specific term, quarter, to allow the code to be used for other reporting periods with minimal adjustments. In the code below, we have made up names for the six divisions to show how we can use arrays to generalize the code. If we had a different set of divisions, we would only have to change the array initialization statement for the division names. Similarly changing the names of the reporting periods would require only a change to the definition of the period name array. Of course, changing the number of reporting periods or the number of divisions would require changes to the symbolic constants that specify the numbers of periods and divisions. Notice that when we pass a whole array to a function, we can change elements of the array. We can do this because whole arrays are passed by reference. Notice that the use of a common input file is maintained by passing the program variable for the file name to the function as a reference to the type ofstream. #include #include using namespace std; // Use global data for array sizes and array names const int MAX_DIVISIONS = 6, MAX_PERIODS = 4; string divisionName[] = {“Pacific”, “Mountain”, “North Central”, “South Central”, “Northeast”, “Southeast” }; string periodName[] = {“First Quarter”, “Second Quarter”, “Third Quarter”, “Fourth Quarter” }; // Function prototypes shown below void getInput( double sales[MAX_PERIODS][ MAX_DIVISIONS] ); void printSalesTable( double sales[MAX_PERIODS][ MAX_DIVISIONS], double periodTotal[], ofstream& outFile ); void printPercentIncrease( double sales[MAX_PERIODS][ MAX_DIVISIONS], double periodTotal[], ofstream& outFile ); void printTopDivision( double sales[MAX_PERIODS][ MAX_DIVISIONS], ofstream& outFile ); int main() { double sales[MAX_PERIODS][ MAX_DIVISIONS]; double periodTotal[MAX_PERIODS]; getInput( sales ); ofstream outFile; printSalesTable( sales, periodTotal, outFile ); printPercentIncrease( sales, periodTotal, outFile ); printTopDivision( sales, outFile ); return EXIT_SUCCESS; } void getInput( double sales[MAX_PERIODS][ MAX_DIVISIONS] ) { // Get input data in this routine. Prompt user for keyboard // input, checking for negative sales figures coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.