SlideShare a Scribd company logo
1 of 18
Download to read offline
CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING 
Page 2 of 19 
SECTION A 
OBJECTIVE (50 marks) 
INSTRUCTIONS: 
This section consists of FOURTY(40) objective questions. 
Answer ALL questions in the answers booklet. 
1. Data can be protected using _____________ such as public, private and protected. 
A. Default Constructor 
B. Method Overloading 
C. Access Specifiers 
D. Member Functions 
2. Which of the following is TRUE about an abstraction? 
I. The process by which data and programs are defined with a representation similar to its meaning. 
II. Do not capture only those details about an object that are relevant to the current perspective. 
III. Tries to reduce and factor out details so that the programmer can focus on a few concepts at a time. 
A. I and III 
B. I and IV 
C. II and III 
D. II and IV 
3. Choose the best answer for the advantages of OOP 
I. Code will be written in redundancy. 
II. Allowed to divide the program into modules 
III. New data and function can be added easily 
IV. Building a program around collections of data and code 
A. I and II 
B. I and III 
C. II and III 
D. II and IV
CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING 
Page 3 of 19 
4. Which symbol is used for standard C++ comment? 
I. / 
II. /* */ 
III. // 
IV. || 
A. I only 
B. I and II 
C. II and III 
D. All the above 
Question 5 refers to the diagram below; 
Diagram 1 
5. Identify the exact concept shown in the diagram? 
A. Concept of class 
B. Concept of object 
C. Concept of abstraction 
D. Concept of encapsulation 
6. What are the two important elements of the object-oriented approach? 
A. Class and Object 
B. Class and Function 
C. Inheritance and Polymorphism 
D. Inheritance and Abstraction 
Student 
Name 
MatrixNo 
CPA 
Course 
Study() 
AttendClass() 
Student
CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING 
Page 4 of 19 
7. Complete the statement below. 
__________________ is a programming paradigm that uses object data structures consisting of data and methods and their interaction with design applications and computer programs. 
A. Structured Programming 
B. Inheritance 
C. Object Oriented Programming 
D. Encapsulation 
8. Complete the statement below. 
__________________ is a subset of procedural programming that enforces a logical structure on the program being written. 
A. Exception Handling 
B. Object Oriented Programming 
C. Package 
D. Structured Programming 
9. Which punctuation must be used to end an expression statement? 
A. . (dot) 
B. ; (semi-colon) 
C. : (colon) 
D. ‘(single quote) 
10. Which one of the following function must be contained in all C++ programs? 
A. start() 
B. system() 
C. main() 
D. program()
CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING 
Page 5 of 19 
Figure 1 
Figure 1 
11. Which of the following indicates the error found in the code segment in Figure 1? 
A. Missing semicolon,; in Line 11. 
B. Missing access specifier, private in Line 3. 
C. Use incorrect keyword class in Line 1. 
D. Code written in Line 9 is a prototype of Area (). 
12. “Think of a person driving a car. He does not need to know the internal working of the engine or the way gear changes work, to be able to drive the car” The statement above relate to: 
A. Inheritance 
B. Abstraction 
C. Encapsulation 
D. Data Abstraction 
1. Class Rectangle 
2. { 
3. 
4. double length; 
5. double width; 
6. 
7. public: 
8. 
9. voidArea(double,double); 
10. 
11. }
CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING 
Page 6 of 19 
Questions 13 and 14 are based on the program segment in Figure 2. 
Figure 2 
Figure 2 
13. How many variables can be found in the program? 
A. One 
B. Two 
C. Three 
D. Four 
14. What is the name of the constructor for the program? 
A. Book1() 
B. book1() 
C. Book() 
D. ~Book() 
//Program to display the price of a book 
#include <iostream.h> 
class Book 
{ 
private: 
float price 1; 
public : 
Book(float price1,float price2) 
~Book() 
{cout <<”n The object is destroyed n”; } 
}; 
Book::Book (float price1,float price2) 
{ cout<<”n The object is initialized n”; 
cout<<”n Price : “<<price1; 
cout<<”n Price : “<<price2; 
} 
void main() 
{ __X__ book1(148.5,130.5); 
}
CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING 
Page 7 of 19 
15. Identify the error with the constructor shown in the following fragment? 
Figure 3 
A. Data types must have private access specifier. 
B. A constructor cannot have a return value. 
C. A constructor must have parameter in parenthesis. 
D. A class cannot have semicolon (;) at the end of the class. 
16. What is the purpose of a destructor ? 
A. To allocate a memory. 
B. To deallocate the memory used. 
C. To destroy any object. 
D. To destruct a program. 
17. Which are the characteristics of a destructor? 
I. The function has the same name as the class 
II. Starts with a tilde (~) 
III. The destructor cannot take arguments 
IV. Multiple destructors for the same class can be defined 
A. I, II, III, IV. 
B. I, II, III. 
C. I, II, IV. 
D. I, III, IV. 
18. Which of the following is defined as ~<class_name>(){} ? 
A. Default Constructor 
B. Constructor 
C. Destructor 
D. Class 
class Invent{ 
int x, y, z; 
public: 
int Invent(); 
};
CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING 
Page 8 of 19 
19. Which of the following is not a characteristic of destructor? 
A. It reclaims the memory that is allocated to the object. 
B. It is called automatically when an object is destroyed or goes out of scope. 
C. It has special function whose task is to initialize the objects of its class. 
D. It has the same name as the class but is preceded by a tilde (~) 
20. Given class C is a friend of class B and class B is a friend of class A. What does that mean? 
A. Class B can access data of a Class C 
B. Class C can access data of a Class B 
C. Class A can access data of a Class B 
D. Class A and B can access data of Class C 
21. Which one of the statements is true about abstract class? 
I. Consists of pure virtual function 
II. The methods in the base class and the derived class use the same method name. 
III. Error will occur if the class does not define the method. 
A. I only 
B. I and II 
C. I,II and III 
D. II and III
CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING 
Page 9 of 19 
22. 
Figure 4 
Figure 4 shows the C++ segment code. Which of the following statement is TRUE? 
A. Class A attempts to access private data of class B. 
B. Class B attempts to access the private data of class A. 
C. Class A declares to be friend to class B. 
D. Class A inherits properties of class B. 
23. Why is the overloading method useful? 
A. It conserves the identifier. 
B. It allows us to give related function common names 
C. It reduces the total number of functions, which result in improving program performance. 
D. It increases the total number of functions, which result in improving program flexibility. 
24. Which are the rules of Overloading Function. 
I. The numbers of parameter received for each version must be the same. 
II. The numbers of parameter received for each version must be different. 
III. The type of parameter received must be different. 
IV. The type of parameter received must be the same. 
V. The return type of the functions is the same. 
A. I & III 
B. II & IV 
C. II, III & V 
D. I, III & V 
class A 
{ friend class B 
private : 
int x,y; 
public : 
A ( int a,int b) 
{ 
x = a; 
y = b; 
} 
};
CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING 
Page 10 of 19 
25. Which of this set of operators is commonly overloaded for user-defined classes? 
I. = (assignment operator) 
II. + - * (binary arithmetic operators) 
III. += -= *= (compound assignment operators) 
IV. == != (comparison operators) 
A. I, & II 
B. I, II, & III 
C. II, III & IV 
D. I, II, III, & IV 
Question 26 is based on Figure 5 below: 
Figure 5 
#include <iostream.h> 
class overloadQ 
{ 
public: 
void ovrldMethod(int num1) 
{ 
cout<<"Result Is: "; 
cout<<num1+2; 
} 
void ovrldMethod(int num1, int num2) 
{ 
cout<<"Result Is: "; 
cout<<num1*num2<<endl; 
} 
}; 
int main() 
{ 
overloadQ ovrld; 
ovrld.ovrldMethod(3); 
ovrld.ovrldMethod(5,7); 
ovrld.ovrldMethod(6); 
}
CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING 
Page 11 of 19 
26. What is the output for this program? 
A. 
B. 
C. 
D. 
27. Which concept is shown in the application of templates? 
A. Polymorphism 
B. Inheritance 
C. Abstraction 
D. Encapsulation 
28. Consider the definition of the function template in Figure 6. 
Figure 6 
Based on the above definition, what is the output if, the program called the template in the main function with the parameters for x1 is “Happy” and x2 is “Holiday”? 
A. Happy 
Holiday 
B. Happy x2 
C. Happy Holiday 
D. Happy+Holiday 
Result Is: 5Result Is: 35 
Result Is: 8 
Result Is: 5 
Result Is: 8Result Is: 35 
Result Is: 6Result Is: 35 
Result Is: 12 
Result Is: 5 
Result Is: 35 
Result Is: 8 
template <class type> 
type weekend ( type x1, type x2) 
{ 
return x1+x2; 
}
CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING 
Page 12 of 19 
29. A class named Car inherits publicly all properties of another class named Vehicle. Which of the following C++ code describes the situation? 
A. class Car : public Vehicle {}; 
B. class Vehicle : public Car {}; 
C. class Car : private Vehicle{}; 
D. class Vehicle : protected Car {}; 
30. Which is the correct coding to define the inheritance class in Figure 7? 
Figure 7 
A. 
class fruit{}; 
class fruit: public local_ fruit{}; 
class local_ fruit : langsat{}; 
B. 
class fruit{}; 
class fruit: public local_ fruit{}; 
class fruit: langsat{}; 
C. 
class fruit{}; 
class local_ fruit : public fruit{}; 
class langsat: public local_ fruit{}; 
D. 
class fruit{}; 
class local_ fruit :: public fruit{}; 
class langsat:: public local_ fruit{}; 
31. To make a member accessible within a hierarchy, but private otherwise, what access specifier do you use? 
A. Public 
B. Private 
C. Protected 
D. Virtual 
fruit 
local fruit 
langsat
CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING 
Page 13 of 19 
32. Which of the following is the type of inheritance where multiple derived classes inherit members from a single base class? 
A. Single inheritance 
B. Multiple inheritance 
C. Hierarchical inheritance 
D. Hybrid inheritance 
33. Which of the following is the main concept applied in polymorphism? 
A. Overload method 
B. Overload operator 
C. Overload destructor 
D. Overload constructor 
34. Which of the following are the advantages of polymorphism? 
I. Easy to develop libraries 
II. Definitions are more general 
III. Greater chance for functions re-use 
IV. Can be convert into package 
A. I,II &III 
B. I,II &IV 
C. II,III &IV 
D. I,III &IV 
35. The following are the different types of polymorphism provided by C++ EXCEPT 
A. Method overloading 
B. Operator overloading 
C. Function overloading 
D. Virtual function 
36. Complete the statements below. 
If a catch statement is written to catch exception objects of a base class type, it can also catch all _____ derived from that base class. 
A. Exceptions for objects 
B. Objects of classes 
C. Arguments 
D. Errors
CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING 
Page 14 of 19 
37. Complete the statement below. 
When the function int some Function(char c) throw( ) is executed, it _____ 
A. can throw anything 
B. may throw an integer 
C. may throw a character 
D. may not throw anything 
38. What happens if an exception is thrown outside a try block? 
A. It generates compile error. 
B. It generates run time error. 
C. It is a call to terminate the program. 
D. It is a call to restart the program. 
39. If a try block has two or more associated catch blocks, select which one will be triggered by an exception. 
A. All that catches parameter type matches the exception. 
B. The first one which catches parameter type matches the exception. 
C. The last which catches parameter type matches the exception. 
D. The catches parameter type most closely matches the exception.
CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING 
Page 15 of 19 
40. Based on Figure 8 below, what the output will be displayed if the input value for a = 15 and value for b = 15? 
Figure 8 
A. Result (a/x) = 0 
B. Exception caught: x = 0 
C. Exception caught: x = 15 
D. Result (a/x) = 15 
#include <iostream> 
using namespace std; 
void main() 
{ 
int a, b; 
cout << "Enter values of a and b n"; 
cin >> a; 
cin >> b; 
int x = a - b; 
try 
{ 
if(x != 0) 
cout << "Result (a/x) = " << a/x << "n"; 
else 
throw(x); 
} 
catch(int x) 
{ 
cout << "Exception caught: x = " << x << "n"; 
} 
cout << "End"; }
CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING 
Page 16 of 19 
SECTION B 
SUBJECTIVE (50 marks) 
INSTRUCTION 
This section consists of TWO (2) subjective questions. 
Answer ALL questions. 
QUESTION 1 
(a) 
Describe two differences between function overloading and operator overloading. 
(6 marks) 
(b) 
Explain the following types of inheritance using a simple program code: 
i. Single inheritance (3 marks) 
ii. Multiple inheritance (3 marks) 
( c) 
Answer the following questions based on Figure 1.3 
Figure 1.3 
#include<iostream.h> 
class cube { 
private: 
int side; 
public: 
(i)___________________ 
(ii)___________________ 
}; 
void cube :: setdata(){ 
side=20; 
cout<<”n SIDE OF CUBE: ”<<side; 
} 
(iii)______________________ 
void main( ){ 
(iv)______________________ 
c.setdata(); 
cout<<”n VOLUME OF CUBE: ”<<__(v)___; 
}
CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING 
Page 17 of 19 
i. Declare a prototype method setdata ( ) (1 marks) 
ii. Declare the method volume( ) as a friend of class cube. (1 marks) 
iii. Write a definition of the non-member method volume() that will 
calculate the volume of cube. (3 marks) 
iv. Create object c for class cube. (1 marks) 
v. Call non-member method volume( ) (1 marks) 
vi. Write the output of the program. (1 marks) 
(d) 
Problem : 
Figure 1.1 shows an in complete program segment. You are required to complete the program coding using two forms of function called Addition. 
In one form it has two parameters and in the other it has three parameters. 
Figure 1.1 
(5 marks) 
void main() 
{ 
int j, k, l, m, n, p, q; 
q = 4; j = 6; 
k = Addition (q, j); 
cout << endl << "Sum of two is " << k << endl; 
l = 5; m = 6; n = 7; 
p = Addition (l, m, n); 
cout << endl << "Sum of three is " << p << endl; 
}
CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING 
Page 18 of 19 
QUESTION 2 
(a) 
Describe the difference between private and protected members of a class. 
(4 marks) 
(b) 
Based on figure 2.1, give the output of the statement code. (2 marks) 
Given : 
i. a= 30, b =25 
Figure 2.1 
Figure 2.1 
(c) 
Convert the segment code in Figure 2.2 to operator overloading. (3 marks) 
Figure 2.2 
int a, b; 
cout << "Enter values of a and b n"; 
cin >> a; 
cin >> b; 
int x = a - b; 
try 
{ 
if(x != 0) 
cout << "Result (a/x) = " << a/x << "n"; 
else 
throw(x) 
} 
catch(int j) 
{ 
cout << "Exception caught: x = " << x << "n"; 
} 
cout << "End"; 
} 
double Subtraction(double a, double b, double c) 
{ 
return a-b-c; 
}
CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING 
Page 19 of 19 
(d) 
Create a function template named BallArea( ). The function receives a parameterized argument representing the radius of a ball and returns a value which representing the area of a ball. Write a main ( ) function demonstrates that the function will works correctly with either an integer or a double argument. 
(9 marks) 
(e) 
Write a program that receives a CGPA from a student, by using exception handling with a CGPA more than 4.0 which will display error messages to user. 
(7 marks)

