P h i

advertisement
Philadelphia University
Lecturer : Dr. Ali Fouad / Ms. Enas Naffar
Coordinator: Dr. Ali Fouad
Internal Examiner : Dr. Samer Hanna
Object Oriented Programming (721220) Sec. 1, 2 Second Exam.
Date: 12-5-2015
Faculty of Information Technology
Department of Software Engineering
Examination Paper
Second Semester of 2014-2015
Time: 60 minutes
Information for Candidates
1. This examination paper contains four questions, totaling 22 marks, 2 mark bonus.
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 [6 Marks , 1 Mark each]
Circle the correct answer to each of the following:
1. If an attribute is private, which methods have access to it?
A) Only those defined in the same class.
B) Only static methods in the same class.
C) Only classes in the same namespace.
D) None of the above.
2. Which element of a class is optional?
a.) Constructs
b.) Fields
c.) Methods
d.) Properties
e) All of the above
3. If a local variable of a method Print( ) in a class called Student has the same name as an instance
variable of Student class, which value is used when Print( ) is executed?
A) the local variable’s
B) the class instance variable’s
C) A+B
D) None of the above since this would cause a compiler error
4. When using encapsulation how should data be shared with external code (i.e. external
class) ?
A) Events
B) Methods
C) Properties
D) Private variables
5. A class can have many methods with the same name, as long as the number of
parameters is different. This is known as:
A) Method Overloading
B) Method Invocating
C) Method Overriding
D) Method Labeling
6) Suppose that class X has a class member that is an object of another class Y. If classes X and Y
both have constructors, in what order will the constructors be executed when an object of class X
is created?
A) First X's constructor is executed, then Y's.
B) First Y's constructor is executed, then X's.
C) Both constructors are executed at the same time.
D) Only X's constructor is executed.
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.
Question2 [4 Marks, 2 Marks each]
A- The following code has some errors. Locate these errors and fix them.
B- After fixing the errors, find the output of this program.
class number
{
public int num;
public void power()
{
Console.WriteLine("Power of {0} = {1}", num, num * num);
}
}
class Program
{
static void Main(string[] args)
{
Console.Write("Enter a number ");
number.num = Convert.ToInt32(Console.ReadLine());
number.power();
}
}
Question3 [8 Marks, 2 Marks each]
Create Student class with
 Three-argument constructor that initializes name, age, and ID number fields.
 Property with modifier only that sets age. (Age>0).
 Property with modifier only that sets ID number.
 ToString method that returns out the class fields as a string.
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.
Question4 [4 Marks, 1 Mark each]
Write Course class to represent a course. A course can have maximum 20 students. Your Course class
should contain the followings:



Declaration of the required fields.
The constructor which doesn’t take any argument and creates a student list without putting any
student into this list.
The instance method addStudent which adds the given Student object into the student list.

The instance method printall which prints the name, age, and Id number of each student in that
course.
Implement the Course class in the spaces provided below.
Good Luck
Download