Upload
taazma
View
228
Download
0
Embed Size (px)
Citation preview
7/29/2019 Manual for OOP & DS_000
1/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
Experiment Number 1
Aim :- Write a C++ program to implement the concept of class andobject.
Given Data: - class student:-roll number, name and address.
Program :-#include
# include
# include
Class student
{
private:
int sno;
char name[20];char address[50];
public:
void getdata()
{
cout > sno;
cout > name;
cout > address;}
void putdata()
{
cout
7/29/2019 Manual for OOP & DS_000
2/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
cout
7/29/2019 Manual for OOP & DS_000
3/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
Experiment Number 2(a)
Aim :- To create c ++ program using reference variable .
Program :-
#include# include
# include
void main()
{
Int num1;
clrscr();
Cout > num1;
int num 2=num1;
Cout
7/29/2019 Manual for OOP & DS_000
4/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
Result :- Hence the above program is executed successfully.
Experiment Number 2(b)
Aim :- To perform swapping program using call by reference.
Program :-#include
# include < conio .h >
# include
Swap ( int * ,int * );
Void main( )
{
int a =10 ,b =20;
Swap ( & a , &b);Cout
7/29/2019 Manual for OOP & DS_000
5/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
A=20
B=10 Result :- Hence the above program is executed successfully.
Experiment Number 3
Aim :- To create a c ++ program using static data member and memberFunction .
Program :-
#include
#include
#include
class test
{private :
int code;
static int count;
public :
void setcode()
{
code=++count;
}
void showcode()
{cout
7/29/2019 Manual for OOP & DS_000
6/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
};
int test:: count;
int main()
{
test t1,t2;
t1.setcode();
t2.setcode();test::showcount();
t1.showcode();
t2.showcode();
getch();
}
Output :-
Count : 2
Object number :1Object number : 2
Result :- Hence the above program is executed successfully.
OOP & DS Practical
7/29/2019 Manual for OOP & DS_000
7/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
Experiment Number 4(a)
Aim :- Write a C++ program to find the area of rectangle by using parameterizedConstructor
Program :-
#include
#include
#include
class CRectangle
{
int width, height;
public:
CRectangle (int,int);
int area()
{
return (width*height);
}
};
CRectangle::CRectangle (int a, int b)
{
width = a;
height = b;
}
OOP & DS Practical
7/29/2019 Manual for OOP & DS_000
8/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
int main (){
clrscr();
CRectangle rect (3,4);
CRectangle rectb (5,6);cout
7/29/2019 Manual for OOP & DS_000
9/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
Experiment Number 4(b)
Aim :- To write a program to find the multiplication values and the cubic valuesusinginline function.
Program :-
#include
#include
class line
{
public:
inline float mul(float x,float y)
{
return(x*y);}
inline float cube(float x)
{
return(x*x*x);}
OOP & DS Practical
7/29/2019 Manual for OOP & DS_000
10/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
};
void main()
{
line obj;float val1,val2;
clrscr();
coutval1>>val2;cout
7/29/2019 Manual for OOP & DS_000
11/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
Experiment Number 5
Aim :- To create c ++ program using friend function .
Program :-
#include
#include
#include
class A;
class B
{
private :
int b;public :
void setvalue(int i)
{
b=i;
}
friend void max(B,A);
};
class A
{
private :
int a;
public :
void setvalue(int i)
{
a=i;
OOP & DS Practical
7/29/2019 Manual for OOP & DS_000
12/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
}
friend void max(B,A);
};
void max(B m,A n)
{
if(m.b > n.a)
cout
7/29/2019 Manual for OOP & DS_000
13/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
Experiment Number 6
Aim :- To create program using function overloading .
Program :-
# include < iostream .h >
# include < conio.h >
int area ( int ,int );
float area ( float ) ;
float area ( float ,float );
void main ( ){
Clrscr ( );
int rectangle ;
float circle , cylinder ;
rectangle = area (4,5);
cout
7/29/2019 Manual for OOP & DS_000
14/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
}
float area ( float r )
{
return (3.14 * r * r ) ;
}
float area ( float a ,float b )
{return (2 * 3.14 * a * b) ;
}
Output :-
Area of rectangle is : 20
Area of circle is : 19.625Area of cylinder is : 565.2
Result :- Hence the above program is executed successfully.
OOP & DS Practical
7/29/2019 Manual for OOP & DS_000
15/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
Experiment Number 7
Aim :- To create a C++ program using Operator Overloading.
Program :-
#include
#include
class complex
{
int a,b;
public:
void getvalue()
{
couta>>b;
}
complex operator+(complex ob)
{
complex t;
t.a=a+ob.a;
OOP & DS Practical
7/29/2019 Manual for OOP & DS_000
16/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
t.b=b+ob.b;
return(t);
}
complex operator-(complex ob)
{
complex t;
t.a=a-ob.a;t.b=b-ob.b;
return(t);
}
void display()
{
cout
7/29/2019 Manual for OOP & DS_000
17/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
result1.display();
getch();
}
Output :-Enter the value of Complex Numbers a,b:2
3
Enter the value of Complex Numbers a,b:
45
Input Values:
2+3i4+5i
Result:6+8i
-2+-2i
Result :- Hence the above program is executed successfully.
OOP & DS Practical
7/29/2019 Manual for OOP & DS_000
18/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
Experiment Number 8
Aim :- To create a C++ program using Inheritance.
Program :-
#include
#include
#include
class A
{
int a;
public:
int b;
void getdata()
{
OOP & DS Practical
7/29/2019 Manual for OOP & DS_000
19/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
couta;
}
void show_ab()
{
cout
7/29/2019 Manual for OOP & DS_000
20/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
coutx;
b1.b=x;
b1.cal();
b1.show_ab();
b1.show();
getch();}
Output :-
Enter the value of a : 12
Enter the value of b: 12
Value of a:12
Value of b : 12
Multiplication is : 114
Result :- Hence the above program is executed successfully.
OOP & DS Practical
7/29/2019 Manual for OOP & DS_000
21/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
Experiment Number 9(a)
Aim :- Write a C++ program- To search an element from given array using LinearSearch.
Program :-#include
#include
void main()
{
clrscr();
int ar[10],n,num,no;
coutn;
cout
7/29/2019 Manual for OOP & DS_000
22/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
no=1;continue;
}
}
if(no==1)cout
7/29/2019 Manual for OOP & DS_000
23/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
Experiment Number 9(b)
Aim :- Write a C++ program- To search an element from given array using BinarySearch.
Program :-#include
#include
void main()
{
clrscr();int a[100],i,loc,mid,beg,end,n,flag=0,item;
coutn;
cout
7/29/2019 Manual for OOP & DS_000
24/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
cout
7/29/2019 Manual for OOP & DS_000
25/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
Experiment Number 10(a)
Aim :- To create a C++ program using Bubble Sort & Selection Sort.
OOP & DS Practical
7/29/2019 Manual for OOP & DS_000
26/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
Program :- BUBBLE SORT
#include
#include
#includemain()
{
int a[10],temp,size,i,j;
clrscr();
printf("How many elements you want to enter ");
scanf("%d",&size);
for(i=0;i
7/29/2019 Manual for OOP & DS_000
27/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
{
printf("%d\n",a[i]);
}
getch();
}
Output :- SELECTION SORT
How many elements you want to enter5
The elements are :
45
65
85
75
23
The sorted array23
45
65
75
85
Result :- Hence the above program is executed successfully.
OOP & DS Practical
7/29/2019 Manual for OOP & DS_000
28/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
Experiment Number 10(b)
Aim :- To create a C++ program using Bubble Sort & Selection Sort.
Program :-
#include
#include
#include
main()
{
int a[10],temp,size,i,j;
clrscr();
printf("How many elements you want to enter ");scanf("%d",&size);
for(i=0;i
7/29/2019 Manual for OOP & DS_000
29/29
ANJUMAN COLLEGE OF ENGINEERING &
TECHNOLOGY, NAGPUR
DEPARTMENT :-ELECTRONICS AND TELECOMMUNICATIONENGINEERING
SUBJECT:- OBJECT ORIENTED PROGRAMMING & DATASTRUCTURE
}
}
}
printf("the sorted array .\n");
for(i=0;i