Question

In: Computer Science

C++ Program A company pays its salespeople on a commission basis.  The salespeople each receive $250 per...

C++ Program

A company pays its salespeople on a commission basis.  The salespeople each receive $250 per week plus 11 percent of their gross sales for the sales period.  For example, a salesperson who grosses $5000 in sales in the period receives $250 plus 11 percent of $5000, or a total of $812.21.  Write a program (using an array of counters) determines for each salesperson their total sales, their salary and additional data points.  There are 12 salesmen for the company.  The input data file is "SalesPerson SalesV3.txt". It contains the salesperson number (3 digit id) followed by his sales.   Each salesperson has numerous sales listed for the period.  You will need to keep up with the total number of sales and of course the total sales per salesman.

Output :  

             1. Print out the Sales report showing the salesmen ID, his total number of sales, his total sales      
and his average per sale.  Show the report in sorted ordered by Sales ID.

    2.  Print out the same report but this time print out in sorted ordered by total sales.

    3.  Print out the same report again sorted on average sales.

The company is looking at a reduction in sales force.  So I need to know which salesman had the smallest total sales.  Print out the worsted salesman, his total sales and percentage of his sales compared to the second worsted salesman.  (Just to see how off his sales really are compared to one other. ie did he have a bad sales period or he is really a bad salesman.)

SalesPerson SalesV3.txt

322 10.80
848 920.00
828 1267.00
848 8320.00
229 66330.00
254 6670.00
689 520.00
691 4880.00
828 3860.00
848 2820.00
229 7848.00
828 60.00
848 820.00
229 8115.00
546 1280.00
828 660.00
848 320.00
190 325.00
828 263.00
848 9315.00
828 3860.00
848 2093.00
322 4225.00
254 960.00
689 220.00
691 436.00
322 4210.00
689 520.00

Solutions

Expert Solution

#include<bits/stdc++.h>
#include<fstream>
using namespace std;

bool mysort(pair<int,float> p1, pair<int,float> p2){
return p1.second > p2.second;
}

struct Salesman{
int id = 0;
int total_sales = 0;
float sales_amount = 0;
float average = 0;

int getId(){return id;}
int getTotalSales(){return total_sales;}
float getSalesAmount(){return sales_amount;}
float getAverage(){return average;}

void setId(int id){id = id;}
void setTotalSales(int sales){
   total_sales = sales;
   }
void setSalesAmount(float amount){
       sales_amount = amount;
}
void setAverage(float avg){
       average = avg;
}
};

struct find_salesman : unary_function<Salesman,bool>{
int id;
find_salesman(int id) : id(id) {}
bool operator () ( const Salesman& s ) const{
return s.id == id;
}
};

bool sort1(Salesman s1, Salesman s2){
return s1.getId() < s2.getId();
}

bool sort2(Salesman s1, Salesman s2){
return s1.getTotalSales() > s2.getTotalSales();
}

bool sort3(Salesman s1, Salesman s2){
return s1.getAverage() > s2.getAverage();
}

int main(){

   // Reading the sales report
   string line;
ifstream myfile("Sales Person SalesV3.txt");
vector<Salesman> salesmen(1000);
map<int,float> sales_stats;                   // This map will store Salesman Id vs His Total Sales amount
map<int,int> sales_count;                   // This map will store Salesman Id vs No. of Sales
vector<int> s1, s2;
if(myfile.is_open()){
       while(getline(myfile,line)){
           istringstream iss(line);           // Reading each record line
           int val = 0;                       // Storing Employee ID
           float stat = 0;                       // Storing Employee Sale Amount
           string s;
           int count = 0;
while(getline(iss,s,' ')){
if(count==0)                   // Count 0 signifies 1st value of map, which is employee Id
val = stoi(s);
if(count==1)                   // Count 1 signifies 2nd value of map, which is Sales Amount
stat = stof(s);
count++;
}
auto it = find_if(salesmen.begin(), salesmen.end(), find_salesman(val));
if(it==salesmen.end()){
Salesman salesman = {val,1,stat,stat};
// The 3rd parameter can be changed to 250 + 0.11*stat (For required case)
salesmen.push_back(salesman);
}
           else{
               it->setId(val);
it->setTotalSales(it->getTotalSales()+1);
it->setSalesAmount(it->getSalesAmount() + stat);
it->setAverage(it->getSalesAmount()/it->getTotalSales());
           }
       }
myfile.close();
}
else{
       cout<<"\nUnable to open file or file doesn't exist";
}

   // Printing 1st Report - Ordered by Salesman ID

sort(salesmen.begin(),salesmen.end(),sort1);
   cout<<"\nReport 1 Ordered By Salesman ID\n";
cout<<"\n ID | Sales | Total Sales | Average per Sale |";
for(auto it=salesmen.begin();it!=salesmen.end();it++){
if(it->getId()!=0){
           cout<<"\n "<<it->getId()<<" | "<<(it->total_sales)<<"\t|\t"
           <<(it->sales_amount)<<"\t|\t"<<(it->average)<<"\t |";
}
}

sort(salesmen.begin(),salesmen.end(),sort2);

   // Printing 2nd Report - Ordered by Total Sales
   cout<<"\n\nReport 2 Ordered by Total Number of Sales\n";
cout<<"\n ID | Sales | Total Sales | Average per Sale |";
for(auto it=salesmen.begin();it!=salesmen.end();it++){
if(it->getId()!=0){
           cout<<"\n "<<it->getId()<<" | "<<(it->total_sales)<<"\t|\t"
           <<(it->sales_amount)<<"\t|\t"<<(it->average)<<"\t |";
}
}


   // Printing 3rd Report - Ordered by Average Sales
sort(salesmen.begin(),salesmen.end(),sort3);
   cout<<"\n\nReport 3 - Ordered by Average\n";
cout<<"\n ID | Sales | Total Sales | Average per Sale |";
for(auto it=salesmen.begin();it!=salesmen.end();it++){
if(it->getId()!=0){
           cout<<"\n "<<it->getId()<<" | "<<(it->total_sales)<<"\t|\t"
           <<(it->sales_amount)<<"\t|\t"<<(it->average)<<"\t |";
}
}


}