More Related Content

What's hot

Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
Doncho Minkov
 
Modul praktikum java pemrograman berorientasi objek
Modul praktikum java pemrograman berorientasi objekModul praktikum java pemrograman berorientasi objek
Modul praktikum java pemrograman berorientasi objek
imam arifin
 

What's hot (20)

FP305 data structure PAPER FINAL SEM 3
FP305 data structure PAPER FINAL SEM 3FP305 data structure PAPER FINAL SEM 3
FP305 data structure PAPER FINAL SEM 3
 
Generics in java
Generics in javaGenerics in java
Generics in java
 
Enumeration in c#
Enumeration in c#Enumeration in c#
Enumeration in c#
 
Pl sql guide
Pl sql guidePl sql guide
Pl sql guide
 
Access specifiers (Public Private Protected) C++
Access specifiers (Public Private  Protected) C++Access specifiers (Public Private  Protected) C++
Access specifiers (Public Private Protected) C++
 
Array in Java
Array in JavaArray in Java
Array in Java
 
Arrays in java language
Arrays in java languageArrays in java language
Arrays in java language
 
Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function
 
Unit 5.ppt
Unit 5.pptUnit 5.ppt
Unit 5.ppt
 
Java packages
Java packagesJava packages
Java packages
 
SQL bertingkat
SQL bertingkatSQL bertingkat
SQL bertingkat
 
