0% found this document useful (0 votes)
4 views2 pages

CSI105 - Lab 02 - AI1901

Lab 2 focuses on defining algorithms and their role in problem-solving, including constructs, pseudocode, and UML diagrams. Students are tasked with reviewing chapter 8 of the textbook and completing exercises that involve writing algorithms in both pseudocode and UML. The exercises include deleting an element from a sorted array, counting even numbers, finding prime numbers, and calculating electricity costs based on consumption.

Uploaded by

fcbalong222
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)
4 views2 pages

CSI105 - Lab 02 - AI1901

Lab 2 focuses on defining algorithms and their role in problem-solving, including constructs, pseudocode, and UML diagrams. Students are tasked with reviewing chapter 8 of the textbook and completing exercises that involve writing algorithms in both pseudocode and UML. The exercises include deleting an element from a sorted array, counting even numbers, finding prime numbers, and calculating electricity costs based on consumption.

Uploaded by

fcbalong222
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/ 2

Lab 2: Algorithm

Duration: 60’

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, 4th
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 the result

Using UML

Input num1, num2

Result=num1+num2

Print out result


Q 1. (2 marks): Write an algorithm to delete an element in a sorted array. The algorithm
must call a search algorithm to find the location of the deletion.

Q 2. (2 marks): Write an algorithm that will find the number of even numbers as long
as you input until “0” is inputted.
For example:
Input Number of even
5 0
8 1
6 2
2 3
0 3

Q 3. (2 marks): Write an algorithm that will print out the prime numbers between two
integers (n1 < n2) inputted from the keyboard.
For example: user input: 2 9  prime numbers = 3 5 7

Q 4. (4 marks): Write an algorithm that will calculate and print out the electricity cost
(in VND) according to the power consumption (kWh).

Electricity price rate


Power consumption Price
1 Level 1: 0 – 50 kWh 1.678 VND
2 Level 2: 51 – 100 kWh 1.734 VND
3 Level 3: 101 – 200 kWh 2.014 VND
4 Level 4: 201 - 300 kWh 2.536 VND
5 Level 5: 301 – 400 kWh 2.834 VND
6 Level 6: above 401 kWh 2.927 VND

For example: if the power consumption (kWh) is 60 kWh.


The electricity cost is 50*1.678 + 10*1.734

You might also like