Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify the code to use functions. Create a getInput function, a calcTotal functi

ID: 3718832 • Letter: M

Question

Modify the code to use functions. Create a getInput function, a calcTotal function and a displayResults function. The purpose of getInput is to prompt the user for input and assign values to the 2D array. The purpose of the caclTotal function is to process the 2D Array and accumulate the total sales. The purpose of the displayResults functionn is to display the entire 2D array for quarterly sales as well as the total sales. The main function should consist of variable declarations and function calls. Do not use global variables. Pass the data through functions parameters or value returning functions. Please help. Answer in C++ please.

2 #include 3 #include 4 using namespace std; 6 int main() const int NUM_DIVS 3 const int NUM QTRS 4 double sales[NUM-DIVS?NUM-QTRS); // Array with 3 rows and 4 columns. double totalSales- int div, qtr; // Number of divisions // Number of quarters // To hold the total sales. // Loop counters. 13 14 cout

Explanation / Answer

Solution:

The methods are given below, please let me know if any of them didn't work.

getInput(double sales[][qtr], int div, int qtr)

{

for(int i= 0; i<div; i++)

{

for(int j= 0; j<qtr; j++)

{

cin>>sales[i][j];

}

}

return;

}

double calcTotal (double sales[][qtr], int div, int qtr)

{

double sumQtr[4]= 0, sumTotal= 0;

for(int i= 0; i<qtr; i++)

{

for(int j= 0; j<div; j++)

{

sumQtr[i]+= sales[i][j];

}

}

for(int i= 0; i<qtr; i++)

sumTotal+= sumQtr[i];

displayResult(sumQtr, sumTotal); //Display result should be called from here

}

void displayResult(double *quarter, double total)

{

cout<<"Quarterly sales total: ";

for(int i= 0; i<4; i++)

{

cout<<<<quarter[i]<<endl;

}

cout<<"Total sales is: "<<total;

}

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote