I am taking a C++ programing course and need to know this source code please. Yo
ID: 3920377 • Letter: I
Question
I am taking a C++ programing course and need to know this source code please.
You have been tasked by the IT department of Acme Electronics to write a program to generate a report about last year’s sales. The report created by the program will be the table shown below. It will also display the division and quarter with the highest sales and the division and quarter with the lowest sales for the year.
The program will need to use a 2-Dimensional array. This array that will hold the sales totals for 4 divisions and for 4 quarters. The array must be created to also hold the total for each division and for each quarter (in other words the total for each column and each row, when thinking about the array as a table or spreadsheet). These totals will be calculated by the program once the values have been inputted by the user. This array will have the quarters as the columns and the divisions as the rows. The last column will hold the totals for the rows (division totals) and the last row will hold the totals for the columns (quarter totals). Note: the very last element in the array will not be used.
Another array should be used to store the division names of North, South, East, and West. This array will be used when getting the inputs from the user and for the outputs.
The program should use two global constants called ROWS and COLS.
The program must provide the following functions:
double CalculateTotal(double [][COLS]);
Calculates the total of the complete array except for the totals in the last column and last row.
Returns the total.
double CalculateAverage(double [][COLS]);
Calculates the average of all the values in the array except for the column and row with the totals in them.
Returns the average.
double CalculateRowTotal(double [][COLS], int);
Calculates the total for row that is specified by the second parameter.
Returns the total for the specified row.
double CalculateColumnTotal(double [][COLS], int);
Calculates the total for a column that is specified by the second parameter.
Returns the total for the specified column.
double FindHighest(double [][COLS], int&, int&);
Finds the highest sales in the array.
Provides the index values (row, column) of where the highest value is located in the array.
Returns the highest amount.
double FindLowest(double [][COLS], int&, int&);
Finds the lowest sales in the array.
Provides the index values of where the lowest value is located in the array.
Returns the lowest amount.
The program should output a table in the same format as below which will then be followed by the division and quarter with the highest value and the division and quarter with the lowest value.
Quarter 1
Quarter 2
Quarter 3
Quarter 4
Division Total
North
South
East
West
Quarter Total
Pseudocode must be provided in the comment block at the top of the file.
Quarter 1
Quarter 2
Quarter 3
Quarter 4
Division Total
North
South
East
West
Quarter Total
Explanation / Answer
/*
Pseudocode is as follows:
Declare 2d array data
Declare ROWS = 5, COLS = 5
Declare totalSales, averagesales, maximumsale, minimumsale
Input sales for North
Input sales for South
Input sales for East
Input sales for West
Calculate Divison total in 5th column of data by callind CalculateRowTotal()
Calculate Quarter total in 5th row of data by callind CalculateColumnTotal()
totalSales = CalculateTotal()
averagesales = CalculateAverage()
maximumsale = FindHighest()
minimumsale = FindLowest()
Display data with headings, totalSales, averagesales, maximumsale, minimumsale
*/
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
const int ROWS = 5;
const int COLS = 5;
double CalculateTotal(double data[][COLS]){
double sum = 0;
for (int i = 0; i<ROWS-1; i++){
for (int j = 0; j<COLS; j++){
sum = sum + data[i][j];
}
}
return sum;
}
double CalculateAverage(double data[][COLS]){
double sum = 0;
for (int i = 0; i<ROWS-1; i++){
for (int j = 0; j<COLS; j++){
sum = sum + data[i][j];
}
}
return sum/(ROWS * COLS);
}
double CalculateRowTotal(double data[][COLS], int r){
double sum = 0;
for (int i = 0; i<COLS-1; i++){
sum = sum + data[r][i];
}
return sum;
}
double CalculateColumnTotal(double data[][COLS], int c){
double sum = 0;
for (int i = 0; i<ROWS-1; i++){
sum = sum + data[i][c];
}
return sum;
}
double FindHighest(double data[][COLS]){
double max = 0;
for (int i = 0; i<ROWS-1; i++){
for (int j = 0; j<COLS-1; j++){
if (data[i][j] > max)
max = data[i][j];
}
}
return max;
}
double FindHighest(double data[][COLS], int &r, int &c){
double max = 0;
for (int i = 0; i<ROWS-1; i++){
for (int j = 0; j<COLS-1; j++){
if (data[i][j] > max){
max = data[i][j];
r = i;
c = j;
}
}
}
return max;
}
double FindLowest(double data[][COLS], int &r, int &c){
double min = 1000000;
for (int i = 0; i<ROWS-1; i++){
for (int j = 0; j<COLS-1; j++){
if (data[i][j] < min){
min = data[i][j];
r = i;
c = j;
}
}
}
return min;
}
int main(){
double data[ROWS][COLS];
string names[] = {"North","South","East","West", "Quarter Total"};
cout << "Enter four quarter sales figures for North:";
cin >> data[0][0] >> data[0][1] >> data[0][2] >> data[0][3];
cout << "Enter four quarter sales figures for South:";
cin >> data[1][0] >> data[1][1] >> data[1][2] >> data[1][3];
cout << "Enter four quarter sales figures for East:";
cin >> data[2][0] >> data[2][1] >> data[2][2] >> data[2][3];
cout << "Enter four quarter sales figures for West:";
cin >> data[3][0] >> data[3][1] >> data[3][2] >> data[3][3];
cout << left << setw(15) << " " << setw(10) << "Quarter 1";
cout << setw(10) << "Quarter 2" << setw(10) << "Quarter 3" << setw(10) << "Quarter 4";
cout << setw(10) << "Division Total" << endl;
for (int i = 0; i<ROWS-1; i++)
data[i][4] = CalculateRowTotal(data,i);
for (int i = 0; i<COLS-1; i++)
data[4][i] = CalculateColumnTotal(data,i);
for (int i = 0; i<ROWS; i++){
cout << left << setw(15) << names[i] << setw(10) << fixed << setprecision(2) << data[i][0];
cout << setw(10) << fixed << setprecision(2) << data[i][1];
cout << setw(10) << fixed << setprecision(2) << data[i][2];
cout << setw(10) << fixed << setprecision(2) << data[i][3];
cout << setw(10) << fixed << setprecision(2) << data[i][4] << endl;
}
cout << "Total Sales:" << fixed << setprecision(2) << CalculateTotal(data) << endl;
cout << "Average Sales:" << fixed << setprecision(2) << CalculateAverage(data) << endl;
int r, c;
double max = FindHighest(data,r,c);
cout << "The highest sales is " << fixed << setprecision(2) << max << " done by " << names[r] << " division in Quarter " << (c+1) << endl;
double min = FindLowest(data,r,c);
cout << "The lowest sales is " << fixed << setprecision(2) << max << " done by " << names[r] << " division in Quarter " << (c+1) << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.