Professional Documents
Culture Documents
BTCS-309
FEATURES OF OOP :-
Emphasis is on data rather than the procedure.
Programs are divided into that are known as objects.
Data structure are designed such that they characterise the object.
Functions that operate on the data of an object are tired together in structure.
Data is hidden & cannot be accessed by external function.
Objects may communicate each other through functions.
New data or function can be easily added whenever necessary.
ADVANTAGES OF OOP:-
C C++
C was developed by Dennis C++ was developed by Bjarne Stroustrup in 1979
Ritchie between 1969 and 1973 at with C++'s predecessor "C with Classes".
AT&T Bell Labs.
C does not support object oriented Being an object oriented programming language
programming; therefore it has no C++ supports polymorphism, encapsulation, and
support for polymorphism, inheritance.
encapsulation, and inheritance.
In C, data are free entities and can be In C++, Encapsulation hides the data to
manipulated by outside code. This is ensure that data structures and operators
because C does not support information are used as intended.
hiding.
C does not support function and operator C++ supports both function and operator
overloading. overloading.
C does not allow functions to be defined In C++, functions can be used inside a
inside structures. structure.
C does not have namespace feature. C++ uses NAMESPACE which avoid
name collisions.
A namespace is a declarative region that
provides a scope to the identifiers (the
names of types, functions, variables, etc)
inside it. Namespaces are used to
organize code into logical groups and to
prevent name collisions that can occur
especially when your code base includes
multiple libraries. All identifiers at
namespace scope are visible to one
another without qualification. Identifiers
outside the namespace can access the
members by using the fully qualified
name for each identifier.
C uses functions for input/output. For C++ uses objects for input output. For
example scanf and printf. example cin and cout.
C does not support reference variables. C++ supports reference variables.
C has no support for virtual and friend C++ supports virtual and friend
functions. functions.
C provides malloc() and calloc()functions C++ provides new operator for memory
for dynamic memory allocation, allocation and delete operator for
and free() for memory de-allocation. memory de-allocation.
C does not provide direct support for error C++ provides support for exception
handling (also called exception handling) handling. Exceptions are used for "hard"
errors that make the code incorrect.
Practical 1
Aim:-To show use of 'const' variable.
#include <iostream.h >
Output :-
Practical 2
Aim:- To show the use of #define directive.
#include<iostream.h>
#include<conio.h>
#define p 3.142
void main()
{
clrscr();
long intr,a,c;
cout<<"\n enter the value of r=";
cin>>r;
a=p*r*r;
cout<<"\n area is="<<int(a)<<endl;
c=2*p*r;
cout<<"\n circumference="<<int(c)<<endl;
getch();
}
Output :-
Practical 3
Aim:-To show the use of size of operator.
#include <iostream.h >
#include <conio.h >
void main ()
{
clrscr();
float a;
cout<<''size of int =''<<size of (int)<<endl;
cout<<''size of float =''<<size of (a)<<endl ;
cout<<''size of char=''<<endl ;
double b;
cout <<''size of double =''<< size of (b)<<endl ;
cout <<'' size of long double =''<<size of (long double) <<endl ;
getch ();
}
Output :-
Practical 4
Aim :-Program to show the use of conditional operator.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
inta,b,c,big;
cout<<"\n enter three values"<<endl;
cin>>a>>b>>c;
big=(a>b)?(a>c?a:c):(b>c?b:c);
cout<<"largest no="<<big;
getch();
}
Output :-