This program should calculate which division in a company had the greatest sales
ID: 3725822 • Letter: T
Question
This program should calculate which division in a company had the greatest sales for a quarter. It should use the following functions:
A function should ask the user for and return the quarterly sales figures for the company's Northeast, Southeast, Northwest, and Southwest divisions.
A function should determine which division had the highest sales figures.
A message should be displayed indicating the leading division and its sales figures for the quarter.
Input Validation: Do not accept dollar amounts less than $0.00.
Additional note: The following code for the main function is a required starting point. Create the functions and corresponding prototypes to make this work.
//declare the function prototypes here (before 'main', as explained in the book)
#include <iostream>
#include <string>
int main()
{
float nE, sE, nW, sW;
nE = input_div( "North East" );
sE = input_div( "South East" );
nW = input_div( "North West" );
sW = input_div( "South West" );
findHighest(nE, sE, nW, sW); //prints the result also
return 0;
}
//************ subroutine definitions below *******************
float input_div( string name)
{
Code inputs dollar value for given division and returns it
(Use a while or do/while loop for validation)
}
Note: this function receives the name of the division
('NorthEast', 'SouthEast', etc.) under 'name', which will appear on the prompt
for its sales input.
void findHighest ( receiving 4 'float' types )
{
Code determines the biggest of 4 floats and
prints the result to the screen.
Note: No need to worry about duplicates in this exercise.
Though, there is a 1 point extra credit for implementing
duplicate top divisions - make it clear in the header comments that this was done.
}
Pseudocode for findHighest(). Use extra variables
to keep track of the highest value and its corresponding name. Assign these
variables the first values of the data and continue checking for and updating
the highest data, like this:
highest = nE
name = "North East"
if sE > highest then
highest = sE
name = "South East"
if nW > highest then
highest = nW
name = "North West"
if sW > highest then
highest = sW
name = "South West"
cout "the highest is " name "with" highest
return 0;
}
(but do use two decimals)
Explanation / Answer
#include <iostream> // #include<iostream.h> when using MS DOS Turbo C++ as compiler
#include <string> // #include<string.h> when using MS DOS Turbo C++ as compiler
float input_div(char[]); // function prototype
void findHighest(float, float, float, float); // function prototype
int main()
{
float nE, sE, nW, sW;
nE = input_div( "North East" );
sE = input_div( "South East" );
nW = input_div( "North West" );
sW = input_div( "South West" );
findHighest(nE, sE, nW, sW); // to find and print the result
return 0;
}
float input_div( char name[10] )
{
float sales_amount;
cout << "Enter the quarter sales for the " << name << " division:" <<" $";
cin >> sales_amount;
while ( sales_amount < 0 ) // loop for validation
{
cout << " -- Sales amount should be a positive value -- ";
cout << "Enter the quarter sales for the " << name << " division:" <<" $";
cin >> sales_amount;
}
return sales_amount;
}
void findHighest(float nE, float sE, float nW, float sW ) // function to find the highest sales
{
float highest;
char name[10] = "North East";
highest = nE;
if (sE > highest)
{
highest = sE;
strcpy (name,"South East"); // using strcpy function from header <string.h>
}
if (nW > highest)
{
highest = nW;
strcpy (name,"North West"); // using strcpy function from header <string.h>
}
if (sW > highest)
{
highest = sW;
strcpy (name,"South West"); // using strcpy function from header <string.h>
}
cout << " The highest is " << name << " division with $" << highest;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.