In: Computer Science
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 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
#include <iostream>
#include<fstream.h>
using namespace std;
float saleID[2][12];
float avgsale[12];
float no_sale[12];
float salary[12];
void print_salesreport()
{
printf("SALES_ID\tTOTAL NUMBER OF SALES\tTOTAL
SALES\tAVG_PER_SALE\tSALARY\n");
for(int i =0; i<12;i++)
printf("%f\t%f\t%f\t%f\t%f\n",saleID[0][i],no_sale[i],saleID[1][i],avgsale[i],salary[i]);
}
int main()
{
int r,c;
ifstream indata("SalesPerson SalesV3.txt");
for(r=0;r<2;r++)
{
for(c=0;c<12;c++)
indata>>saleID[r][c];
}
float swap;
//Salary calculation
for(int i=0;i<12;i++)
{
salary[i]=250+(0.11*saleID[1][i]);
}
//bubblesort for saleID
for(int i=0;i<11;i++)
{
for(int j=0; j<11-i;j++)
{
if (saleID[0][j]>saleID[0][j+1])
{
swap=saleID[0][j];
saleID[0][j]=saleID[0][j+1];
saleID[0][j+1]=swap;
swap=saleID[1][j];
saleID[1][j]=saleID[1][j+1];
saleID[1][j+1]=swap;
swap=avgsale[j];
avgsale[j]=avgsale[j+1];
avgsale[j+1]=swap;
swap=salary[j];
salary[j]=salary[j+1];
salary[j+1]=swap;
swap=nosale[j];
nosale[j]=nosale[j+1];
nosale[j+1]=swap;
}
}
}
printf("\nThe sales report in sorted ordered by Sales ID\n");
print_salesreport();
//bubblesort for total_sales
for(int i=0;i<11;i++)
{
for(int j=0; j<11-i;j++)
{
if (saleID[1][j]>saleID[1][j+1])
{
swap=saleID[0][j];
saleID[0][j]=saleID[0][j+1];
saleID[0][j+1]=swap;
swap=saleID[1][j];
saleID[1][j]=saleID[1][j+1];
saleID[1][j+1]=swap;
swap=avgsale[j];
avgsale[j]=avgsale[j+1];
avgsale[j+1]=swap;
swap=salary[j];
salary[j]=salary[j+1];
salary[j+1]=swap;
swap=nosale[j];
nosale[j]=nosale[j+1];
nosale[j+1]=swap;
}
}
}
printf("\nThe sales report in sorted ordered by total
sales\n");
print_salesreport();
float per;
per=((saleID[1][1]-saleID[1][0])/saleID[1][1])*100;
printf("\nThe worsted salesman is Sales_ID:%f with totalsales:%f
\n",saleID[0][0],saleID[1][0]);
printf("Percentage of his sales compared to the second worsted
salesman is %f",per);
//bubblesort for average_sales
for(int i=0;i<11;i++)
{
for(int j=0; j<11-i;j++)
{
if (avgsale[j]>avgsale[j+1])
{
swap=saleID[0][j];
saleID[0][j]=saleID[0][j+1];
saleID[0][j+1]=swap;
swap=saleID[1][j];
saleID[1][j]=saleID[1][j+1];
saleID[1][j+1]=swap;
swap=avgsale[j];
avgsale[j]=avgsale[j+1];
avgsale[j+1]=swap;
swap=salary[j];
salary[j]=salary[j+1];
salary[j+1]=swap;
swap=nosale[j];
nosale[j]=nosale[j+1];
nosale[j+1]=swap;
}
}
}
printf("\nThe sales report in sorted ordered by Average
sales\n");
print_salesreport();
return 0;
}