QUESTION 2: NESTED LOOPS
Company ABC employs a number of salesmen to sell a variety of items. These salesmen earn their income from a commission and are paid based on the items they sell.
Company ABC sells several different lines of merchandise
according to grades, namely A, B, C, D and E. Grade A products are difficult to sell (such as a flat screen television) and the salesman receive a higher commission if they sell items from this grade. On the other hand,
products that are graded at E (such as a magazine), are widespread and do not require any creative sales techniques.
Commission is determined as follows:
Grades CommissionGrade A 20% of the total sales
Grade B 18% of the total sales
Grade C 15% of the total sales
Grade D 10% of the total sales
Grade E 5% of the total sales
After the gross salary (i.e. salary before deductions) for each salesman is calculated, a portion of this salary is taxed according to the following tax categories:
Category Current rate Gross salary
Super income tax rate 50% is greater than or equal to R20 000.00
High income tax rate 40% is less than R20 000.00 but greater than or equal to
R15 000.00
Mid income tax rate 30% is less than R15 000 but greater than or equal to
R10 000.00
Low income tax rate 20% is less than R10 000.00 but greater than equal to
R5 000.00
Lowest income tax rate 10% is below R5 000.00
In addition to paying taxes, the salesmen have to contribute a portion of their salary towards their medical aid scheme. Some salesmen qualify for a tax rebate of 50% if their medical aid contribution is greater than or equal to 10% of their gross salary and if their salary is less than R5000.00.
Write a C++ program to determine the tax, gross salary and the final net salary received by each salesman in Company ABC. The program should display these details in the form of a pay slip for each salesman. Additionally
the program should display the total amount in sales made for the month.
The program has the following structure:
· Totals are initialised;
totalSales and
grossSalary (gross salary for each salesman).
· A prompting message for the number of salesmen at Company ABC.
· A for loop iterating over the number of salesmen.
· Inside this for loop - a prompting message is displayed requesting the user to enter the salesman's staff
number.
· A while loop validates the staff number which can only be between 999 and 9999.
· A prompt for the salesmen's medical aid contribution that will be deducted from each salesman's salary.
· Inside the outer for loop is another inner for loop going from one to five corresponding to the different
grades of products sold. Inside this for loop is a switch statement which is used for prompting the user to input the total sales in rands for each grade of merchandise sold.
· A nested if statement follows to determine the amount of tax that will be deducted from each salesman's salary.
· The tax rebate is determined based on the medical aid contribution.
· A payslip for the salesman is displayed, indicating the gross salary, tax deduction, medical aid contribution deduction and the net salary.
· When the outer for loop is exited, the total sales made for the month is displayed.
A partial implementation of the above program specification is given below. The lines where you have to insert or complete code are indicated in bold.
Note 1:
...Indicates that a line of code needs to be completed.
//*** Indicates that more than one line of code needs to be completed.
:
Program code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#include <iostream>
using namespace std;
int main()
{
int numSalesmen;
int staffNumber;
float commission;
float tax;
float netSalary;
float medicalAid;
float gradeSales;
float totalSales = 0;
float grossSalary = 0;
const float superIncomeTaxRate = 0.5;
const float highIncomeTaxRate = 0.4;
const float midIncomeTaxRate = 0.3;
const float lowIncomeTaxRate = 0.2;
const float lowestIncomeTaxRate = 0.1;
const float gradeACommission = 0.2;
const float gradeBCommission = 0.18;
const float gradeCCommission = 0.15;
const float gradeDCommission = 0.1;
const float gradeECommission = 0.05;
//***prompt for number of salesman
//for loop iterate over number of salesmen
for(...;...;...)
{
cout<<"Enter the staff number for salesman " << ... << " : ";
cin >> staffNumber;
//validate staff number
while (...)
{
//***prompt for staff number
}
cout<< "Enter the medical aid contribution for staff number " << ... << " : ";
cin >> medicalAid;
//for loop iterating over the grades
for (...;...;...)
{
switch (...)
{
case 1 : cout << "Enter total sales for Grade A:";
commission = gradeACommission;
break;
//*** complete switch statement
}//end switch statement
cin >> gradeSales;
//determine gross salary
grossSalary = grossSalary + gradeSales*commission;
//determine total sales
totalSales = ...
}//end inner for-loop
//nested if statement to determine taxes
if (grossSalary >= 20000.00)
tax = tax = grossSalary*superIncomeTaxRate;
else if (...)
tax = ...;
else if (...)
tax = ...;
else if (...)
tax = ...;
else
tax = grossSalary*lowestIncomeTaxRate;
//determine if salesman gets rebate based on medical aid contribution
if (medicalAid >= (0.1*grossSalary) && ...)
{
//rebate
tax = tax*0.5;
}
//determine net salary
netSalary = ...;
cout.setf(ios::fixed);
cout.precision(2);
//Please see Note 2 below for an explanation of cout.width, and a preview of the
//payslip
cout << ".................PAY SLIP....................."
<< endl;
cout << "Staff Number : # " ;
cout.width(10);
cout << ... << endl;
cout << "Gross Salary : R " ;
cout.width(10);
cout << ... << endl;
cout << "Tax Deducted : R " ;
cout.width(10);
cout << ... << endl;
cout << "Medical Aid : R " ;
cout.width(10);
cout << ... << endl;
cout << "Net Salary : R " ;
cout.width(10);
cout << ... << endl;
cout << ".............................................."
<< endl <<endl;
//reset grossSalary to 0 for next salesman
grossSalary = ...;
}//end of outer for-loop
//display total sales
cout<<" Total Sales for this month : R " << ... << endl;
return 0;
}
| |
See comment....