A company pays its salespeople on a commission basis. The salespeople each recei
ID: 3803264 • Letter: A
Question
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 receives $200 plus 9 percent of$5000,or a 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. use pointers instead of arrays (C++ question)
Explanation / Answer
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int main()
{
char c='Y';
// to store the count
int *counter = (int *)malloc(9*sizeof(int));
double salary, sales;
// while user want to enter sales
while(c=='Y'|| c=='y'){
cout << "Enter Monthly Sales: ";
cin >> sales;
// calculate salary based on sales
salary = 200 + sales*0.09;
// based on salary, increment the appropriate counter
if(salary >=200 && salary < 300)
counter[0] += 1;
else if(salary < 400)
counter[1] += 1;
else if(salary < 500)
counter[2] += 1;
else if(salary < 600)
counter[3] += 1;
else if(salary < 700)
counter[4] += 1;
else if(salary < 800)
counter[5] += 1;
else if(salary < 900)
counter[6] += 1;
else if(salary < 1000)
counter[7] += 1;
else
counter[8] += 1;
// if user want to enter sales for more employees
cout << "Do you want to enter for another employee(y/n): ";
cin >> c;
while (getchar() != ' '); // to flush new line character
}
// print the results
cout << "Number of persons earning $200-$299:" << counter[0] << endl;
cout << "Number of persons earning $300-$399:" << counter[1] << endl;
cout << "Number of persons earning $400-$499:" << counter[2] << endl;
cout << "Number of persons earning $500-$599:" << counter[3] << endl;
cout << "Number of persons earning $600-$699:" << counter[4] << endl;
cout << "Number of persons earning $700-$799:" << counter[5] << endl;
cout << "Number of persons earning $800-$899:" << counter[6] << endl;
cout << "Number of persons earning $900-$999:" << counter[7] << endl;
cout << "Number of persons earning $1000 and above:" << counter[8] << endl;
// free the memory allocated dynamically
free(counter);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.