Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question #2: Use one –dimensional array to solve the following problem. A compan

ID: 3622705 • Letter: Q

Question

Question #2:
Use one –dimensional array to solve the following problem. A company pays its salespeople on a commission basis. The salespeople each receive $200 per week plus 9 percent of their gross sales for that week. For example, a salesperson who grosses $5000 in sales in a week receive $200 plus 9 percent of $5000, or total of $650. Write a program (using an array of counters)that determines how many of the salespeople earned salaries in each of the following ranges(assume that each salesperson's salary is truncated to an integer amount):
a) $200-$299
b) $300-$399
c) $400-$499
d) $500-$599
e) $600-$699
f) $700-$799
g) $800-$899
h) $900-$999
i) $1000 and over

Explanation / Answer

PLEASE RATE

The program:

 

 

#include <iostream>
using namespace std;

int main( void )
{
/* We will use this as the 1d array to hold our count */
int rangeOfSalaries[ 9 ] = { 0 };

/* This is soem sample data for us to work off of... */
int sampleData[ 30 ] = { 5000, 5641, 4619, 6541, 684, 178, 240,
2310, 9189, 1114, 0, 4610, 446, 257,
5464, 6400, 4768, 2356, 0, 3456, 3451, 5648,
2139, 3511, 8486, 2133, 5845, 5615, 999 };
int salary = 0; // We will use this to hold our salary calculation for each sales person
int flag = 0;

/* Loops through and handles our count in our 1-dimensional array */
for( int i = 0; i <= 29; i++ )
{
/* Calculate the salary for the person */
salary = 200 + (sampleData[ i ] * 0.09);

flag = 0;

if( salary <= 299 ){ flag = 0; }
else if( salary <= 399 ){ flag = 1; }
else if( salary <= 499 ){ flag = 2; }
else if( salary <= 599 ){ flag = 3; }
else if( salary <= 699 ){ flag = 4; }
else if( salary <= 799 ){ flag = 5; }
else if( salary <= 899 ){ flag = 6; }
else if( salary <= 999 ){ flag = 7; }
else if(salary >= 1000){ flag = 8; }

/* Increase the correct counter for the right range the salary is in */
rangeOfSalaries[ flag ]++;
}

/* Output all the data */
cout << "$200-$299 " << rangeOfSalaries[ 0 ] << endl;
cout << "$300-$399 " << rangeOfSalaries[ 1 ] << endl;
cout << "$400-$499 " << rangeOfSalaries[ 2 ] << endl;
cout << "$500-$599 " << rangeOfSalaries[ 3 ] << endl;
cout << "$600-$699 " << rangeOfSalaries[ 4 ] << endl;
cout << "$700-$799 " << rangeOfSalaries[ 5 ] << endl;
cout << "$800-$899 " << rangeOfSalaries[ 6 ] << endl;
cout << "$900-$999 " << rangeOfSalaries[ 7 ] << endl;
cout << "$1000 and over " << rangeOfSalaries[ 8 ] << endl;

/* For Windows-- To keep the console window open */
system("PAUSE");
}

Sample output:


$200-$299         9
$300-$399         3
$400-$499         2
$500-$599         3
$600-$699         5
$700-$799         6
$800-$899         0
$900-$999         1
$1000 and over    1
Press any key to continue . . .