Lab 02
Lab 02
Duration: 90’
Lab 2: Algorithm
Objective:
Materials:
Based on exercises of chapter 8 in the textbook “Foundations Of Computer Science, 4nd
Edition, Behrouz Forouzan, 2017.”
Student's task:
- Review the whole chapter 8 content in the textbook.
- Write down solutions to exercises (step by step)
- Finish exercises and submit the results to the lecturer in class.
Scoring scale: 10
Students will represent the algorithm of the problem in two ways: pseudo-code and UML
Using pseudo-code:
Input: num1, num2
Processing: result=num1+num2
Output: print out result
Using UML
Result=num1+num2
Exercise 2 (2 marks): Write an algorithm that will find the smallest integer among five
integers: 12, 34, 9, 24, 39
Processing:
min=12 if( min>34 )
{ min=34}
if(min>9){ min=9 }
If(min>24){ Min=24 }
Else{ Min=39 }
Using ULM:
Exercise 3 (2 marks): Write an algorithm that will print out the sum of integers inputted
from the keyboard until the value 0 is inputted.
Input: num
Processing:
Sum=0
Do
{
Accept num
Sum = sum+num
} While(n!=0)
Using ULM
Exercise 4 (4 marks):
Suppose that:
In Viet Nam, each people has to pay for his/her yearly personal income tax as the
following description:
Rules:
Tax-free income:
Personal pending amount (tiền nuôi bản thân) pa= 9,000,000 d /month
Alimony (tiền cấp dưỡng) for each his/her dependent pd= 3,600,000
d/month/dependent
With n dependents, Yearly tax-free income: tf = 12*(pa + n*pd)
Based on taxable income, the employee has to pay his/her income tax with levels
pre-defined in the following table:
Write an algorithm that will calculate and print out : income, ti (Taxable Income) and income tax.
Input: n , income
Processing
Pa = 9000000
Pd = 3600000
Tf = 12*(Pa:n*Pd)
Ti = icome – Tf
If (Ti<=0)
{Income tax = 0 }
else
if ( Ti>0 && Ti <=5.000.000)
{ Income ax = Ti * 5/100 }
else
if ( Ti > 5.000.000 && Ti <= 10.000.000)
{Income tax = 5.000.000 * 5/100 + (Ti – 5.000.000) * 10/100 }
else
if ( Ti > 10.000.000 && Ti <= 18.000.000)
{ Income tax= 5.000.000 * 5/100 +5.000.000 * 10/100 +(Ti-10.000.000)*15/100 }
else
Income tax= 5.000.000 * 5/100 +5.000.000 * 10/100 + 8.000.000 *15/100 + (Ti-18.000.000)*20/100
Return 0
Output: print out income, Ti, Income tax.
ULM :