GUI programming
GUI programmingGUI programming
GUI programming
 
Database connectivity in python
Database connectivity in pythonDatabase connectivity in python
Database connectivity in python
 
Advanced Programming C++
Advanced Programming C++Advanced Programming C++
Advanced Programming C++
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
 
Modul praktikum java pemrograman berorientasi objek
Modul praktikum java pemrograman berorientasi objekModul praktikum java pemrograman berorientasi objek
Modul praktikum java pemrograman berorientasi objek
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Sql task answers
Sql task answersSql task answers
Sql task answers
 
Unary operator overloading
Unary operator overloadingUnary operator overloading
Unary operator overloading
 

Similar to FP 301 OOP FINAL PAPER

Kality CS Model_Exit_Exams_with_answer - Copy (2).doc
Kality CS Model_Exit_Exams_with_answer - Copy (2).docKality CS Model_Exit_Exams_with_answer - Copy (2).doc
Kality CS Model_Exit_Exams_with_answer - Copy (2).doc
AnimutGeremew3
 
C# programming constructors
C# programming  constructorsC# programming  constructors
C# programming constructors
성진 원
 
Mcq+questions+cxc+it
Mcq+questions+cxc+itMcq+questions+cxc+it
Mcq+questions+cxc+it
jimkana13
 
