Question

In: Computer Science

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 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 <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;
}


Related Solutions

ASSEMBLY PROGRAM!!! QtSpim Sorting Data Add the Bubble Sort to minMaxArray.asm to sort the array into...
ASSEMBLY PROGRAM!!! QtSpim Sorting Data Add the Bubble Sort to minMaxArray.asm to sort the array into ascending order. Use the Bubble Sort algorithm from the lecture. You can use either Base Addressing or Indexed Addressing for the arrays. For this assignment, make sure you prompt the user for the numbers. Do not hard-code them in the data section. NOTE: Declare the array last in the Data section.
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...
// This program uses a bubble sort to arrange an array of integers in // ascending...
// This program uses a bubble sort to arrange an array of integers in // ascending order (smallest to largest). It then display the array // before the sorting and after the sorting. Modify the program so it orders // integers in descending order (largest to smallest). Then add some code // to display the array at each step of the algorithm. You don't have to // modify anything in the main() function. All modification are inside // the bubbleSortArray()...
Given the following array, write a program in C++ to sort the array using a selection...
Given the following array, write a program in C++ to sort the array using a selection sort and display the number of scores that are less than 500 and those greater than 500. Scores[0] = 198 Scores[3] = 85 Scores[6] = 73 Scores[9] = 989 Scores[1] = 486 Scores[4] = 216 Scores[7] = 319 Scores[2] = 651 Scores[5] = 912 Scores[8] = 846
Write and test a C program to implement Bubble Sort. . In your C program, you...
Write and test a C program to implement Bubble Sort. . In your C program, you should do: Implement the array use an integer pointer, get the size of the array from standard input and use the malloc function to allocate the required memory for it. Read the array elements from standard input. Print out the sorted array, and don’t forget to free the memory. Debug your program using Eclipse C/C++ CDT.
(code in C++ language) [Code Bubble sort, Insertion sort Create a Big array with random numbers....
(code in C++ language) [Code Bubble sort, Insertion sort Create a Big array with random numbers. Record the time. Run Bubble Check time (compute the processing time) do it 100 times (random numbers) Take the average Insertion: Compare] (some explanations please)
Write Insertion Sort and Bubble Sort Program for C# also write their algorithm and Explain their...
Write Insertion Sort and Bubble Sort Program for C# also write their algorithm and Explain their working.
Write a program to implement and analyzing the Bubble Sort. a. Write a C++ function for...
Write a program to implement and analyzing the Bubble Sort. a. Write a C++ function for Bubble Sort b. Use a dynamic array of integers in a variable size of n. c. Display the following information: 1) Total counts of comparisons 2) Total counts of shifts / moves / swaps, whichever applies d. Write a main() function to test a best, and an average cases in terms of time efficiency i. Fill out the array with random numbers for an...
Write a program in Java to sort the given array using merge sort, quick sort, insertion...
Write a program in Java to sort the given array using merge sort, quick sort, insertion sort, selection sort and bubble sort based on the input from the user which sorting technique they wanted to use. Get the array size, array elements from the user, and also display the sorted array along with the name of the sorting technique used.
1.   Bubble Sort Implement a bubble sort program that will read from a file “pp2.txt” from...
1.   Bubble Sort Implement a bubble sort program that will read from a file “pp2.txt” from the current directory a list of intergers (10 numbers to be exact), and the sort them, and print them to the screen. You can use redirection to read data from a given file through standard input, as opposed to reading the data from the file with the read API (similar to Lab #1). You can assume the input data will only have 10 numbers...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT