I need help trying to adjust my program to look like the sales report. Any suggestions on how to approach this.
Prompt:
Use a single-subscripted array to solve the following problem: A company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who grosses $5000 in sales in a week receives $200 plus 9% of $5000 or a total of $650. Write a program (using an array of counters) that determines how many of the salespeople earned salaries in each of the following ranges (assume that each salesperson’s salary is truncated to an integer amount):
a) $200-$299
b) $300-$399
c) $400-$499
d) $500-$599
e) $600-$699
f) $700-$799
g) $800-$899
h) $900-$999
i) $1000 and over
Summarize the results in tabular format.
Have a .cpp and a Salesreport.h that contains the Sales.
Requirements:
1. Create a class named SalesReport with the array of counters as the class member data.
2. Write an integer function that returns the salary with the gross sales as the function argument.
3. Write a void function that takes the salary as the function argument and increase the appropriate array elements.
Sample Run:
Enter a sales amount: (negative to end):1000
Enter a sales amount: (negative to end):3000
Enter a sales amount: (negative to end):3000
Enter a sales amount: (negative to end):5000
Range Number
$200-299 1
$300-399 0
$400-499 2
$500-599 0
$600-699 1
Here is what I have so far: A main.cpp and a Sales.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
Main.cpp
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
#include "Sales.h"
using namespace std;
using std::cout;
using std::cin;
using std::endl;
Salesperson::Salesperson(double gross_sales_arg)
: grossSales {gross_sales_arg}
{}
double Salesperson::getGrossSales()
{
return grossSales;
}
//setter method
void Salesperson::setGrossSales(double sales)
{
if(sales != -1)
{
grossSales = sales;
}
}
// calculate and return the salary using gross_sales
double Salesperson::findSalary()
{
return (0.09 * grossSales) + 200; //salary calculation
}
void waittoEnter();
int main()
{
double week_sales = 0.0;
while(week_sales != -1)
{
std::cout << "Please enter sales in dollars (-1 to end): ";
std::cin >> week_sales; //input
std::cin.ignore(1); //helps to ignore next line
if(week_sales == -1)
{
break;
}
Salesperson spers(week_sales);//salesperson object
std::cout << "salary is " << std::fixed << std::setprecision(2)
<< spers.findSalary() << '\n';//precision requirement
}
waittoEnter();
return 0;
}
//this function makes sure to allow enter to continue
void waittoEnter()
{
std::cout << "\nPress enter to continue...\n";
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
Sales.h
#ifndef SALES
#define SALES
class Salesperson {
public:
//calling methods
Salesperson(double gross_sales_arg = 0.0);//type cast
double getGrossSales();
void setGrossSales(double sales);
double findSalary();
private:
double grossSales= 0.0;
};
#endif // SALESPERSON
|