What does it mean by information hiding? What are the advantages of it? {5 Marks}

Similar documents
C++ Crash Kurs. Polymorphism. Dr. Dennis Pfisterer Institut für Telematik, Universität zu Lübeck

Inheritance, and Polymorphism.

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

The University of Nottingham

Introduction to Programming Using Java (98-388)

POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors

POLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE

CS 162, Lecture 25: Exam II Review. 30 May 2018

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Extending Classes (contd.) (Chapter 15) Questions:

Object-Oriented Programming (OOP) Fundamental Principles of OOP

EL2310 Scientific Programming

Midterm Review. PIC 10B Spring 2018

C++_ MARKS 40 MIN

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

Polymorphism. Zimmer CSCI 330

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC

Chapter 5 Object-Oriented Programming

C++ Important Questions with Answers

Passing arguments to functions by. const member functions const arguments to a function. Function overloading and overriding Templates

Absolute C++ Walter Savitch

CS32 - Week 4. Umut Oztok. Jul 15, Umut Oztok CS32 - Week 4

Intermediate Programming, Spring 2017*

ECE Fall 20l2, Second Exam

Object Oriented Programming. Solved MCQs - Part 2

What is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1

Polymorphism Part 1 1

CGS 2405 Advanced Programming with C++ Course Justification

FINAL TERM EXAMINATION SPRING 2010 CS304- OBJECT ORIENTED PROGRAMMING

CSC1322 Object-Oriented Programming Concepts

AN OVERVIEW OF C++ 1

Midterm Exam 5 April 20, 2015

Constructors.


Chapter 1: Object-Oriented Programming Using C++

Constants, References

VIRTUAL FUNCTIONS Chapter 10


Abstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

IS0020 Program Design and Software Tools Midterm, Fall, 2004

CS304 Object Oriented Programming Final Term

EL2310 Scientific Programming

ENCAPSULATION AND POLYMORPHISM

Object Oriented Software Design II

Pointers II. Class 31

C Pointers. 6th April 2017 Giulio Picierro

Review: C++ Basic Concepts. Dr. Yingwu Zhu

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am

CS 247: Software Engineering Principles. ADT Design

C++ Review. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

OBJECT ORIENTED PROGRAMMING. Ms. Ajeta Nandal C.R.Polytechnic,Rohtak

EL2310 Scientific Programming

CS105 C++ Lecture 7. More on Classes, Inheritance

Pointers. 1 Background. 1.1 Variables and Memory. 1.2 Motivating Pointers Massachusetts Institute of Technology

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

C++ (Non for C Programmer) (BT307) 40 Hours

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING

An Introduction to C++

COMP 2355 Introduction to Systems Programming

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Object Oriented Programming with c++ Question Bank

Interview Questions of C++

EL2310 Scientific Programming

CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING C ++ Basics Review part 2 Auto pointer, templates, STL algorithms

1/29/2011 AUTO POINTER (AUTO_PTR) INTERMEDIATE SOFTWARE DESIGN SPRING delete ptr might not happen memory leak!

C++ Inheritance and Encapsulation

Object-Oriented Programming. Lecture 4 Dr Piotr Cybula

