0% found this document useful (0 votes)
22 views

Lab 02 CSI Computer Organization

The document describes a lab assignment on algorithms. The objective is to define algorithms, constructs, pseudocode and UML diagrams. Students must solve 4 exercises that involve writing algorithms to: 1) calculate mathematical operations on inputs, 2) find the smallest number among inputs, 3) calculate a running sum of inputs until a stop value, and 4) calculate personal income tax based on income and number of dependents. Pseudocode is used to represent the algorithms for each exercise.

Uploaded by

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

Lab 02 CSI Computer Organization

The document describes a lab assignment on algorithms. The objective is to define algorithms, constructs, pseudocode and UML diagrams. Students must solve 4 exercises that involve writing algorithms to: 1) calculate mathematical operations on inputs, 2) find the smallest number among inputs, 3) calculate a running sum of inputs until a stop value, and 4) calculate personal income tax based on income and number of dependents. Pseudocode is used to represent the algorithms for each exercise.

Uploaded by

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

22:47 19/10/2023 Lab 02 CSI Computer Organization

CSI104: Foundations Of Computer Science

Duration: 90’

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

about:blank 1/8
22:47 19/10/2023 Lab 02 CSI Computer Organization

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.
WORKSHOP3 BAI 2
Using pseudo-code

Input : num1, option, num2


Processing:
Case ‘+’: num1 + num2
Result
Case ‘-‘: num1 – num2
Result
Case ‘*’: num1 * num2
Result
Case ‘/’: num1 / num2
Result
default: op is not supported
output: printf out result

about:blank 2/8
22:47 19/10/2023 Lab 02 CSI Computer Organization

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

Using pseudo-code

Input: 12, 34, 9, 24, 39

Processing:

Min = 12

If min > number

Output: print out min

about:blank 3/8
22:47 19/10/2023 Lab 02 CSI Computer Organization

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.

Using pseudo-code

Input: Enter integers n;

Processing:

about:blank 4/8
22:47 19/10/2023 Lab 02 CSI Computer Organization

Sum = 0;

For ( ; ; )

If n!= 0 ; continue

If n ==0; sum =i sum +n; break

Output: Print out sum;

about:blank 5/8
22:47 19/10/2023 Lab 02 CSI Computer Organization

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:

about:blank 6/8
22:47 19/10/2023 Lab 02 CSI Computer Organization

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.

Using pseudo-code

Input: dependemts

Processing: tf = 12*(pa + n*pd)


Input: income

Processing: ti = income – tf

If ( ti<0){

processing: income Tax = 0;

} else if ( ti <= 5.000.000){

processing: income Tax = 0.05 * ti;

about:blank 7/8
22:47 19/10/2023 Lab 02 CSI Computer Organization

} else if ( 5.000.001<= ti <= 10.000.000){

processing: income Tax = 0.1 * ti;

} else if ( 10.000.001<= ti <= 18.000.000){

processing: income Tax = 0.15 * ti;

} else if (ti > 18.000.000){

processing: income Tax = 0.2 * ti;

tf = 5000000*0,05 + 5000000*0.1 + 8000000*0.15 + (n – 18000000)*0.2

about:blank 8/8

You might also like