Week 6

6th Week – (31st March 2013)

We had a test. Usually we’d have a quiz. And usually I don’t give a pokemon poop about the difference between a test and a quiz. Nevertheless, we had a test this week. Or last week. Past tense. It happened. A 2-hour practical test. In class. A nerve-wrecking test which began EARLY-IN-THE-MORNING-YES-9-AM-IS-EARLY till the end of class. 2 hours of nausea-inducing, brain-smoking, time-limited, test. The good news was that I’ve successfully submitted all the answers for the questions on time. The grim news was that I felt so nauseous at the end of the class, I slept like the dead for the following days. 3 days later, I’m still feeling nauseous. Enough about that, I’ll be letting my written programs (my answers for the test but not all) do the talking now. Here. You may copy and paste if you’re that desperate but learn to cover it up. Good luck to you.

 

#include <cstdlib>

#include <iostream>

 

/* Name : Babybird   Matric No : UK25837  Date : 28 March 2013

Week 6 Test CSC3102  Question 3B

Program : Program to Calculate Yearly Salary for N Employee

 

 

PROBLEM: Madyazkom Company Limited asks you solve the problem of calculating monthly

payroll and the yearly tax of a company employee. The salary per month consists of basic

salary, monthly overtime allowance and monthly housing allowance. It will be taxed yearly

according to his full yearly salary based on the following conditions:

 

a) If the total yearly salary 10,000.00 or less, no tax.

b) If the total yearly salary RM20,000.00 or less, the tax is 10% of the total salary

c) If the total yearly salary RM20,001.00 and above, tax is 20% of total salaries

d) display his full amount, the tax amount & the final salary after deduction of tax

 

Example data of monthly salary & allowances:

Staff  monthly salary    monthly overtime   housing allowance

Staff1    1500.00          200.00              300.00

 

(A) Algorithm

Input    : The following data to be inputted by user;

a) Monthly salary; ms

b) Monthly overtime; mo

c) Housing allowance; ha

Process  : Calculate the transaction;

a) Add all the payroll and multiply it by 12 to get the total yearly payroll in

a year;

ttlsal = (ms + mo + ha) * 12;

b) Apply ‘conditional selection’ function using ‘if’ keyphrase.

i)   If the total yearly salary 10,000.00 or less, no tax;

if ( ttlsal < 10000)

ii)  If the total yearly salary RM20,000.00 or less,

the tax is 10% of the total salary ;

if ( ttlsal > 10000 && ttlsal < 20000)

iii) If the total yearly salary RM20,001.00 and above,

tax is 20% of total salaries

if ( ttlsal > 200001)

c) Subtract the total yearly salary with the tax reduction to get the

final yearly payroll

d) The ‘loop’ function is used to find yearly payroll for N times

 

Output   : The results that need to be displayed are;

a) Total Yearly salary

b) Amount of tax received

c) Final salary after deduction of tax  */

 

 

using namespace std;

 

void getData(); // Divide and conquer strategy using 3 functions

void calcData();

void dispData();

 

 

int main(int argc, char *argv[])

{

int loop, N;

// Introduction to program

cout << “\n********* Week 6 Test CSC3102 Q3B **************” << endl;

cout << ”   * Program to Calculate Yearly Salary for N Employee *” << endl;

cout << ”  *********** Name : Babybird *******” << endl;

cout << ”   ********  Matric No : UK25837 ***********” << endl << endl << endl;

cout << “\nPlease input the number of employees: ” << endl;

cin >> N;

for ( loop=0; loop < N; loop++)

{

getData();   // Call function 1

calcData();  // Call function 2

dispData();  // Call function 3

}

cout << “\nEnd of Question 3B” << endl;

system(“PAUSE”);

return EXIT_SUCCESS;

}

 

void getData()

{

float ms, mo, ha;

 

// First ‘user prompt’

cout << “\nPlease key in the salaries received in a month: ” << endl;

cin  >> ms >> mo >> ha;

 

}

 

void calcData()

{

float ms, mo, ha, ttlsal, salred, realsal;

 

//Add all the payroll and multiply it by 12 to get the total yearly payroll in

// a year;

ttlsal = (ms + mo + ha) * 12;

 

cout << “\nThe total salary in a year (before tax reduction) is: ” << ttlsal << endl;

 

//b) Apply ‘conditional selection’ function using ‘if’ keyphrase.

if ( ttlsal < 10000)

cout << “\nNo tax reduction.” << endl;

salred = 0;

if ( ttlsal > 10000 && ttlsal < 20000)

cout << “\nTax Reduction : 10%” << endl;

salred = ttlsal * 0.1;

if ( ttlsal > 200001)

cout << “\nTax Reduction : 20%” << endl;

salred = ttlsal * 0.2;

cout << “\nThe salary reduction is: ” << salred << endl;

 

//c) Subtract the total yearly salary with the tax reduction to get the final yearly payroll

realsal = ttlsal – salred;

}

// Display final salary after tax reduction

void dispData()

{

float ms, mo, ha, ttlsal, salred, realsal;

cout << “\nThe final yearly salary (after tax reduction) is: ” << realsal << endl;

}

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s