PDA

View Full Version : CS304 Object Oriented Programming Assginment 6 Deadline 30 July 2010



viki
07-26-2010, 04:03 PM
Assignment
Dear students in this course you have now learnt all the basic concepts of OOP and implemented it in a programming language. It is a simple assignment in which you have to answer the following:
a) What is Static Polymorphism? Write its alternative name with a simple example.
(2 lines for defining + single example with code)

b) What is Dynamic Polymorphism? Write its alternative name with a simple example.
(2 lines for defining + single example with code)

c) What is the main difference between Data Hiding and Data Abstraction? How we achieve it in Inheritance? (Be specific: don’t write detailed theory: give it in your own words after study)


Warning: If any one found copied from Internet, Zero (0) marks will be awarded automatically to that ID as we shall have a strict check for plagiarism.


What to submit?
You have to submit the solution in a MS word file.

abrar
08-01-2010, 05:18 AM
What is Static Polymorphism? Write its alternative name with a simple example.
Answer:
Static polymorphism refers to an entity existing in different physical forms simultaneously. Static polymorphism involves binding of functions based on the number, type, and sequence of arguments. The various types of parameters are specified in the function declaration, and therefore the function can be bound to calls at compile time. This form of association is called early binding. The term early binding stems from the fact that when the program is executed, the calls are already bound to the appropriate functions.

The resolution of a function call is based on number, type, and sequence of arguments declared for each form of the function. Consider the following function declaration:


void add(int x , int y)
{
int z;
z=x+y;
return z;
}
void add(float x, float y)
{
float z;
z=x+y;
return z;
}
When the add() function is invoked, the parameters passed to it will determine which version of the function will be executed. This resolution is done at compile time.


What is Dynamic Polymorphism? Write its alternative name with a simple example
Answer:
Dynamic polymorphism is also known as runtime polymorphism.
=
It is achieved by means of virtual functions.
-
Depending on the type of object referred by a variable the decision about the method to be called (whether to call base class implementation or the derived class implementation) is taken at runtime.
A member of a class that can be redefined in its derived classes is known as a virtual member. In order to declare a member of a class as virtual, we must precede its declaration with the keyword virtual:

// virtual members
#include <iostream>
using namespace std;

class CPolygon {
protected:
int width, height;
public:
void set_values (int a, int b)
{ width=a; height=b; }
virtual int area ()
{ return (0); }
};

class CRectangle: public CPolygon {
public:
int area ()
{ return (width * height); }
};

class CTriangle: public CPolygon {
public:
int area ()
{ return (width * height / 2); }
};

int main () {
CRectangle rect;
CTriangle trgl;
CPolygon poly;
CPolygon * ppoly1 = &rect;
CPolygon * ppoly2 = &trgl;
CPolygon * ppoly3 = &poly;
ppoly1->set_values (4,5);
ppoly2->set_values (4,5);
ppoly3->set_values (4,5);
cout << ppoly1->area() << endl;
cout << ppoly2->area() << endl;
cout << ppoly3->area() << endl;
return 0;
}

What is the main difference between Data Hiding and Data Abstraction? How we achieve it in Inheritance? (Be specific: don’t write detailed theory: give it in your own words after study)
Answer:
Abstraction: Abstraction refers to removal/reduction of irrelevant data or unnecessary data or confidential data from a Class.
Data hiding: Data hiding is a feature provided by the abstraction for hiding the data from the class.
Both refer to the same thing.
Data Abstraction is that we hide the data from outside world(outside the class), i.e. making the data directly unavailable to the outside code.

The outside code can access the data only through the member functions.

These member functions actually specify a set of actions that can be performed on the data.
Outside code cannot do any other operation that are not specified by the member functions.

Xpert
08-01-2010, 03:19 PM
Thanks for the reply dear.

viki
08-01-2010, 05:12 PM
so nice of u dear