0% found this document useful (0 votes)
17 views3 pages

EE121_Recitation_2_Fall2024

Uploaded by

seifsoumes
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)
17 views3 pages

EE121_Recitation_2_Fall2024

Uploaded by

seifsoumes
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/ 3

L01 / EE121 Algorithmic/ FALL 2024 / R.

NAMANE

Recitation#2: Algorithmic Language Part-1


Objectives:
• Understand the concept of variables and data types in algorithms.
• Learn how expressions (arithmetic and logical) are constructed and evaluated.
• Practice running an algorithm and deducing its output.
• Writing algorithms using elementary instructions (read, write, and assignment).

Exercise 1: Identifying Valid and Invalid Variable Names


Given the following list of variable names, determine which ones are valid and which ones are invalid based on the
rules for identifiers in algorithms:
1. age
2. _total
3. 1stGrade
4. total_amount$
5. Name
6. final-score
7. height_in_meters
8. sum_of_numbers
9. price of item
10. num#ofItems
For each invalid identifier, explain why it is not valid and suggest a corrected version.

Exercise 2: Delivering a Student's Transcript


You are tasked with developing an algorithm that generates a student's transcript. The transcript should display the
following information:
1. Institute Name
2. Student Name
3. Student ID
4. Gender (M for male and F for female)
5. Semester
6. Course Names (Claculus, Physics, Algorithmic)
7. Course Grades
8. Total Credits
9. GPA
10. Passed (True if the student’s GPA is above 10, False otherwise).
The student’s grades and credits are used to calculate the GPA (Grade Point Average) using this formula:
𝑆𝑆𝑆𝑆𝑆𝑆 𝑜𝑜𝑜𝑜 (𝐺𝐺𝐺𝐺𝐺𝐺𝐺𝐺𝐺𝐺 ∗ 𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶 𝑓𝑓𝑓𝑓𝑓𝑓 𝑒𝑒𝑒𝑒𝑒𝑒ℎ 𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐𝑐)
𝐺𝐺𝐺𝐺𝐺𝐺 =
𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇 𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶
Transcript Example
• Institute : IEEE
• Name: Mohamed Amine
• ID: 12345
• Gender : M
• Semester: Fall 2024
• Courses:
 Calculus: Grade = 12.5, Credits = 4
 Physics: Grade = 14.0, Credits = 3
 Algorithmic: Grade = 16. 5, Credits = 3
• Total Credits: 10
• GPA: 14.15
• Passed: True
Tasks:
1. Identify Variables vs. Constants:
o For each of the objects used in the given problem, identify whether it is a variable or a constant.
2. Determine the Data Types:
o For each object, specify its data type.
1
L01 / EE121 Algorithmic/ FALL 2024 / R. NAMANE

Exercise 3: Evaluating Expressions


1. Assume that the five variables i, j, x, a, and b have been properly declared and initialized according to table1.
Complete table2 by giving the value and the type of the given expressions.

Expression Value Type


Variable Type Value (i + j ) % 4
i integer 50 x/3
j integer 20 i/3
x real 20.0 i=j
a boolean True a AND b
b boolean False NOT ((a AND b) OR a)
Table1 (b OR ( j < i ))
Table2

2. Assume that five integers have been properly declared and initialized with the following values:
a =2, b=3, c=9, d=11 and q=7.
What will be the value of E in the following three assignments?
E ← a + b * c – d*q
E ← b * d / q - a +q
E ← - a + b / 2*a

3. What is the value of E in each of the following assignments if we consider that A=3, B=4, X=3.0, Y= -1.0,
C=’K’ and F=False.
E ← -X*A+Y
E ← B-A/Y+2
E ← (4+A*4–B+(A+16))/(Y–9+6*3)
E ← (((B–2)/(Y/3))/2)*((5*X)-16)
E ← F AND NOT (C<’A’)
E ← (X>Y) OR (A>B)
E ← (X≤Y) AND (A<B)

Exercise 4: Algorithm Evaluation


What will be the values of variables A, B, and C after the execution of both Algo1 and Algo2?

Algorithm Algo1 Algorithm Algo2