Tcs sample technical placement paper level i
Tcs sample technical placement paper level iTcs sample technical placement paper level i
Tcs sample technical placement paper level i
Pooja Reddy
 
QUESTION 1A business system is a(n)A.collection of operations .pdf
QUESTION 1A business system is a(n)A.collection of operations .pdfQUESTION 1A business system is a(n)A.collection of operations .pdf
QUESTION 1A business system is a(n)A.collection of operations .pdf
feelinggifts
 

Similar to FP 301 OOP FINAL PAPER (20)

C++ questions
C++ questionsC++ questions
C++ questions
 
BISH CS Modle Exit Exam.doc
BISH CS Modle Exit Exam.docBISH CS Modle Exit Exam.doc
BISH CS Modle Exit Exam.doc
 
OOM MCQ 2018
OOM  MCQ 2018OOM  MCQ 2018
OOM MCQ 2018
 
Kality CS Model_Exit_Exams_with_answer - Copy (2).doc
Kality CS Model_Exit_Exams_with_answer - Copy (2).docKality CS Model_Exit_Exams_with_answer - Copy (2).doc
Kality CS Model_Exit_Exams_with_answer - Copy (2).doc
 
Exam for c
Exam for cExam for c
Exam for c
 
J3 Computer Studies (Pre-NECO BECE)
J3 Computer Studies (Pre-NECO BECE)J3 Computer Studies (Pre-NECO BECE)
J3 Computer Studies (Pre-NECO BECE)
 