(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University

IBS Software Services Technical Interview Questions. Q1. What is the difference between declaration and definition?

VB.NET. Exercise 1: Creating Your First Application in Visual Basic.NET

COMP322 - Introduction to C++

Variables, Memory and Pointers

RAJIV GANDHI COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF INFORMATION TECHNOLOGY OBJECT ORIENTED PROGRAMMING QUESTION BANK UNIT I 2 MARKS

CS11 Introduction to C++ Fall Lecture 7

Before we start - Announcements: There will be a LAB TONIGHT from 5:30 6:30 in CAMP 172. In compensation, no class on Friday, Jan. 31.

G52CPP C++ Programming Lecture 20

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Implementing an ADT with a Class

THE NAME OF THE CONSTRUCTOR AND DESTRUCTOR(HAVING (~) BEFORE ITS NAME) FUNCTION MUST BE SAME AS THE NAME OF THE CLASS IN WHICH THEY ARE DECLARED.

COMS W3101 Programming Language: C++ (Fall 2016) Ramana Isukapalli

22316 Course Title : Object Oriented Programming using C++ Max. Marks : 70 Time: 3 Hrs.

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

Friends and Overloaded Operators

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

Object-Oriented Design (OOD) and C++

Friends and Overloaded Operators

Compaq Interview Questions And Answers

1. Software Systems Complexity, OO Paradigm, UML

Friend Functions, Inheritance

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

Chapter 02 Building Multitier Programs with Classes

Higher Secondary Second Year COMPUTER SCIENCE Model question Paper - 3

Java Object Oriented Design. CSC207 Fall 2014

C++ PROGRAMMING LANGUAGE: DYNAMIC MEMORY ALLOCATION AND EXCEPTION IN C++. CAAM 519, CHAPTER 15

MAHALAKSHMI ENGINEERING COLLEGE B TIRUCHIRAPALLI

OBJ. ORI.& MULT. PROG., M.C.Q. BANK, FOR UNIT -2, SECOND YEAR COMP. ENGG. SEM-4, 2012 PATTERN, U.O.P. UNIT-2

Transcription:

SECTION ONE (COMPULSORY) Question #1 [30 Marks] a) Describe the main characteristics of object-oriented programming. {5 Marks Encapsulation the ability to define a new type and a set of operations on that type, withoutrevealing the representation of the type. Inheritance the ability to create new types that inherit properties from existing types. Polymorphism the ability to use one name for two or more related but technically differentpurposes; one interface, multiple methods. What does it mean by information hiding? What are the advantages of it? {5 Marks In computer science, information hiding is the principle of segregation of the design decisions in a computer program that are most likely to change, thus protecting other parts of the program from extensive modification if the design decision is changed. b) i) Define inheritance {2 Marks Ability to derive new objects from old-permits objects of a more specific class to inherit the properties (data) and behaviors (functions) of a more general class -ability to define a hierarchical relationship between objects ii) Explain the importance of inheritance in generic programming {3 Marks c) i) Define an abstract class. {2 Marks An abstract class cannot be instantiated. An abstract class is a class that is declared abstract it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed. ii) Explain the importance of abstract class. {3 Marks The purpose of an abstract class is to provide a common definition of a base class that multiple derived classes can share. e) i) With an example, write a syntax of one class inheriting another class{3 Marks classderivedclassname(baseclassname): <statement-1>... <statement-n> Page 1

ii) Whatmakesavirtualfunctionspecialandinterestingisthatitsupportssocalledrun-time polymorphism.that is, when a base class pointer (or a base class reference) points to a derived object that contains avirtual function and that virtual function is called by using that pointer, C++ determines which versionof that function to call based upon the type of the object that is pointed to. Using the sample code below explain how this works. {7 Marks. class base { virtual void print() const { cout<< "base" <<endl; class sub : public base { void print() const { cout<< "sub" <<endl; classsubsub : public sub { void print() const { cout<< "subsub" <<endl; int main() { base b; sub s; subsubss; b.print(); s.print(); ss.print(); base *p[3]; p[0] = &ss; p[1] = &s; p[2] = &b; Page 2

for (int i = 0; i < 3; i++) p[i]->print(); class base { virtual void print() const { cout<< "base" <<endl; // virtual! class sub : public base { void print() const { cout<< "sub" <<endl; classsubsub : public sub { void print() const { cout<< "subsub" <<endl; int main() { base b; sub s; subsubss; b.print(); s.print(); ss.print(); // "base", "sub", "subsub" base *p[3]; // pointers to base class p[0] = &ss; p[1] = &s; p[2] = &b; for (int i = 0; i < 3; i++) p[i]->print(); // "subsub", "sub", "base" Page 3

SECTION TWO (ANSWER ANY TWO QUESTIONS) Question #2 [20 Marks] a) i) Define polymorphism as used in generic programming {2 Marks the ability to use one name for two or more related but technically different purposes; one interface, multiple methods. how objects respond to certain kinds of messages -ability for different objects to interpret functions differently ii) Explain the importance of polymorphism as used in generic programming {3 Marks Polymorphism is a very important concept in object oriented programming which enables to change the behavior of the applications in the run time based on the object on which the invocation happens. This enables to easily change the system without making much changes to the application. b) Define a Point structure with x and y coordinates. Write a function pdistance(point, Point)that computes the distance between two points. Write a function pathlength(point[], int) that takes anarray of Point (representing a path) and its size as input parameters and compute the path length by using the pdistance function. Write a main program to test your structure and functions. {15 marks Question #3[20 Marks] a) Define the term encapsulation {2 marks the process of compartmentalizing the elements of an abstraction that constitute its structure and behavior; encapsulation serves to separate the contractual interface of an abstraction and its implementation. b) Explain the importance of encapsulation as used in generic programming. {3 Marks The purpose is to achieve potential for change: the internal mechanisms of the component can be improved without impact on other components, or the component can be replaced with a different one that supports the same public interface. Encapsulation also protects the integrity of the component, by preventing users from setting the internal data of the component into an invalid or inconsistent state. Page 4

c) Exception handling can be a useful tool when developing and debugging a program. The three commands used for it are try, throw and catch. Write a program to clearly demonstrate use of these commands. {15 Marks #include <string> int main () { try { double *m; m = new double[10]; if (m == NULL) throw string("allocation failure"); for (int i = 0; i < 100; i++) { if (i > 9) throw i; m[i] = i * i; // etc delete [] m; catch (int n) { cout<< "Exception: index " << n << " is out of range." <<endl; return 1; catch (string &s) { cout<< "Exception: " << s <<endl; return 2; Question #4[20 Marks] a) Define the term copy constructor. {2 Marks The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. Page 5

b) Explain the importance of constructors. {3 Marks The copy constructor is used to: Initialize one object from another of the same type. Copy an object to pass it as an argument to a function. Copy an object to return it from a function. c) What would be the output of the following code: (5 Marks) voiddo_calc(int n1, int& n2); int main(void) { int num1 = 1; int num2 = 2; do_calc(num2,num1); cout<< num2 << " " << num1 <<endl; voiddo_calc(int n1, int& n2) { n1 = n1 + 5; n2 = n2 * 5; cout<< n2 << " " << n1 <<endl; d) With an example of a program demonstrate function overloading. {10 Marks Question #5[20 Marks] a) With the help of a code show the difference between a class and an object {5 marks A class is a datatype, an object is an instance of a datatype. b) Explain the difference between private, public and protected as used in generic programming {6 Marks They are access modifiers and help us implement Encapsulation (or information hiding). They tell the compiler which other classes should have access to the field or method being defined. Page 6

Private - Only the current class will have access to the field or method. Protected - Only the current class and subclasses (and sometimes also same-package classes) of this class will have access to the field or method.public - Any class can refer to the field or call the method. c) Virtual functions implement the one interface, multiple methods philosophy. With the help of a code demonstrate the use of virtual functions. {9 Marks class base { virtual void print() const { cout<< "base" <<endl; // virtual! class sub : public base { void print() const { cout<< "sub" <<endl; classsubsub : public sub { void print() const { cout<< "subsub" <<endl; int main() { base b; sub s; subsubss; b.print(); s.print(); ss.print(); // "base", "sub", "subsub" base *p[3]; // pointers to base class p[0] = &ss; p[1] = &s; p[2] = &b; for (int i = 0; i < 3; i++) p[i]->print(); // "subsub", "sub", "base" Page 7