Variables A,B,C:integer Variables A,B,C:integer
Start Start
A ← 10 A ← 3
B ← 5 B ← 10
C ← A+B C ← A + B
A ← A+2 B ← A * C
C ← 2*C+B-A A ← C - 4
Write(A,B,C) C ← A - B/A
Stop Write (A,B,C)
Stop

Exercise 5: Algorithms for geometry


1. Write an algorithm that reads the two sides of a rectangle and calculate its area.
2. Write an algorithm for finding the area and circumference of a circle by giving it radius r.
3. Consider a cylinder with radius 𝑟𝑟 and height ℎ. Write an algorithm that calculates its curved surface area 𝑠𝑠, its
total surface area 𝑡𝑡𝑡𝑡, and its volume 𝑣𝑣 such that: 𝑠𝑠 = 2𝜋𝜋𝜋𝜋ℎ , 𝑡𝑡𝑡𝑡 = 2𝜋𝜋𝜋𝜋ℎ + 2𝜋𝜋𝑟𝑟 2 , and 𝑣𝑣 = 𝜋𝜋𝑟𝑟 2 ℎ.
2
L01 / EE121 Algorithmic/ FALL 2024 / R. NAMANE

4. Write an algorithm which determines and displays the position (x,y), at any given time t, of a moving particle
in the xy-plane according to the following parametric equations:
𝑥𝑥(𝑡𝑡) = 2𝑡𝑡
� 3𝑡𝑡 2 where x,y are in meters and t in seconds.
𝑦𝑦(𝑡𝑡) = 2 − 4𝑡𝑡

Exercise 6: Algorithms to perform conversions


1. Write an algorithm that converts a length given in inches to centimeters such that 1 inch=2.54 cm. once the
conversion is performed, the algorithm then prints the results to the screen.
2. Write an algorithm which asks for a temperature Tf, expressed in degree Farenheit, and which converts and
displays it into degree Celsius Tc. The formula to convert from Farenheit to Celsius is Tc = (Tf -32)*5/9.
3. Write an algorithm that asks the user to enter a time T (integer) expressed in seconds, and then converts and
displays it in hours, minutes, and seconds. For example, if T=23513 seconds, the algorithm should convert and
display it as 6 hours 31 minutes 53 seconds.

Exercise 7: Algorithms for calculation


1. For L01 students, the algorithmic course is graded as follows:
The mid-term exam is worth 30% of the overall course grade. The final exam is worth 60% of the overall
course grade. The remaining 10% of the course grade comes from the attendance and participation in
recitations.
Write and algorithm that reads the three grades of a certain student, then calculates and displays his overall
course grade.
2. Let Ax2+Bx+C=0 be a quadratic equation, such that: A, B are integers and C is a real (assume that A is non-
zero). Write an algorithm that calculates and displays the discriminant Δ of the previous equation.
3. Write an algorithm that calculates the value of the following expression:
(4 − 𝑎𝑎𝑎𝑎)2 − 3𝑐𝑐𝑐𝑐
𝐹𝐹 =
2𝑒𝑒 − 𝑎𝑎
Where: a,b,c,d and e are integers and assume that 2𝑒𝑒 − 𝑎𝑎 ≠ 0.

Exercise 8: Challenging exercise 1


In this exercise, you are asked to create an algorithm that reads two integers, X and Y, from the user and calculates the
sum and difference of these values. However, you need to provide two distinct algorithms based on the following
conditions:
1. First Solution: The algorithm should compute and display both the sum and difference using separate
variables.
2. Second Solution: The algorithm should compute the sum and difference without using any additional
variables, only updating X and Y themselves.

Exercise 9: Challenging exercise 2


In this exercise you are asked to propose an algorithm that allows to swap (or exchange) and display the values of two
integers A and B given by the user. For example, if the user gives the value 3 for A and the value 5 for B, your
algorithm should output A = 5 and B = 3.
For this exercise, you are asked to propose two solutions according to the following two requirements:
1. Using as many variables as you wish in the first solution.
2. Without using any variable other than A and B in the second solution.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy