You are on page 1of 8

# The German University Cairo Spring 2018

## Media Engineering and Technology

Dr. Rimon Elias
Dr. Hisham Othman

Final Exam

Bar code

## 1. Duration of the exam: 3 hours (180 minutes).

2. (Non-programmable) Calculators are allowed.
3. No books or other aids are permitted for this test.
4. This exam booklet contains 8 pages, including this one.
5. Write your solutions in the space provided. If you need more space, write on the back of
the sheet containing the problem or on the extra sheets.

## Please, do not write anything on this area.

Question 1 2 3 4 5 6 Total

Maximum Marks 12 10 7 10 12 12 63

Earned Marks

1
Exercise 1: ( 12 marks)
Consider any two different positive numbers a and b in an ascending order. Consider also their average c
(assuming that the exact values are not given).
Find if the following conditions are always True, always False, or Depends. Provide the reason.
[Hints:
- “Depends” means it could be True and it could be False, depending on the exact values of a and b.
- The first row in the table is solved as an example.]

## Always True Depends

a<b Reason: because a and b are in
(a+b+c) == 53 Reason: because it depends on
an ascending order. the values of a, b and c

## Always True Always True

b>c Reason: because c as an average
((a-c)*2) < 15 Reason: because a<c, so (a-c) is
should be between a and b -ve

## Always True Always True

(b+c) > a Reason: because b > a and c is
((c-b)<a) or ((b+a)>30) Reason: because a<c, so (a-c) is
+ve. -ve

Always False
Always False
True example:
b > ( 2*c – a ) Reason: because c=(a+b)/2, so
(a>c) and ( c>5) a= 3, b = 5, c = 9
(3 is not greater than 9) AND
b should be equal (2c-a).
(9 is not greater than 100)
False AND False → False

2
Exercise 2: ( 10 marks)
Find the output the following algorithms.

Algorithm1:
cost = [0,10,20,30,40,50,60,70,80,90]
n = len(cost)
i=0
while i < n:
tmp = cost[i]
cost[i] = cost[n-(i+1)]
cost[n-(i+1)] = tmp
i=i+1
print(cost)

Output of Algorithm1:
[0,10, 20, 30, 40, 50, 60, 70, 80, 90]

## Algorithm2: Assume the input is 29.

Mark = eval(input())
if (Mark < 0):
print("invalid mark")
if (Mark <30):
if (Mark <50):
if (Mark <60):
if (Mark <74):
if (Mark <85):
else:

Output of Algorithm2:

FF
F
D
C
B

3
Exercise 3: ( 7 marks)
Provide the final outputs of the following algorithm for the inputs given in the table.

Algorithm:

M = eval(input("Enter M:"))
N = eval(input("Enter N:"))
result = 0
while M > 0:
result = result + N
M=M-1
print("Result=",result)

Solution:

Inputs Output

M N Result

4 5 20

2 -3 -6

-30 10 0

-20 -7 0

5 0 0

3 4.1 12.3

15.9 2 32

## 25.2 3.3 85.8

4
Exercise 4: ( 10 marks)
(a) Trace the following algorithm and fill-in the associated table.
(b) What is the final output of the algorithm?

Values = [50,40,20,80,40,30,60,20,70]
n = len(price)
candidate = values
location = 0
i=1
while i < n:
if values[i] < candidate:
candidate = values[i]
location = i
i=i+1
print("The best value is at location: ", location)

Solution:

i candidate location

0 50 0

1 40 1

2 20 2

3 20 2

4 20 2

5 20 2

6 20 2

7 20 2

8 20 2

## The best value is at location 2

5
Exercise 5: ( 12 marks)
Write an algorithm that takes as an input the time duration in a decimal hours format. The algorithm should
then print the time duration in terms of integer days, hours, minutes, if not zero. (See the examples below.)

Example1: Example2:
Input: Input:
Enter time duration in decimal hour format: 36.75 Enter time duration in decimal hour format: 6.25
Output: Output:
The time duration is: The time duration is:
1 day(s) 6 hour(s)
12 hour(s) 15 minute(s)
45 minute(s)

Solution:

## time = eval(input("Enter time duration in decimal hour format:"))

print("The time duration is:")

days = int(time/24)
if days>0:
print(days, " day(s)")

hours = int(time%24)
if hours>0:
print(hours, " hour(s)")

minutes = (time-int(time))*60
minutes = int(minutes)
if minutes>0:
print(minutes, " minute(s)")

6
Exercise 6: ( 12 marks)

Write an algorithm that gets as an input a list of ages of the employees in your company. The algorithm should
print the number of employees that are expected to be retired in the following five years. The algorithm should
also print the ratio of these retired employees over the total number of the employees. Assume that the
retirement age is at 60 years.

Example:
Input:
Enter list of ages:[30,40,55,57,59,45,25,28]

Output:
3 employee(s) expected to be retired in 5 years.
37.5 % of the employees expected to be retired in 5 years.

Solution:
ages=eval(input("Enter list of ages:"))
n=len(ages)
i=0
count=0
while i<n:
if ages[i]>=55:
count+=1
i+=1
per=100*count/n
print(count, " employee(s) is(are) expected to be retired in 5 years.")
print(per, "% of the employees is expected to be retired in 5 years.")

7
Extra Page