Question

In: Computer Science

Write a program that determines which of the company’s four divisions (Northeast, Southeast, Northwest, and Southwest)...

Write a program that determines which of the company’s four divisions (Northeast, Southeast, Northwest, and Southwest) had the greatest sales for the quarter. It should include the following two functions, which are called by main.

Rewrite the “getSales” function in the “winning division”program.

The function has no return value;

◦The function accepts one reference variable to a double and one string variable as arguments.

◦Your program still needs to call getSalesfour times for each division to get their quarterly sales figures.

This is the code I have so far.


#include <iostream>
#include <string>
using namespace std;

//Prototypes
double getSales(string, double&);
void findHighest(double, double, double, double);

int main()
{
   //Variables for each division's sales
   double NE_sales, SE_sales, NW_sales, SW_sales;
   double s1, s2, s3, s4;

   //Getting the values for each division's sales
   NE_sales = getSales("Northeast", s1);
   SE_sales = getSales("Southeast", s2);
   NW_sales = getSales("Northwest", s3);
   SW_sales = getSales("Southwest", s4);

   //Finding the highest sales
   findHighest(NE_sales, SE_sales, NW_sales, SW_sales);

   system("pause");

   return 0;
}

//Getting sales for each division
double getSales(string name, double &salesRef)
{
   double sales;

   cout << "Please enter the sales for " << name << " division: ";
   cin >> sales;

   //Input validation
   while (sales < 0)
   {
       cout << "Please enter a positive number for the sales for " << name << " division: ";
       cin >> sales;
   }
   salesRef = sales;
   //Returning sales for this division
   return sales;
}

//Finding highest sales
void findHighest(double divNE, double divSE, double divNW, double divSW)
{
   double maxSales;

   //Comparing each division
   maxSales = max(max(max(divNE, divSE), divNW), divSW);

   cout << endl;

   //Outputting result once max is known
   if (maxSales == divNE)
       cout << "The Northeast division grossed the most with a total of $" << divNE << endl;
   else if (maxSales == divSE)
       cout << "The Southeast division grossed the most with a total of $" << divSE << endl;
   else if (maxSales == divNW)
       cout << "THe Northwest division grossed the most with a total of $" << divNW << endl;
   else
       cout << "The Southwest division grossed the most with a total of $" << divSW << endl;

   return;
}


I don't know if I did the reference variable right or how to make the function have no return value.

Solutions

Expert Solution

Solution:

Code implementation:

#include <iostream>
#include <string>
using namespace std;

//Prototypes
double getSales(string, double&);
void findHighest(double, double, double, double);

int main()
{
//Variables for each division's sales
double s1, s2, s3, s4;

//Getting the values for each division's sales, now s1,s2,s3,s4 will be updated with the values entered by user.
getSales("Northeast", s1);
getSales("Southeast", s2);
getSales("Northwest", s3);
getSales("Southwest", s4);

//Finding the highest sales
findHighest(s1,s2,s3,s4);

//system("pause");

return 0;
}

//Getting sales for each division
double getSales(string name, double &salesRef)
{
double sales;

cout << "Please enter the sales for " << name << " division: ";
cin >> sales;

//Input validation
while (sales < 0)
{
cout << "Please enter a positive number for the sales for " << name << " division: ";
cin >> sales;
}
cout<<sales<<endl;
salesRef = sales; // return statement not required.
}

//Finding highest sales
void findHighest(double divNE, double divSE, double divNW, double divSW)
{
double maxSales;

//Comparing each division
maxSales = max(max(max(divNE, divSE), divNW), divSW);

cout << endl;

//Outputting result once max is known
if (maxSales == divNE)
cout << "The Northeast division grossed the most with a total of $" << divNE << endl;
else if (maxSales == divSE)
cout << "The Southeast division grossed the most with a total of $" << divSE << endl;
else if (maxSales == divNW)
cout << "THe Northwest division grossed the most with a total of $" << divNW << endl;
else
cout << "The Southwest division grossed the most with a total of $" << divSW << endl;

return;
}

Code screenshot:

Code Input and output screenshot:


Related Solutions

write a c++ program an expression that determines if an integer, n is a negative four...
write a c++ program an expression that determines if an integer, n is a negative four digit number. write a c++ program an expression that determines if a string, wd, equals "so" ignoring case.
Write a program that determines the best possible meeting time for four people. The possibilities for...
Write a program that determines the best possible meeting time for four people. The possibilities for meeting times are 8:00-12:00, 12:00-18:00 or 18:00-23:00. You should begin by asking the first user to choose a meeting time. The user should enter the number 1 for the 8:00-12:00 meeting time, the number 2 for the 12:00-18:00 meeting time, or the number 3 for the 18:00-23:00 meeting time
PYTHON PROGRAM: Write a program that determines the day of the week for any given calendar...
PYTHON PROGRAM: Write a program that determines the day of the week for any given calendar date after January 1, 1900, which was a Monday. This program will need to account for leap years, which occur in every year that is divisible by 4, except for years that are divisible by 100 but are not divisible by 400. For example, 1900 was not a leap year, but 2000 was a leap year.
Write a program that determines a student’s grade. The program will read three types of scores...
Write a program that determines a student’s grade. The program will read three types of scores (quiz, mid-term, and final scores) and determine the grade based on the following rules: -if the average score =90% =>grade=A -if the average score >= 70% and <90% => grade=B -if the average score>=50% and <70% =>grade=C -if the average score<50% =>grade=F Using Switch Statement Need to code to be simple to understand. No pointers should be used
Write a program in JAVA that takes in two words, and then it recursively determines if...
Write a program in JAVA that takes in two words, and then it recursively determines if the letters of the first word are contained, in any order, in the second word. If the size of the first word is larger than the second then it should automatically return false. Also if both strings are empty then return true. YOU MAY NOT(!!!!!!!!!!): Use any iterative loops. In other words, no for-loops, no while-loops, no do-while-loops, no for-each loops. Use the string...
Write a program that determines whether an input string is a palindrome; that is, whether it...
Write a program that determines whether an input string is a palindrome; that is, whether it can be read the same way forward and backward. At each point, you can read only one character of the input string; do not use an array to first store this string and then analyze it (except, possibly, in a stack implementation). Consider using multiple stacks. In Pseudocode please
Write a program in PYTHON that determines the cost of painting the walls of a windowless...
Write a program in PYTHON that determines the cost of painting the walls of a windowless room. There is one door and it will be painted the same color as the walls. The problem requires a main function and two custom functions that are imported from a custom module that you create. In main, the program should prompt the user for five inputs shown in blue in the Sample Output below: the length, width, and height of the room in feet. the...
I am trying to write a java program that determines if an inputted year is a...
I am trying to write a java program that determines if an inputted year is a leap year or not, but I am not able to use if else statements how would I do it. I don't need the code just advice.
Write a program that determines the change to be dispensed from a vending machine. An item...
Write a program that determines the change to be dispensed from a vending machine. An item in the machine can cost between 25 cents and 1 dollar, in 5-cents increments (25, 30, 35, . . . 90, 95, or 100), and the machine accepts only a single dollar bill to pay for the item. (Explain with algorithms if you can please!)
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT