Question

In: Computer Science

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 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.)

We are still in the beginning stages so we cannot use vectors, pointers, or functions from a library. Please be as verbose as possible, I am still very new.

Our teacher mentioned a method to do this using a 1D array, but on this assignment we have to use a 2D array, 12x4.

His method is: infile>>ID>>sales; //these variables are arrays

subscript=searchInsert(ID, Sales); //everytime you read in an ID and sales, the function searches if that number has already been saved in the array.

sales[subscript]=sales[subscript] + sale; //returns the subscript number and updates the sold amount for that employee ID number.

I have written my print header functions, my average function, and my sort function already. We are required to use a bubble sort to sort by employee number, average sales, etc.

Sample input, left is the ID Number and right is the sale they made.

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

Some of my code so far:

//my search function

float testSearch(float sales[][4], int ID_Num, int rowNum) //for row that you are on, for column 0, if sales of that
//row==ID number you sent, return the sub
{
int r, c;
for(r=0;r<=rowNum;r++)
{
for(c=0;c<1;c++)
{
if (sales[r][c]==ID_Num)
{
return r;
}

}
}
}

for(r=0;r<13;r++) //reading the files in
{
for(c=0;c<=1;c++)
{
infile>>sales[r][c];
ID_Num=sales[r][0];
sub=testSearch(sales, ID_Num, r);

}

cout<<"Sub: "<<sub<<endl;
  
}

This returns:

Sub: 0
Sub: 1
Sub: 2
Sub: 1
Sub: 4
Sub: 5
Sub: 6
Sub: 7
Sub: 2
Sub: 1
Sub: 4
Sub: 2
Sub: 1

to show me the subscript. What I'm stuck on is when it returns the subscript, being able to have it know that if that value already exists in the array for row 0-11, add the new sales amount to it.

For example:

322 10.80
848 920.00
828 1267.00
848 8320.00
229 66330.00

once 848 is read again in row 3, the total sales needs to be updated to $9,240.00 and anytime an ID number is found again, update the sold amount.

Solutions

Expert Solution

IDE used Dev C++

#include <iostream>
#include <fstream>


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

int main()
{
double salesper[12][4];
double temp[20][4];
int n;
double m;
int i =0;
int j=0;
int c1[12];
int k=0;
   double c2[12];
   int tot_sp=0; //total unique salesperson
   int duplicate=0; //total duplicate
   int totdata=0; //totaldata
   ifstream f; // to open the text file in read mode
f.open("SalesPerson SalesV3.txt");
  
// f >> text works same as cin >> text.
  
while(f>>n>>m)
   {
   c1[i]=n;
       c2[i]=m;
       i++;
   totdata++;
}
  
   for(i=0;i<totdata;i++) //storing data in temporary 2Darrray
   {
       temp[i][0]=c1[i];
       temp[i][1]=c2[i];
       temp[i][2]=1;
       temp[i][3]=c2[i];
      
   }
   for(i=0;i<totdata;i++) //checking for duplicate id
   {
       for(j=i+1;j<totdata;j++)
       {
           int count =1;
           if(temp[i][0]==temp[j][0])
           {
               temp[i][1]=temp[i][1]+temp[j][1]; //summing up the bonus
               count++;
               temp[i][2]=count;
               temp[i][3]=(temp[i][1]/2); //calculate average
               for(k=j;k<totdata;k++)
               {
                   temp[k][0]=temp[k+1][0];
                   temp[k][1]=temp[k+1][1];
                   temp[k][2]=temp[k+1][2];
                   temp[k][3]=temp[k+1][3];
               }
               duplicate++;
          
           }
       }
   }
   tot_sp = totdata-duplicate;
   for(i=0;i<tot_sp;i++) //storing the tempory 2d array to final array
   {
       for(j=0;j<4;j++)
       {
          
           salesper[i][j]=temp[i][j];
       }
  
   }
  
   for(i=0;i<tot_sp;i++) //printing the data
   {
       for(j=0;j<4;j++)
       {
          
           cout<<salesper[i][j]<<" ";
       }
       cout<<endl;
   }
return 0;
}
  


Related Solutions

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...
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...
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...
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...
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,100 per person. Glade hopes that by increasing commissions to 17% and decreasing each salesperson’s salary to $21,700, 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...
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...
A company pays its employees as managers (who receive a fixed weekly salary)
A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 40 hours they work and “time-and-a-half,” i.e. 1.5 times their hourly wage, for overtime hours worked), commission workers (who receive $250 plus 5.7% of their gross weekly sales), or pieceworkers (who receive a fixed amount of money per item for each of the items they produce-each pieceworker in this company works on only one...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT