Sei sulla pagina 1di 9

DEPARTMENT OF INFORMATION TECHNOLOGY CENTRE FOR DIPLOMA

STUDIES

DAT 133033 COMPUTER ALGORITHM


LAB EXERCISE
SESSION 20192020-1

*SERIES NUMBER LE 1 LE 2 LE3 LE 4

TITLE SELECTION CONTROL STRUCTURE


DATELINE 23 OCTOBER 2019
LECTURER NAME PUAN HAZWANI BINTI RAHMAT

STUDENTS NAME MATRIX NO SECTION


1. ANIS AISHAH BINTI AA191565 5
STUDENTS DETAIL ASIATI RAILI
2. NUR HALWANIE BINTI AA191336 5
MOHD HARUN

3. SITI NURAZREEN AA191267 5


BINTI SAM

TOTAL MARKS

LECTURER COMMENTS:

Notes: 1. *Please tick “√” at the appropriate box


2. Submit this report to your Lab’s lecturer. Please use blue paper for Section 1, green paper for Section 2, red paper
for Section 3, yellow paper for Section 4 and pink paper for Section 5 as for this Front Page
QUESTION 1

Worker in the company is given a Housing Allowance, a Telephone Allowance and


Transportation Allowance. The allowance are RM600, RM700 and RM750
respectively, and are only paid to workers with a basic salary exceeding RM2500.
Every worker is required to contribute 9% of their gross salary to EPF. workers with a
basic salary of less than RM2000 are required to further contribute 2% of their gross
salary to SOCSO. The system should allow us to enter a worker’s basic salary, and
calculate their gross salary, total contribution and net salary.

Net Salary = Gross Salary - Total Contribution


Gross Salary = Basic Salary + Total Allowances

PROBLEM DEFINITION

● The required information is net salary


● The net salary depends on values of the gross salary and total contribution
● The gross salary depends on values of basic salary and total allowances
● The total contribution depends on EPF , SOCSO and gross salary
● The total allowances depends on house allowance, telephone allowance, and
transportation allowance.

IPO CHART

Output netSalary

EPF = 0.09 , SOCSO = 0.02


totalAllowances = houseAllowance + telephoneAllowance +
transportationAllowance
Process grossSalary = basicSalary + totalAllowances
totalContributionA = EPF * grossSalary
total ContributionB = (EPF + SOCSO) *grossSalary
netSalary = grossSalary - totalContribution

Data basicSalary, houseAllowance, telephoneAllowance,


transportationAllowance
PSEUDOCODE

Start
Display “Enter Basic Salary”
Read basicSalary
EPF = 9 / 100
SOCSO = 2 / 100
If (basicSalary >= 2500)
Display “Enter House Allowance”
Read houseAllowance
Display “Enter Telephone Allowance”
Read telephoneAllowance
Display “Enter Transportation Allowance”
Read transportationAllowance
totalAllowances = houseAllowance + telephoneAllowance + transportationAllowance
grossSalary = basicSalary + totalAllowances
totalContribution = EPF * grossSalary
Else
(basicSalary <= 2000)
grossSalary = basicSalary
totalContribution = (EPF + SOCSO) * grossSalary
EndIf
netSalary = grossSalary - totalContribution
Display “The net salary is :” +netSalary
End
FLOWCHART
TRACE TABLE

EXPECTED SCREEN

Enter basic salary = 2500, 2000


Enter house allowance = 600
Enter telephone allowance = 700
Enter transportion allowance = 750
The net salary is = 4140.5, 1780
QUESTION 2

Design an algorithm for a program that displays the menu below. The program should
ask the user to enter a choice, then the selected operation will be performed. Each
operation will receive inputs and display the output.

Choice Operation
----------------------------------------------------------------------------------------------------
C Calculate the area of a circle
T Calculate the perimeter of a triangle
R Calculate the area of a rectangle
S Calculate the volume of a cylinder

PROBLEM DEFINITION

● The required information is Area Of Circle, Perimeter Of Triangle, Area Of


Rectangle and Volume Of Cylinder.
● The Area Of Circle depends on 3.142 * radius ^ 2
● The Permeter Of Triangle depends on 3 side which is side A + side B + side
C of triangle
● The Area Of Rectangle depends on values length * width
● The Volume Of Cylinder depends on 3.142 * (radius^2) * height

IPO CHART

Input choice, length, width, sideA, sideB, sideC

areaOfCircle = 3.142 * radius ^ 2


Process perimeterOfTriangle = sideA + sideB + sideC
areaOfRectangle = length * width
volumeOfCylinder = 3.142 * (radius ^ 2) * height

areaOfCircle
Output perimeterOfTriangle
areaOfRectangle
volumeOfCylinder
PSEUDOCODE

Start
Display “Enter choice”
Read choice
If (choice = “c”)
Display “Enter Radius”
Read radius
areaOfCircle = 3.142 * radius ^ 2
Display “c is :” +areaOfCircle
Else
If (choice = “t”)
Display “Enter Side A”
Read sideA
Display “Enter Side B”
Read sideB
Display “Enter Side C”
Read sideC
perimeterOfTriangle = sideA + sideB + sideC
Display “t is :” +perimeterOfTriangle
Else
If (choice = “r”)
Display “Enter Length”
Read length
Display “Enter Width”
Read width
areaOfRectangle = length * width
Display “r is :” +areaOfRectangle
Else
If (choice = “s”)
Display “Enter Radius”
Read radius
Display “Enter Height”
Read height
volumeOfCylinder = 3.142 * radius ^ 2 * height
Display “s is :” +volumeOfCylinder
EndIf
End
FLOWCHART
TRACE TABLE

EXPECTED SCREEN

Enter choice = c, t, r, s
Enter radius = 2
Enter sideA, sideB, sideC = 2,2,2
Enter length = 4
Enter width = 2
Enter heigth = 4
The area of circle is = 7.142
The perimeter of triangle is = 6
The area of rectangle is = 8
The volume of cylinder is = 50.272

Potrebbero piacerti anche