0% found this document useful (0 votes)
115 views6 pages

Lab - 02 - Nhóm 7

The document outlines Lab 2 for CSI106, focusing on algorithms, pseudocode, and UML diagrams. Students are required to complete exercises from chapter 8 of the textbook, which involve writing algorithms for various tasks, including basic arithmetic operations and income tax calculations. The lab aims to enhance students' understanding of algorithm design and problem-solving techniques.

Uploaded by

cauminhdi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views6 pages

Lab - 02 - Nhóm 7

The document outlines Lab 2 for CSI106, focusing on algorithms, pseudocode, and UML diagrams. Students are required to complete exercises from chapter 8 of the textbook, which involve writing algorithms for various tasks, including basic arithmetic operations and income tax calculations. The lab aims to enhance students' understanding of algorithm design and problem-solving techniques.

Uploaded by

cauminhdi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

CSI106: Foundations Of Computer Science

Duration: 60’

Lab 2: Algorithm
Objective:

 Define an algorithm and relate it to problem-solving


 Define three constructs and describe their use in algorithms.
 Describe pseudocode and how they are used in algorithms.
 Describe UML diagrams and how they are used in algorithms.

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

Sample: Write an algorithm to calculate the sum of two integers

Using pseudo-code:

Input: num1, num2


Processing: result=num1+num2
Output: print out result

Using UML

Input num1, num2

Result=num1+num2

Print out result


Exercise 1 (2 marks): Write an algorithm to allows users to input two integers and an
operator of four operators +, -, *, / then print out the result to the monitor.

Exercise 2 (2 marks): Write an algorithm that will find the smallest integer among five
integers: 12, 34, 9, 24, 39

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.

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)

Taxable income (thu nhập chịu thuế)


ti = income – tf
( If ti<=0 then income tax = 0)

Based on taxable income, the employee has to pay his/her income tax with levels
pre-defined in the following table:

Leve Taxable Income Income tax


l
1 Less than or equal to 5%
5.000.000
2 From 5.000.001 to 10%
10.000.000
3 From 10.000.001 to 15%
18.000.000
4 Over 18.000.000 20%

Write an algorithm that will calculate and print out : income, ti (Taxable Income) and
income tax.
BÀI 1:
Pseudo-code:

Input: num1, num2

Processing:
sum = num1 + num2
sub = num1 - num2
pro = num1 * num2

While (sum2 == 0)
Input: sum2

div = num1 / sum2

Output: Print out sum, sub, pro, div

true
INPUT: number1,
number 2

While
num2 ==0
sum=num1+num2;

sub=num1-num2;
false
pro=num1*num2;

div=num1/num2

Output: print out:


sum, sub, pro, div.
BÀI 2:
Using pseudo-code:

Input: 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) => Min = 39

Output: Print out Min

Input: 12, 34, 9, 24, 39

Min=12

true

Mi Min=3
false

true

Mi Min=9
false true

false Mi Min=2

Mi

Input:
BÀI 3:

Using pseudo-code:

Input: number

sum = 0

While (number != 0)

sum = sum + number

input: number

Output: Print out sum

Input: number
sum = 0

Sum = Sum + number

True Whille False


number != 0 PRINT SUM
BÀI 4:
Input:

Income

Number of dependents

Tax-free income:

pa = 9,000,000

pd = 3,600,000

tf = 12*(pa + n*pd)

ti = income – tf

If ti <= 0 thì tax = 0

Else if (ti <= 5tr) It = ti * 0.05;

Else if (ti <= 10tr) It = 5tr * 0.05 + (ti - 5tr) * 0.1

Else if (ti <= 18tr) It = 5tr * 0.05 + 5tr * 0.1 + (ti - 10tr) * 0.15

Else It = 5tr * 0.05 + 5tr * 0.1 + 8tr * 0.15 + (ti - 18tr) * 0.2

Output: Print out taxable income, income, income tax

You might also like