Related Solutions

A company pays its salespeople on a commission basis. The salespeople each receive $250 per week...
A company pays its salespeople on a commission basis. The salespeople each receive $250 per week plus 11 percent of their gross sales for the sales period. For example, a salesperson who grosses $5000 in sales in the period receives $250 plus 11 percent of $5000, or a total of $812.21. Write a program (using an array of counters) determines for each salesperson their total sales, their salary and additional data points. There are 12 salesmen for the company. The...
A company pays its five salespeople on a commission basis. The salespeople receive $200 plus 10%...
A company pays its five salespeople on a commission basis. The salespeople receive $200 plus 10% of their sale. For example, for the employee sale of $1000, the commission is $300. Write a C program that: inputs each employee sales. The program then calculates the employee commission, prints out each employee commission. The program calculates the total sum of all commissions paid, and print. Your program will use a sentinel value to exit. You must use a one-dimensional array for...
A company pays its salespeople on a commission basis. The salespeople are paid $200 per week...
A company pays its salespeople on a commission basis. The salespeople are paid $200 per week plus 9% of their gross sales for that week. For example, a salesperson who sells $5000 worth of merchandise in a week is paid $200 plus 9% of $5000, for a weekly pay of $650. Create an application that uses a for loop to input each sales person’s gross sales for the week, and calculates and displays that sales person’s weekly pay. Process one...
C++ Program (Using 2D array and bubble sort to sort data) A company pays its salespeople...
C++ Program (Using 2D array and bubble sort to sort data) A company pays its salespeople on a commission basis.  The salespeople each receive $250 per week plus 11 percent of their gross sales for the sales period.  For example, a salesperson who grosses $5000 in sales in the period receives $250 plus 11 percent of $5000, or a total of $812.21.  Write a program (using an array of counters) determines for each salesperson their total sales, their salary and additional data points.  There...
First The sales department of a cellular phone company pays its salespeople $1,500 per month plus...
First The sales department of a cellular phone company pays its salespeople $1,500 per month plus 25 percent of each new subscriber’s first month’s billings. A new subscriber’s first-month bill averages $80. Salespeople work 160 hours a month (four weeks at 40 hours per week). If salespeople work more than 160 hours per month, they receive $12 per hour for hours in excess of 160. Sales leads for the sales department are generated in a variety of ways—direct mailings to...
Program for C++ A company has six salespeople. Every month, they go on road trips to...
Program for C++ A company has six salespeople. Every month, they go on road trips to sell the company’s product. At the end of each month, the total sales for a salesperson in that month, together with that salesperson’s ID and the month, is recorded in a file. At the end of each year, the manager of the company wants to see an annual sales report. Due to the amount of data involved, he’s like to be able to view...
Glade, Inc. is trying to decide whether to increase the commission-based pay of its salespeople. Currently,...
Glade, Inc. is trying to decide whether to increase the commission-based pay of its salespeople. Currently, each of its five salespeople earns a 6% commission on the units they sell for $100 each, plus a fixed salary of $41,200 per person. Glade hopes that by increasing commissions to 11% and decreasing each salesperson’s salary to $21,200, sales will increase because salespeople will be more motivated. Currently, sales are 20,000 units. Glade’s other fixed costs, NOT including the salespeople’s salaries, total...
Glade, Inc. is trying to decide whether to increase the commission-based pay of its salespeople. Currently,...
Glade, Inc. is trying to decide whether to increase the commission-based pay of its salespeople. Currently, each of its five salespeople earns a 9% commission on the units they sell for $100 each, plus a fixed salary of $40,200 per person. Glade hopes that by increasing commissions to 14% and decreasing each salesperson’s salary to $21,100, sales will increase because salespeople will be more motivated. Currently, sales are 20,000 units. Glade’s other fixed costs, NOT including the salespeople’s salaries, total...
Glade, Inc. is trying to decide whether to increase the commission-based pay of its salespeople. Currently,...
Glade, Inc. is trying to decide whether to increase the commission-based pay of its salespeople. Currently, each of its five salespeople earns a 12% commission on the units they sell for $100 each, plus a fixed salary of $41,900 per person. Glade hopes that by increasing commissions to 17% and decreasing each salesperson’s salary to $21,600, sales will increase because salespeople will be more motivated. Currently, sales are 20,000 units. Glade’s other fixed costs, NOT including the salespeople’s salaries, total...
Glade, Inc. is trying to decide whether to increase the commission-based pay of its salespeople. Currently,...
Glade, Inc. is trying to decide whether to increase the commission-based pay of its salespeople. Currently, each of its five salespeople earns a 7% commission on the units they sell for $100 each, plus a fixed salary of $40,100 per person. Glade hopes that by increasing commissions to 12% and decreasing each salesperson’s salary to $21,500, sales will increase because salespeople will be more motivated. Currently, sales are 17,000 units. Glade’s other fixed costs, NOT including the salespeople’s salaries, total...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT