Help.
Write a C++ program that determines which of a company's four
divisions (North, South, East, West) has the greatest sales for the
quarter. It should include three functions at a minimum:
float getSales() is passed the name of a division. It asks the user for a division's quarterly sales figure, calls a validate() function that will validate the input, and then returns the value back to main(). This function should be called once for each division.
void validate() is called from the getSales() function to ensure the input value is not negative nor has character input. If invalid input is found, loop until the user enters a valid value. It will then return to getSales().
void findHighest() is passed the four sales totals. It determines which is the largest value and prints the name of the high grossing division along with its sales figure
// C++ program that determines which of a company's four divisions (North, South, East, West) has the greatest sales for the quarter.
#include <iostream>
#include <limits>
#include <iomanip>
using namespace std;
// function declaration
float getSales(string name);
void validate(float &sales);
void findHighest(float northSales, float southSales, float eastSales, float westSales);
int main() {
float northSales,southSales,eastSales,westSales;
// get the quarterly sales for the divisions
northSales = getSales("North");
southSales = getSales("South");
eastSales = getSales("East");
westSales = getSales("West");
// find the division with the highest sales
findHighest(northSales,southSales,eastSales,westSales);
return 0;
}
// function to get the quarterly sales for the passed division
float getSales(string name)
{
float sales;
cout<<"\n Enter the quarterly sales for "<<name<<" division : ";
validate(sales);
return sales;
}
// function to validate the input and return valid input
// argument is passed by reference
void validate(float &sales)
{
cin>>sales;
// in case of input error (sales negative or out of range)
while(cin.fail() || sales < 0)
{
cin.clear(); // clears the error flags
cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n'); // and remove the bad input
cout<<" Invalid sales. Enter quarterly sales : ";
cin>>sales;
}
}
// function to determine and print the division with the highest sales
void findHighest(float northSales, float southSales, float eastSales, float westSales)
{
string highestName = "North";
float highestSales = northSales;
if(southSales > highestSales)
{
highestSales = southSales;
highestName = "South";
}
if(eastSales > highestSales)
{
highestSales = eastSales;
highestName = "East";
}
if(westSales > highestSales)
{
highestSales = westSales;
highestName = "West";
}
cout<<"\n Highest grossing division : "<<highestName<<" Sales figure : "<<highestSales<<endl;
}
//end of program
Output:
Help. Write a C++ program that determines which of a company's four divisions (North, South, East,...
Write a program that determines which of a company's eight divisions (North, South, East, West, Northeast, Southeast, Northwest, Southwest) had the greatest sales for a quarter. It should include the following two functions which are called only by main. double getSales() - it is passed the name of a division. It asks the user for a division's quarterly sales figure, validates the input then returns it. It should be called once for each division. Negative dollar amounts are invalid. void...
C++ Write a program that determines which of the 6 states had the most traffic tickets last year. The 6 states are California, Georgia, Alabama, Illinois, Michigan, and Florida. The program should have the following 2 functions, which are called by main. Int getNumTickets () is passed the name of the state. It asks the user for the number of traffic tickets reported during last year, validates the input and then returns it. It should be called once for each...
c plus plus determines which of 5 geographic regions within a major city north south east west and central had the fewest reported traffic accidents last year it should have the following function which are called by main int get NumAccidents is passed the name of a region it asks the user for the number of traffic accidents reported in that region during the last year validates the input then returns it. it should be called once for each city...
guys need help please im super lost anyone save me do programming exercise top_div_array.cpp: Winning Division app (top_div.cpp) revisited to use arrays This is the same program done last week but using and passing arrays instead of individual variables. Start with the following file / cODE BELOW: // Name: top_div_array.cpp // Description: // This app inputs sales for four regional division and displays the highest. // To accomplish this, use two arrays of equal length - one for sales and...
Have Corporate Sales for 6 divisions and their quarterly sales figures. The issue is the error function where I am unable to have user reinput the same quarterly amount without going to the next quarter input. This has affected the total sales for the company. /***************************************** This program gathers sales information for six divisions and displays the total sales for each division and total company. *****************************************/ #include<iostream> using namespace std; // Classs division sales class DivSales { private: // Variables...
Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( ); // constructor ~Salesperson( ); // destructor Salesperson(double q1, double q2, double q3, double q4); // constructor void getsales( ); // Function to get 4 sales figures from user void setsales( int quarter, double sales); // Function to set 1 of 4 quarterly sales // figure. This function will be called // from function getsales ( ) every time a // user enters a sales...
C++ and Using Microsoft Visual Studio. Write 2 programs: One program will use a structure to store the following data on a company division: Division Name (East, West, North, and South) Quarter (1, 2, 3, or 4) Quarterly Sales The user should be asked for the four quarters' sales figures for the East, West, North, and South divisions. The data for each quarter for each division should be written to a file. The second program will read the data written...
Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...
I need help with this c++ question please
thank you
ltls. The program should urt valte. 11. Lowest Score Drop Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions: void getscore() should ask the user for a test score, store it in a reference param- eter variable, and validate it. This function should be called by main once for each of...
C Programming QUESTION 9 Write a program that prompts for and reads four integer input values, then a single character command. Submit your program as a .c file named midterm_prog2.c. Note that, similarly to your programming assignments, some percentage of your grade will depend on proper programming style. Your program will calculate and print a new value based on the command that's entered, as follows: 'A' or 'a': Calculate the average of the four input values 'S' or 's': Calculate...