In: Computer Science
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.
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;
}