Philadelphia University Lecturer : Dr. Ali Fouad Coordinator : Dr. Ali Fouad Internal Examiner : Dr. Samer Hanna Faculty of Information Technology Department of Software Engineering Examination Paper Advanced Object Oriented Programming (721324) Sec. 1 First Exam. Date: 17-11-2013 First Semester of 2013-2014 Time: 50 minutes Information for Candidates 1. This examination paper contains five questions, totaling 25 marks. 2. The marks for parts of questions are shown in round brackets. Advice to Candidates 1. You should attempt all questions. 2. You should write your answers clearly. I. Basic concepts Objective: The aim of the question in this part is to evaluate your knowledge and skills concerning with the basic concepts of object oriented. Question1 (3 marks) 1. How do you call __str__method? 2. What’s wrong with the following? L = [2, 5, 7] L = L.append(3) Question2 (7 mark) Act like the python interpreter and run the following program. What will the following python statements display? 1. def Multiply(a, b): return a * b list = [(6, 3), (1, 7), (5, 5) , (2, 8)] print [Multiply(y, x) for (x, y) in list] 2. print [(x, y) for x in [1,2] for y in [3,1,4] if x != y] 3. def f(a, L=[]): L.append(a) return L print f(1) print f(2) print f(3) II. Familiar Problem Solving Objective: The aim of the question in this part is to evaluate your ability to solve problems in object oriented programming, focusing on constructors, assessors, and other methods. Question3 (3 marks) Translate the following while loop into a for loop (which does the same thing as the while loop): i = 20 while (i > 0): print "i = ", i i =- 1 Question4 (8 marks) A vector of dimension n is an ordered collection of n elements, which are called components. Write a Python class named Vector that has the following methods: __init__ method that allow us to insert data into a Vector object when we construct it. __str__ method that prints a Vector object we actually want to print the data contained in the Vector. getn(n) method that returns nth component from the vector. __add__ method that finds the sum of two vectors i.e. if A = (A1, A2, ..., An) and B = (B1, B2, ..., Bn) are two vectors thanA + B = (A1 + B1, A2 + B2, ..., An + Bn) III. Unfamiliar Problem Solving Objective: The aim of the question in this part is to evaluate that student can solve familiar problems with ease and can make progress toward the solution of unfamiliar problems, and can set out reasoning and explanation in clear and coherent manner. Question5 (4 marks) Write a python function that reverses the order of the words in a sentence and the order of the letters in each word