Philadelphia University Faculty of Information Technology Department of Computer Science Examination Paper Lecturers : of all Sections Coordinator : Prof. S. Ghoul Internal Examiner : Dr. Nadia Yacob Programming Fundamentals (750112) All Sections 2nd Exam First Semester of 2008/2009 Date: December, 16, 2008 -------- Time: 50 minutes Information for Candidates 1. This examination paper contains 6 questions totaling 20 marks. 2. The marks for parts of questions are shown in round brackets. Advice to Candidates 1. You should attempt questions from 1 to 5. The question 6 is optional. Consider the following figures to answer the questions that follow: Discounting_Items; //--------------------- discounting item relatively to their prices Let ax + b = 0 be an equation of first order, where a ≠ 0 . begin // --------------------- Data definition ------------------------------ ItemOrder, ItemPrice, DiscountRate are numbers; ItemCost, ItemNumber are numbers; The solution of this equation is given by the following expression: x← - b/a // ----------------------- Actions-------------------------------------- ItemOrder 1; [1] input ItemNumber; while (ItemOrder ≤ ItemNumber) do begin input ItemPrice; if (ItemPrice < 20) then DiscountRate 0.10 [2] else if (ItemPrice < 50) then DiscountRate 0.20 else DiscountRate 0.40; ItemCost ItemPrice - ItemPrice * DiscountRate; output ItemOrder, ItemPrice, ItemCost; ItemOrder ItemOrder + 1; [3] end //While; End // Discounting_Items; Figure 1. N Items cost computing algorithm. We want: To solve N equations of this order. All data are given by the user and may contain errors. To print the values of a, b, and x when x exists To print an error message when x doesn’t exist Figure 2. A first order equation problem. I. Basic Notions Objectives. The aim of the questions in this part is to evaluate that you have the required minimal knowledge and skills in problem solving. Answers in the pass category represent the minimum acceptable standard . Consider the algorithm in Figure 1 and answer the following: 1. Trace the algorithm with ItemNumber = 2, ItemPrice = 10 (for first iteration); ItemPrice = 70 (for second iteration). (2m) 2. What will happen if the action [1] is removed. (1m) 3. What will happen if the action [3] is removed. (2m) II. Familiar Problems Solving Objectives. The aim of the questions in this part is to evaluate that you have some basic knowledge of the key aspects of the lecture material and can attempt to solve familiar problems. 4. Translate the algorithm in a C program. 5. Rewrite the if statement [2] by completing the following: if (ItemPrice ≥ 50) then … ; (5m) (5m) III. Unfamiliar Problems Solving Objectives. The aim of the question in this part is to evaluate that you can solve familiar problems with ease and can make progress towards the solution of unfamiliar problems, and can set out reasoning and explanation in a clear and coherent manner. 6. Write an algorithm solving the problem defined in Figure 2. (5m) Philadelphia University Faculty of Information Technology Department of Computer Science Examination Paper Lecturers : of all Sections Coordinator : Prof. S. Ghoul Internal Examiner : Dr. Nadia Yacob Programming Fundamentals (750112) All Sections Final Exam Date: january, 19, 2009 -------- Time: 120 minutes First Semester of 2008/2009 Information for Candidates 3. This examination paper contains 4 questions totaling 40 marks. 4. The marks for parts of questions are shown in round brackets. Advice to Candidates 1. You should attempt questions from 1 to 5. The question 6 is optional. #include <iostream.h> void cube (float y); {y=y*y*y} void main { int x; cin >> x while (x != 0); {cube(x, int & y); cout << x << endl; } } Figure 1 search (V, R are number) begin while (I ≤ N and A[I] ≠ V) do I I + 1; If (A[I] = V) then R 1 else R 0; end Manip_Array begin constant N = 5; A[N] array of numbers Search (A, N) End; Figure 2 if (n < 10) if (n > 0) cout <<"The number is positive." << endl; else cout << "The number is negative." << endl; 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 Figure 4 Figure 3 I. Basic Notions Objectives. The aim of the questions in this part is to evaluate that you have the required minimal knowledge and skills in problem solving. Answers in the pass category represent the minimum acceptable standard . 1. Find and correct the errors in the program figure 1. (5m) 2. Find and correct the errors the algorithm figure 2. (5m) 3. The nested conditional statement shown below has been written by an inexperienced C/C++ programmer. The behavior of the statement is not correctly represented by the writing format. a. What is the output of the statement if the variable n has the value 7 ? If n has the value 15 ? If n has the value 3 ? (5m) b. Correct the syntax of the statement so that the logic of the corrected statement corresponds to the printing "the number is positive" only if the number is > 0 and < 10. otherwise printing the number is negative. (5m) III. Familiar Problems Solving Objectives. The aim of the questions in this part is to evaluate that you have some basic knowledge of the key aspects of the lecture material and can attempt to solve familiar problems. 4. Write a suitable pseudo-code of a proposed program that carries out the followings: a) Read a ten real numbers; b) Find the average of the negative numbers only; c) Find the squares of the positive numbers only. d) Translate the algorithm to an equivalent C++ code. (2 mark) (4 marks) (4 marks) (5 marks) III. Unfamiliar Problems Solving Objectives. The aim of the question in this part is to evaluate that you can solve familiar problems with ease and can make progress towards the solution of unfamiliar problems, and can set out reasoning and explanation in a clear and coherent manner. 5. Write an algorithm that compute the matrix A [4,4] if figure 4. (5m) Philadelphia University Faculty of Information Technology Department of Computer Science Examination Paper Lecturers : All Sections Coordinator : Prof. S. Ghoul Internal Examiner : Dr. Nadia Yacob Programming Fundamentals (750112) All Sections First Exam Complementary First Semester of 2008/2009 Date: November, 25, 2008 -------- Time: 50 minutes Information for Candidates 5. This examination paper contains 6 questions totaling 20 marks. 6. The marks for parts of questions are shown in round brackets. Advice to Candidates 1. You should attempt questions, such that the sum of their marks will be equal to 15. ← EquationSecondDegree // Begin //Data definition a, b, c, delta, x1, x2 are numbers // ax2 + bx + c = 0; with a ≠ 0 // Actions Input a, b, c; delta← b2 – 4ac; if (delta ≥ 0) then begin x1 ← [-b + sqrt (delta)]/2a; Let ax + b = 0 be an equation of first order Where a ≠ 0 . The solution of this equation is given by the following expression: x← - b/a We want to print the value of x and the following result: R ← (x = 0) or (x < 0) or (x >0) x2 ← [-b - sqrt (delta)]/2a; end Output x1, x2; End Figure 1. Figure 2. I. Basic Notions Objectives. The aim of the questions in this part is to evaluate that you have the required minimal knowledge and skills in problem solving. Answers in the pass category represent the minimum acceptable standard. Consider the algorithm in Figure 1 and answer the following: 1. Trace (run) the algorithm with a = 1, b = -3, c = 2. 2. Draw a Flow Chart for this algorithm (3m) (2m) IV. Familiar Problems Solving Objectives. The aim of the questions in this part is to evaluate that you have some basic knowledge of the key aspects of the lecture material and can attempt to solve familiar problems. 3. The algorithm in the Figure 1 doesn't handle incorrect user input data. Modify this algorithm for carrying out the same task but with user input data correctness verification. (3 m) 4. Translate the algorithm in Figure 1 into a C program. (2 m) III. Unfamiliar Problems Solving Objectives. The aim of the questions in this part is to evaluate that you can solve familiar problems with ease and can make progress towards the solution of unfamiliar problems, and can set out reasoning and explanation in a clear and coherent manner 6. Write a single algorithm (complete data definition and actions) and the corresponding C program computing the expressions defined in Figure 2. (5m + 5m) Philadelphia University Faculty of Information Technology Department of Computer Science Examination Paper Lecturers : All Sections Coordinator : Prof. S. Ghoul Internal Examiner : Dr. Nadia Yacob Programming Fundamentals (750112) All Sections First Exam Complementary First Semester of 2008/2009 Date: November, 25, 2008 -------- Time: 50 minutes Information for Candidates 7. This examination paper contains 5 questions totaling 20 marks. 8. The marks for parts of questions are shown in round brackets. Advice to Candidates 1. You should attempt questions, such that the sum of their marks will be equal to 15. EquationSecondDegree // Begin //Data definition a, b, c, delta, x1, x2 are numbers // ax2 + bx + c = 0; with a ≠ 0 // Actions input a, b, c; delta ← b2 – 4ac; if (delta ≥ 0) then begin x1 ← [-b + sqrt (delta)]/2a; Let ax + b = 0 be an equation of first order Where a ≠ 0 . The solution of this equation is given by the following expression: x← - b/a We want to print the value of x and the following result: R ← (x = 0) or (x < 0) or (x >0) x2 ← [-b - sqrt (delta)]/2a; end output x1, x2; End Figure 1. Figure 2. I. Basic Notions Objectives. The aim of the questions in this part is to evaluate that you have the required minimal knowledge and skills in problem solving. Answers in the pass category represent the minimum acceptable standard . Consider the algorithm in Figure 1 and answer the following: 1. Trace (run) the algorithm with a = 1, b = -3, c = 2. 2. Draw a Flow Chart for this algorithm (3m) (2m) V. Familiar Problems Solving Objectives. The aim of the questions in this part is to evaluate that you have some basic knowledge of the key aspects of the lecture material and can attempt to solve familiar problems. 3. The algorithm in the Figure 1 doesn't handle incorrect user input data. Modify this algorithm for carrying out the same task but with user input data correctness verification. (3 m) 4. Translate the algorithm in Figure 1 into a C program. (2 m) III. Unfamiliar Problems Solving Objectives. The aim of the questions in this part is to evaluate that you can solve familiar problems with ease and can make progress towards the solution of unfamiliar problems, and can set out reasoning and explanation in a clear and coherent manner 5. Write a single algorithm (complete data definition and actions) and the corresponding C program computing the expressions defined in Figure 2. (5m + 5m)