Drawbacks of Procedural Language
Drawbacks of Procedural Language
Language
• Less importance to data, and more importance
to procedure
• Data is exposed, so it can be changed
accidentally
• The procedural approach is not similar to our
visualization of our system
• Procedural modules are not independent of each
other. It hampers its independent and
simultaneous development and reusability
• New data types can’t be created
Characteristics of OO Methodology
• CLASS & OBJECT
• Data and the instructions operating on that
data are enclosed in a logical shell. It’s
called a class
• An instance of a class is called an object
• To put the data and the related function
together is more logical
Encapsulation & Data Hiding
• The data and the function operating on that data
are enclosed in one shell, it’s called
encapsulation
• Outside this shell the data is not visible, only
functions are visible and accessible
• The member data are hidden from the outside
world and user, so it can’t be changed
accidentally like in procedural language
• * Data hiding and data security are different
aspects
Data Abstraction
• Abstraction means hiding of details. Hiding
always provides simplicity. The hiding may
be at three levels:
• Hiding of instruction level details
• Hiding of data level details
• Hiding of both details
Inheritance
• Inheritance is a programming technique
used to construct specialized classes from
existing classes
A
Super Class / Parent Class / Base Class
• ‘cin’ and ‘cout’ are the predefined objects of this class, i.e. , iostream.h,
These are not functions
• ‘>>’, ‘<<‘ are extraction & insertion operator, These are basically functions
int x;
int& xx;
xx=x; // Error: not possible
/////////////////////////////////////
int y;
int* py;
py=&y; // No Error: used frequently
Comparison…
• A reference once created and bound to a
variable, cannot be reinitialized to another
variable. A pointer can be reinitialized any time
int x,y;
int& xy=x; // a reference
xy=y; // not possible; only value of y will
// be copied, reference will not be changed
//////////////////////////////////////////////////////
int x,y;
int * pxy=&x; //p xy is a pointer to x
pxy=&y; // NO ERROR: used frequently
Comparison…
• There is no concept of NULL reference.
There exist NULL pointers
• A function returning a reference can
appear on the left hand side of the
assignment operator. There is no such
concept with pointers
Questions???
Comment about the follwing statements:
int& x=10;
const int& y=10;
Pass-by-Reference Parameter
Passing
#include <iostream.h>
void change(int&,int); //prototype
int main()
{
int a=10;
b=20;
change(a,b); //function called
cout<<endl<<a<<b; //a=11, b=20
return 0;
}
<<"imaginary Part:"<<cc.img;
}
Movie Example (tute)
#include<iostream.h>
#include<conio.h>
void printMovie(char arr[10], int rtime);
void printMovie(char arr[3]);
void main()
{
printMovie("hello",5);
printMovie("hello");
//default value of nn is 2
int main()
{float x;
int n;
x=5.0; n=3;
cout<<power(x,n); //5.03=124.0; default value not used
cout<<power(x); // 5.02=25.0; default value used; n=2
return 0;
}
/* Function to calculate power input
input: x and n
output: x to the power n
*/
float power(float xx, int nn)
{
float res=1.0;
for(int i=0;i<nn;i++) //loop to calculate power
res *=xx;
return res;
}
Facts…
• Default arguments are type checked at the
time of function declaration and evaluated
at the time of call. So, the default value is
given to the prototype declaration
• Default value can only be provided to the
trailing arguments
For example:
Float power(float xx=10, int nn); //Error
Example…
void main()
{
printMovie("hello",5);
printMovie("hello");
#include<iostream.h>
int& sum(int x,int y);
int main()
{
int a=10, b=20;
int& s=sum(a,b);
cout<<endl<<“The sum is:”<<s;
return 0;
}
//function returning reference of a variable
int& sum(int x, inty)
{
int z;
z=x+y;
return z;
}
Output????
Program has an error???????