complete the following code

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 Commission
Grade 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.
44
· 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
#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;
COS1511/101/3/2011
45
//***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
46
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;
}
Note 2 : The program displays a pay slip for each salesman as follows:
.................PAY SLIP.....................
Staff Number : # 1111
Gross Salary : R 4100.00
Tax Deducted : R 205.00
Medical Aid : R 3000.00
Net Salary : R 895.00
..............................................
We have used cout.width() to display and align the amount fields on the payslip. Because width() is a
member function, it must be invoked with a cout object. One can set the width of a field, as we have done. We’ve
chosen 10, which will be wide enough for the staff number and the amount fields. cout.width() only changes
the width of the very next output field and then immediately reverts to the default. The default width of the output
will be just enough space to print the number, character, or string in the output buffer. One can change this by using
width(). It aligns the amounts properly. You will not be tested on cout.width() in the exam.
=]

I'll give you a hand if you ask specific and addressable questions. Shorten your post to something I can read quickly and assess. And personalize it. Homework won't get answered, generally.
Topic archived. No new replies allowed.