PART - 1 Cpp programming Solved MCQ
PART - 1 Cpp programming Solved MCQPART - 1 Cpp programming Solved MCQ
PART - 1 Cpp programming Solved MCQ
 
C# programming constructors
C# programming  constructorsC# programming  constructors
C# programming constructors
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Mcq+questions+cxc+it
Mcq+questions+cxc+itMcq+questions+cxc+it
Mcq+questions+cxc+it
 
Question Paper Code 065 informatic Practice New CBSE - 2021
Question Paper Code 065 informatic Practice New CBSE - 2021 Question Paper Code 065 informatic Practice New CBSE - 2021
Question Paper Code 065 informatic Practice New CBSE - 2021
 
Tcs sample technical placement paper level i
Tcs sample technical placement paper level iTcs sample technical placement paper level i
Tcs sample technical placement paper level i
 
QUESTION 1A business system is a(n)A.collection of operations .pdf
QUESTION 1A business system is a(n)A.collection of operations .pdfQUESTION 1A business system is a(n)A.collection of operations .pdf
QUESTION 1A business system is a(n)A.collection of operations .pdf
 
Java Programming.pdf
Java Programming.pdfJava Programming.pdf
Java Programming.pdf
 
Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming concepts
 
Part - 2 Cpp programming Solved MCQ
Part - 2  Cpp programming Solved MCQ Part - 2  Cpp programming Solved MCQ
Part - 2 Cpp programming Solved MCQ
 
Java Quiz
Java QuizJava Quiz
Java Quiz
 
Question đúng cnu
Question đúng cnuQuestion đúng cnu
Question đúng cnu
 
CBSE Grade12, Computer Science, Sample Question Paper
CBSE Grade12, Computer Science, Sample Question PaperCBSE Grade12, Computer Science, Sample Question Paper
CBSE Grade12, Computer Science, Sample Question Paper
 
Interfaces c#
Interfaces c#Interfaces c#
Interfaces c#
 

More from Syahriha Ruslan (10)

OSOS SEM 4 Chapter 2 part 1
OSOS SEM 4 Chapter 2 part 1OSOS SEM 4 Chapter 2 part 1
OSOS SEM 4 Chapter 2 part 1
 
OSOS SEM 4 Chapter 1
OSOS SEM 4 Chapter 1OSOS SEM 4 Chapter 1
OSOS SEM 4 Chapter 1
 
FP305 data structure
FP305     data structure FP305     data structure
FP305 data structure
 
FP305 data structure june 2012
FP305   data structure june 2012FP305   data structure june 2012
FP305 data structure june 2012
 
FP304 DATABASE SYSTEM PAPER FINAL EXAM AGAIN
FP304 DATABASE SYSTEM  PAPER FINAL EXAM AGAINFP304 DATABASE SYSTEM  PAPER FINAL EXAM AGAIN
FP304 DATABASE SYSTEM PAPER FINAL EXAM AGAIN
 
FP304 DATABASE SYSTEM FINAL PAPER
FP304    DATABASE SYSTEM FINAL PAPERFP304    DATABASE SYSTEM FINAL PAPER
FP304 DATABASE SYSTEM FINAL PAPER
 
Fp304 DATABASE SYSTEM JUNE 2012
Fp304   DATABASE SYSTEM JUNE 2012Fp304   DATABASE SYSTEM JUNE 2012
Fp304 DATABASE SYSTEM JUNE 2012
 
FP 303 COMPUTER NETWORK PAPER FINAL Q
FP 303 COMPUTER NETWORK PAPER FINAL QFP 303 COMPUTER NETWORK PAPER FINAL Q
FP 303 COMPUTER NETWORK PAPER FINAL Q
 
