0 views

Uploaded by Natalie Vatavalis

Exam computer science

- Variables in c
- IntroductiontoDynamixelMotorControlUsingtheArbotiX++++
- Sing System
- Programming
- examples-sheet-1.pdf
- PROGRAMMING_ASSIGNMENT_ONE.pdf
- JavaLabPdf.pdf
- IOCARDs DRIVERversion 1.1
- Code is Ssue
- GLUTReferenceCard.pdf
- Java Programming Cheat Sheet
- Doctor Vee's C++ Codes for the tutorial
- OpenMiracle_DbDesign
- Homework 1
- datadic.docx
- Magic Composite
- bpj lesson 13
- File Handling
- Abdon Pogi Act 3
- 03VariablesPointersArrays-2x2

You are on page 1of 8

Dr. Rimon Elias

Dr. Hisham Othman

Final Exam

Model Answer

Bar code

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.

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.]

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

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

(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]

Mark = eval(input())

if (Mark < 0):

print("invalid mark")

if (Mark <30):

print("The grade is FF")

if (Mark <50):

print("The grade is F")

if (Mark <60):

print("The grade is D")

if (Mark <74):

print("The grade is C")

if (Mark <85):

print("The grade is B")

else:

print("The grade is A")

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

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[0]

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

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:

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

- Variables in cUploaded bySandeep9
- IntroductiontoDynamixelMotorControlUsingtheArbotiX++++Uploaded bysanietom
- Sing SystemUploaded byhabesh64
- ProgrammingUploaded bySiddharth Sharma
- examples-sheet-1.pdfUploaded byAbraham Sauvingnon
- PROGRAMMING_ASSIGNMENT_ONE.pdfUploaded byAaron Goldsmith
- JavaLabPdf.pdfUploaded byShreyank Buddhadev
- IOCARDs DRIVERversion 1.1Uploaded byOlivier Briot
- Code is SsueUploaded byAnkit Kansal
- GLUTReferenceCard.pdfUploaded byremedios14
- Java Programming Cheat SheetUploaded byYogesh2323
- Doctor Vee's C++ Codes for the tutorialUploaded byMayowa
- OpenMiracle_DbDesignUploaded byssaurabh_ss
- Homework 1Uploaded byMohamed Meftah
- datadic.docxUploaded byAnjo Deguzman
- Magic CompositeUploaded bymonalisa
- bpj lesson 13Uploaded byapi-307094923
- File HandlingUploaded byDebraj Bhattacharjee
- Abdon Pogi Act 3Uploaded byAnonymous JJ6E0Lpy2n
- 03VariablesPointersArrays-2x2Uploaded byHussain NJ
- Chapter 06 - Variables and Data Types V2-1Uploaded byRodrigoBurgos
- 1 Intro and PointersUploaded bysavio77
- CE206 Lecture 02 Basics pUploaded byShuvro Chakravorty
- C++ Function OverloadingUploaded byJversha
- an350Uploaded byNghia Duong
- Control Statements (1)Uploaded byAgilen Magalingam
- Ibps Clerk Syllabus With Exam PatternUploaded bySampatKumar
- Net Tutsplus Com Tutorials Other SQL for Beginners Part 2Uploaded bykhalilhn12
- Compiler ConstructionUploaded bynasir jaan
- Why Would You Precede the MainUploaded byOnofre Daniel

- What is Verification and Validation, NAFEMSUploaded bygulilero_yo
- EE120_F08_CourseSyllabusUploaded byhusen8744
- MOSEKUploaded byTranThang09
- BABI ProjectUploaded byShruti Vinyas
- Lecture 01Uploaded bysrikanth.mujjiga
- Cost EstimationUploaded byEleazar Briones Lopez
- IEEE Final Year Projects 2011-2012 ::Image Processing:: Elysium Technologies Pvt LtdUploaded bysunda_pass
- Model Stacking Classification r AmsantacUploaded byAnonymous PZOnWG
- java bookUploaded byapi-3836128
- HD 6 Numerical Integration of SDOF 2008Uploaded byconcord1103
- What is the Expectation Maximization Algorithm?Uploaded byslash020
- Monte Carlo MethodsUploaded byRubens Bozano
- Lecture 2 - LP Duality, Simplex Method Complexity, Ellipsoid MethodUploaded bygdenunzio
- Effect of the Optimizations RTL Erosion 3x3Uploaded bySimon Wouters
- Computer Vision(r)Uploaded byNagwa Ibrahim Ali
- Rr411103 Image Processing and Pattern RecognitionUploaded byvasuvlsi
- Zh 05110257261Uploaded byAlion
- Essentials of Machine Learning Algorithms (With Python and R Codes)Uploaded byAbhishek Patel
- Analysis Log EtabsUploaded bysahmedu
- Mathematical Analysis of Recursive AlgorithmsUploaded byDema Kangguang Ngeendukk
- Ma221 17s Hw01 GradersUploaded byMark Krupinski
- SECRET IMAGE TRANSMISSION THROUGH MOSAIC IMAGEUploaded byCS & IT
- Decision Analysis 2Uploaded bySrikanth Balasubramanian
- PID-POSTUploaded byosamah
- A Fuzzy Track-keeping Autopilot ForUploaded byfaisalzhuida
- Vector Ant Colony OptimizationUploaded byCS & IT
- aprioriUploaded byjijibishamishra
- June, 2014 Exam SolUploaded byعبداللهأحمد
- On Signed Graphs Whose Two Path Signed Graphs are Switching Equivalent to Their Jump Signed GraphsUploaded byDon Hass
- Artificial Intelligence Techniques Based on Aquaculture Solar Thermal WaterUploaded byCABean1