asked 119k views
4 votes
/*

* This program prompts the user for quarterly sales figures,
* computes the total sales for the year and the average sales
* per quarter and month.
*/
// write the required include and using statements


// declare a method named getSales which returns a double
// and has no parameters

// declare a method named computeTotal which returns
// a double and has four doubles as parameter

// declare a method named computeQuarterAvg which returns
// a double and has a double as parameter

// declare a method named computeMonthlyAvg which returns
// a double and has a double as parameter

// Declare a method named printData which has no parameters or return value

// Declare a method named personalInfo which has no parameters or return value

int main()
// call the printData method

// call the personalInfo method

system("pause"); // For Visual Studio only!
return 0;


// The getSales method has no parameters and returns a double.
// This method uses the static integer variable quarter, which
// is initialized to 1 and incremented before the return statement.
// The method uses the local double variable sales, initialized to 0,
// to store the value entered by the user.
// The method prompts the user for quarterly sales using the phrase
// "Enter the sales for Quarter #[quarter]: ", stores the value in sales,
// and returns the value of sales.


// The computeTotal function receives 4 doubles as parameters and
// returns a double. Use the label q1, q2, q3, and q4 for the parameters.
// The function computes the total of the values by adding them, and returns
// the value. No variables are declared in this method.


// The computeQuarterAvg function receives a double as parameter and
// returns a double. Use the label yearlySales for the parameter. The
// function computes the average sales per quarter by dividing the total
// sales for the year by 4 and returns the value. No variables are
// declared in this method.


// The computeMonthlyAvg function receives a double as parameter and
// returns a double. Use the label yearlySales for the parameter. The
// function computes the average sales per month by dividing the total
// sales for the year by 12 and returns the value. No variables are
// declared in this method.


// The printData method has no parameters or return value. Four local
// double variables are declared, quarter1, quarter2, quarter3, and
// quarter4, all of which are initialized to the return value of the
// getSales method. The method then prints the phrase "The total sales
// for the year were [total sales], with a quarterly average of
// [average per quarter], and a monthly average of [monthly average]"


// The personalInfo method prints a statement with your personal information using
// the phrase "***** Program developed by [YOUR NAME], ID# [YOUR ID NUMBER] *****"
// where the square brackets and the text within is substituted with your personal
// information. Make sure to add a blank line before and after the phrase is printed.

1 Answer

2 votes

Answer:

#include <iostream>

using namespace std;

double getSales();

double computeTotal(double q1, double q2, double q3, double q4);

double computeQuarterAvg(double yearlySales);

double computeMonthlyAvg(double yearlySales);

void printData();

void personalInfo();

int main() {

printData();

personalInfo();

system("pause");

return 0;

}

double getSales() {

static int quarter = 1;

double sales = 0;

cout << "Enter the sales for Quarter #" << quarter << ": ";

cin >> sales;

quarter++;

return sales;

}

double computeTotal(double q1, double q2, double q3, double q4) {

return q1 + q2 + q3 + q4;

}

double computeQuarterAvg(double yearlySales) {

return yearlySales / 4;

}

double computeMonthlyAvg(double yearlySales) {

return yearlySales / 12;

}

void printData() {

double quarter1 = getSales();

double quarter2 = getSales();

double quarter3 = getSales();

double quarter4 = getSales();

double totalSales = computeTotal(quarter1, quarter2, quarter3, quarter4);

double quarterAvg = computeQuarterAvg(totalSales);

double monthlyAvg = computeMonthlyAvg(totalSales);

cout << "The total sales for the year were " << totalSales << ", with a quarterly average of "

<< quarterAvg << ", and a monthly average of " << monthlyAvg << endl;

}

void personalInfo() {

cout << endl;

cout << "***** Program developed by [YOUR NAME], ID# [YOUR ID NUMBER] *****" << endl;

cout << endl;

}

Step-by-step explanation:

Here's the complete code that incorporates the provided instructions:

```cpp

#include <iostream>

using namespace std;

double getSales();

double computeTotal(double q1, double q2, double q3, double q4);

double computeQuarterAvg(double yearlySales);

double computeMonthlyAvg(double yearlySales);

void printData();

void personalInfo();

int main() {

printData();

personalInfo();

system("pause");

return 0;

}

double getSales() {

static int quarter = 1;

double sales = 0;

cout << "Enter the sales for Quarter #" << quarter << ": ";

cin >> sales;

quarter++;

return sales;

}

double computeTotal(double q1, double q2, double q3, double q4) {

return q1 + q2 + q3 + q4;

}

double computeQuarterAvg(double yearlySales) {

return yearlySales / 4;

}

double computeMonthlyAvg(double yearlySales) {

return yearlySales / 12;

}

void printData() {

double quarter1 = getSales();

double quarter2 = getSales();

double quarter3 = getSales();

double quarter4 = getSales();

double totalSales = computeTotal(quarter1, quarter2, quarter3, quarter4);

double quarterAvg = computeQuarterAvg(totalSales);

double monthlyAvg = computeMonthlyAvg(totalSales);

cout << "The total sales for the year were " << totalSales << ", with a quarterly average of "

<< quarterAvg << ", and a monthly average of " << monthlyAvg << endl;

}

void personalInfo() {

cout << endl;

cout << "***** Program developed by [YOUR NAME], ID# [YOUR ID NUMBER] *****" << endl;

cout << endl;

}

```

In this code, the provided instructions are implemented as follows:

- The `getSales` function prompts the user for quarterly sales figures and returns the entered value. It uses a static integer variable `quarter` to keep track of the current quarter.

- The `computeTotal` function takes four doubles as parameters and returns the sum of those values.

- The `computeQuarterAvg` function takes the yearly sales as a parameter and returns the average sales per quarter (yearly sales divided by 4).

- The `computeMonthlyAvg` function takes the yearly sales as a parameter and returns the average sales per month (yearly sales divided by 12).

- The `printData` function calls `getSales` four times to get the sales for each quarter, computes the total sales, quarterly average, and monthly average using the other functions, and prints the results.

- The `personalInfo` function prints a statement with your personal information. You need to replace `[YOUR NAME]` and `[YOUR ID NUMBER]` with your actual name and ID number.

The `main` function calls `printData` and `personalInfo` functions accordingly and includes the necessary headers and using statements.

Make sure to replace `[YOUR NAME]` and `[YOUR ID NUMBER]` in the `personalInfo` function with your actual name and ID number before running the program.

answered
User Liam G
by
7.3k points