FP 303 COMPUTER NETWORK PAPER FINAL
FP 303 COMPUTER NETWORK PAPER FINALFP 303 COMPUTER NETWORK PAPER FINAL
FP 303 COMPUTER NETWORK PAPER FINAL
 
FP 303 COMPUTER NETWORK FINAL PAPER JUNE 2012
FP 303 COMPUTER NETWORK FINAL PAPER JUNE 2012FP 303 COMPUTER NETWORK FINAL PAPER JUNE 2012
FP 303 COMPUTER NETWORK FINAL PAPER JUNE 2012
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

FP 301 OOP FINAL PAPER

  • 1. CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING Page 2 of 19 SECTION A OBJECTIVE (50 marks) INSTRUCTIONS: This section consists of FOURTY(40) objective questions. Answer ALL questions in the answers booklet. 1. Data can be protected using _____________ such as public, private and protected. A. Default Constructor B. Method Overloading C. Access Specifiers D. Member Functions 2. Which of the following is TRUE about an abstraction? I. The process by which data and programs are defined with a representation similar to its meaning. II. Do not capture only those details about an object that are relevant to the current perspective. III. Tries to reduce and factor out details so that the programmer can focus on a few concepts at a time. A. I and III B. I and IV C. II and III D. II and IV 3. Choose the best answer for the advantages of OOP I. Code will be written in redundancy. II. Allowed to divide the program into modules III. New data and function can be added easily IV. Building a program around collections of data and code A. I and II B. I and III C. II and III D. II and IV
  • 2. CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING Page 3 of 19 4. Which symbol is used for standard C++ comment? I. / II. /* */ III. // IV. || A. I only B. I and II C. II and III D. All the above Question 5 refers to the diagram below; Diagram 1 5. Identify the exact concept shown in the diagram? A. Concept of class B. Concept of object C. Concept of abstraction D. Concept of encapsulation 6. What are the two important elements of the object-oriented approach? A. Class and Object B. Class and Function C. Inheritance and Polymorphism D. Inheritance and Abstraction Student Name MatrixNo CPA Course Study() AttendClass() Student
  • 3. CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING Page 4 of 19 7. Complete the statement below. __________________ is a programming paradigm that uses object data structures consisting of data and methods and their interaction with design applications and computer programs. A. Structured Programming B. Inheritance C. Object Oriented Programming D. Encapsulation 8. Complete the statement below. __________________ is a subset of procedural programming that enforces a logical structure on the program being written. A. Exception Handling B. Object Oriented Programming C. Package D. Structured Programming 9. Which punctuation must be used to end an expression statement? A. . (dot) B. ; (semi-colon) C. : (colon) D. ‘(single quote) 10. Which one of the following function must be contained in all C++ programs? A. start() B. system() C. main() D. program()
  • 4. CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING Page 5 of 19 Figure 1 Figure 1 11. Which of the following indicates the error found in the code segment in Figure 1? A. Missing semicolon,; in Line 11. B. Missing access specifier, private in Line 3. C. Use incorrect keyword class in Line 1. D. Code written in Line 9 is a prototype of Area (). 12. “Think of a person driving a car. He does not need to know the internal working of the engine or the way gear changes work, to be able to drive the car” The statement above relate to: A. Inheritance B. Abstraction C. Encapsulation D. Data Abstraction 1. Class Rectangle 2. { 3. 4. double length; 5. double width; 6. 7. public: 8. 9. voidArea(double,double); 10. 11. }
  • 5. CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING Page 6 of 19 Questions 13 and 14 are based on the program segment in Figure 2. Figure 2 Figure 2 13. How many variables can be found in the program? A. One B. Two C. Three D. Four 14. What is the name of the constructor for the program? A. Book1() B. book1() C. Book() D. ~Book() //Program to display the price of a book #include <iostream.h> class Book { private: float price 1; public : Book(float price1,float price2) ~Book() {cout <<”n The object is destroyed n”; } }; Book::Book (float price1,float price2) { cout<<”n The object is initialized n”; cout<<”n Price : “<<price1; cout<<”n Price : “<<price2; } void main() { __X__ book1(148.5,130.5); }
  • 6. CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING Page 7 of 19 15. Identify the error with the constructor shown in the following fragment? Figure 3 A. Data types must have private access specifier. B. A constructor cannot have a return value. C. A constructor must have parameter in parenthesis. D. A class cannot have semicolon (;) at the end of the class. 16. What is the purpose of a destructor ? A. To allocate a memory. B. To deallocate the memory used. C. To destroy any object. D. To destruct a program. 17. Which are the characteristics of a destructor? I. The function has the same name as the class II. Starts with a tilde (~) III. The destructor cannot take arguments IV. Multiple destructors for the same class can be defined A. I, II, III, IV. B. I, II, III. C. I, II, IV. D. I, III, IV. 18. Which of the following is defined as ~<class_name>(){} ? A. Default Constructor B. Constructor C. Destructor D. Class class Invent{ int x, y, z; public: int Invent(); };
  • 7. CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING Page 8 of 19 19. Which of the following is not a characteristic of destructor? A. It reclaims the memory that is allocated to the object. B. It is called automatically when an object is destroyed or goes out of scope. C. It has special function whose task is to initialize the objects of its class. D. It has the same name as the class but is preceded by a tilde (~) 20. Given class C is a friend of class B and class B is a friend of class A. What does that mean? A. Class B can access data of a Class C B. Class C can access data of a Class B C. Class A can access data of a Class B D. Class A and B can access data of Class C 21. Which one of the statements is true about abstract class? I. Consists of pure virtual function II. The methods in the base class and the derived class use the same method name. III. Error will occur if the class does not define the method. A. I only B. I and II C. I,II and III D. II and III
  • 8. CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING Page 9 of 19 22. Figure 4 Figure 4 shows the C++ segment code. Which of the following statement is TRUE? A. Class A attempts to access private data of class B. B. Class B attempts to access the private data of class A. C. Class A declares to be friend to class B. D. Class A inherits properties of class B. 23. Why is the overloading method useful? A. It conserves the identifier. B. It allows us to give related function common names C. It reduces the total number of functions, which result in improving program performance. D. It increases the total number of functions, which result in improving program flexibility. 24. Which are the rules of Overloading Function. I. The numbers of parameter received for each version must be the same. II. The numbers of parameter received for each version must be different. III. The type of parameter received must be different. IV. The type of parameter received must be the same. V. The return type of the functions is the same. A. I & III B. II & IV C. II, III & V D. I, III & V class A { friend class B private : int x,y; public : A ( int a,int b) { x = a; y = b; } };
  • 9. CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING Page 10 of 19 25. Which of this set of operators is commonly overloaded for user-defined classes? I. = (assignment operator) II. + - * (binary arithmetic operators) III. += -= *= (compound assignment operators) IV. == != (comparison operators) A. I, & II B. I, II, & III C. II, III & IV D. I, II, III, & IV Question 26 is based on Figure 5 below: Figure 5 #include <iostream.h> class overloadQ { public: void ovrldMethod(int num1) { cout<<"Result Is: "; cout<<num1+2; } void ovrldMethod(int num1, int num2) { cout<<"Result Is: "; cout<<num1*num2<<endl; } }; int main() { overloadQ ovrld; ovrld.ovrldMethod(3); ovrld.ovrldMethod(5,7); ovrld.ovrldMethod(6); }
  • 10. CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING Page 11 of 19 26. What is the output for this program? A. B. C. D. 27. Which concept is shown in the application of templates? A. Polymorphism B. Inheritance C. Abstraction D. Encapsulation 28. Consider the definition of the function template in Figure 6. Figure 6 Based on the above definition, what is the output if, the program called the template in the main function with the parameters for x1 is “Happy” and x2 is “Holiday”? A. Happy Holiday B. Happy x2 C. Happy Holiday D. Happy+Holiday Result Is: 5Result Is: 35 Result Is: 8 Result Is: 5 Result Is: 8Result Is: 35 Result Is: 6Result Is: 35 Result Is: 12 Result Is: 5 Result Is: 35 Result Is: 8 template <class type> type weekend ( type x1, type x2) { return x1+x2; }
  • 11. CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING Page 12 of 19 29. A class named Car inherits publicly all properties of another class named Vehicle. Which of the following C++ code describes the situation? A. class Car : public Vehicle {}; B. class Vehicle : public Car {}; C. class Car : private Vehicle{}; D. class Vehicle : protected Car {}; 30. Which is the correct coding to define the inheritance class in Figure 7? Figure 7 A. class fruit{}; class fruit: public local_ fruit{}; class local_ fruit : langsat{}; B. class fruit{}; class fruit: public local_ fruit{}; class fruit: langsat{}; C. class fruit{}; class local_ fruit : public fruit{}; class langsat: public local_ fruit{}; D. class fruit{}; class local_ fruit :: public fruit{}; class langsat:: public local_ fruit{}; 31. To make a member accessible within a hierarchy, but private otherwise, what access specifier do you use? A. Public B. Private C. Protected D. Virtual fruit local fruit langsat
  • 12. CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING Page 13 of 19 32. Which of the following is the type of inheritance where multiple derived classes inherit members from a single base class? A. Single inheritance B. Multiple inheritance C. Hierarchical inheritance D. Hybrid inheritance 33. Which of the following is the main concept applied in polymorphism? A. Overload method B. Overload operator C. Overload destructor D. Overload constructor 34. Which of the following are the advantages of polymorphism? I. Easy to develop libraries II. Definitions are more general III. Greater chance for functions re-use IV. Can be convert into package A. I,II &III B. I,II &IV C. II,III &IV D. I,III &IV 35. The following are the different types of polymorphism provided by C++ EXCEPT A. Method overloading B. Operator overloading C. Function overloading D. Virtual function 36. Complete the statements below. If a catch statement is written to catch exception objects of a base class type, it can also catch all _____ derived from that base class. A. Exceptions for objects B. Objects of classes C. Arguments D. Errors
  • 13. CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING Page 14 of 19 37. Complete the statement below. When the function int some Function(char c) throw( ) is executed, it _____ A. can throw anything B. may throw an integer C. may throw a character D. may not throw anything 38. What happens if an exception is thrown outside a try block? A. It generates compile error. B. It generates run time error. C. It is a call to terminate the program. D. It is a call to restart the program. 39. If a try block has two or more associated catch blocks, select which one will be triggered by an exception. A. All that catches parameter type matches the exception. B. The first one which catches parameter type matches the exception. C. The last which catches parameter type matches the exception. D. The catches parameter type most closely matches the exception.
  • 14. CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING Page 15 of 19 40. Based on Figure 8 below, what the output will be displayed if the input value for a = 15 and value for b = 15? Figure 8 A. Result (a/x) = 0 B. Exception caught: x = 0 C. Exception caught: x = 15 D. Result (a/x) = 15 #include <iostream> using namespace std; void main() { int a, b; cout << "Enter values of a and b n"; cin >> a; cin >> b; int x = a - b; try { if(x != 0) cout << "Result (a/x) = " << a/x << "n"; else throw(x); } catch(int x) { cout << "Exception caught: x = " << x << "n"; } cout << "End"; }
  • 15. CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING Page 16 of 19 SECTION B SUBJECTIVE (50 marks) INSTRUCTION This section consists of TWO (2) subjective questions. Answer ALL questions. QUESTION 1 (a) Describe two differences between function overloading and operator overloading. (6 marks) (b) Explain the following types of inheritance using a simple program code: i. Single inheritance (3 marks) ii. Multiple inheritance (3 marks) ( c) Answer the following questions based on Figure 1.3 Figure 1.3 #include<iostream.h> class cube { private: int side; public: (i)___________________ (ii)___________________ }; void cube :: setdata(){ side=20; cout<<”n SIDE OF CUBE: ”<<side; } (iii)______________________ void main( ){ (iv)______________________ c.setdata(); cout<<”n VOLUME OF CUBE: ”<<__(v)___; }
  • 16. CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING Page 17 of 19 i. Declare a prototype method setdata ( ) (1 marks) ii. Declare the method volume( ) as a friend of class cube. (1 marks) iii. Write a definition of the non-member method volume() that will calculate the volume of cube. (3 marks) iv. Create object c for class cube. (1 marks) v. Call non-member method volume( ) (1 marks) vi. Write the output of the program. (1 marks) (d) Problem : Figure 1.1 shows an in complete program segment. You are required to complete the program coding using two forms of function called Addition. In one form it has two parameters and in the other it has three parameters. Figure 1.1 (5 marks) void main() { int j, k, l, m, n, p, q; q = 4; j = 6; k = Addition (q, j); cout << endl << "Sum of two is " << k << endl; l = 5; m = 6; n = 7; p = Addition (l, m, n); cout << endl << "Sum of three is " << p << endl; }
  • 17. CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING Page 18 of 19 QUESTION 2 (a) Describe the difference between private and protected members of a class. (4 marks) (b) Based on figure 2.1, give the output of the statement code. (2 marks) Given : i. a= 30, b =25 Figure 2.1 Figure 2.1 (c) Convert the segment code in Figure 2.2 to operator overloading. (3 marks) Figure 2.2 int a, b; cout << "Enter values of a and b n"; cin >> a; cin >> b; int x = a - b; try { if(x != 0) cout << "Result (a/x) = " << a/x << "n"; else throw(x) } catch(int j) { cout << "Exception caught: x = " << x << "n"; } cout << "End"; } double Subtraction(double a, double b, double c) { return a-b-c; }
  • 18. CONFIDENTIAL F3031: OBJECT ORIENTED PROGRAMMING Page 19 of 19 (d) Create a function template named BallArea( ). The function receives a parameterized argument representing the radius of a ball and returns a value which representing the area of a ball. Write a main ( ) function demonstrates that the function will works correctly with either an integer or a double argument. (9 marks) (e) Write a program that receives a CGPA from a student, by using exception handling with a CGPA more than 4.0 which will display error messages to user. (7 marks)