Object Oriented Programming lab
Object Oriented Programming lab
NEW EDITION
of
PREPARED BY
Mr.D.Paramesh
2
SCHOOL OF COMPUTING
LAB MANUAL
3
SUBJECT CODE:BCS3L2
Regulation 2015
(2015-2016)
4
LIST OF EXPERIMENTS:
1. Programs Using Functions
- Functions with default arguments
- Implementation of Call by Value, Call by Address and Call by Reference
2. Simple Classes for understanding objects, member functions and Constructors
- Classes with primitive data members
- Classes with arrays as data members
- Classes with pointers as data members – String Class
- Classes with constant data members, Classes with static member functions
3. Compile time Polymorphism
- Operator Overloading including Unary and Binary Operators, Function Overloading
4. Runtime Polymorphism
- Inheritance ,Virtual functions
- Virtual Base Classes, Templates
- File Handling-Sequential access, Random access.
5
LIST OF EXPERIMENTS
PROGRAMMING IN C++
CONTENT
f) Inline Function 17
f) Friend Function 33
c) Function Overloading 41
a) Single Inheritance 43
b) Multiple Inheritance 47
c) Multilevel Inheritance 50
d) Virtual Function 53
4
e) Virtual Base Class 56
f) Class Templates 60
7
g) Function Template 63
AIM:
To write a C++ program to find the sum of the given variables using function with
default arguments.
ALGORITHM:
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
void main()
{
float sum(float a,int b=10,int c=15,int =20);
int a=2,b=3,c=4,d=5;
clrscr();
cout<<"\nsum="<<sum(0);
cout<<"\nsum="<<sum(a,b,c,d);
cout<<"\nsum="<<sum(a,b,c);
cout<<"\nsum="<<sum(a,b);
cout<<"\nsum="<<sum(a);
cout<<"\nsum="<<sum(b,c,d);
getch();
}
OUTPUT:
sum=45
sum=14
sum=29
sum=40
sum=47
sum=32
RESULT:
Thus, the given program is verified and executed successfully.
DATE:
AIM:
To implement the concept of function with default arguments.
ALGORITHM:
SOURCE CODE:
11
#include<iostream.h>
void printLine(char =’_’,int =70);
void main()
{
printLine();
printLine(‘/’);
printLine(‘*’,40);
printLine(‘R’,55);
}
void printLine(char ch, int Repeatcount)
{
int i;
cout<<endl;
for(i=0;i<Repeatcount;i++)
cout<<ch;
}
OUTPUT:
-----------------------------------
//////////////////////////////////////
****************************
RRRRRRRRRRRRRRRRRRRRRRR
RESULT:
AIM:
To write a C++ program to find the value of a number raised to its power using call by
value.
ALGORITHM:
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
void main()
{
int x,y;
double power(int,int);
clrscr();
cout<<"Enter ,y:"<<endl;
cin>>x>>y;
cout<<x<<" to the power "<<y <<" is "<< power(x,y);
getch();
}
OUTPUT:
Enter X, Y: 2 3
2 To the Power 3 is 8
RESULT:
Thus, the given program is verified and executed successfully.
DATE:
AIM:
To write a C++ program to implement the concept of Call by Address.
ALGORITHM:
SOURCE CODE:
15
#include<iostream.h>
#include<conio.h>
OUTPUT:
The value of i before swapping is: 20
The value of j before swapping is: 10
The value of i after swapping is: 10
The value of j after swapping is: 20
RESULT:
Thus a program implementing the concept of Call by Address was verified and
successfully implemented.
AIM:
To write a program in C++ to implement the concept of call by reference.
ALGORITHM:
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
void refer(int &a, int &b)
{
cout<<"\n\n The value of integer is:"<<a;
cout<<"\n\n The value of integer is:"<<b;
}
void refer(float a, float b)
{
cout<<"\n\n Value of floating is:"<<a;
cout<<"\n\n Value of floating is:"<<b;
}
void main()
{
int x,y;
float n,m;
clrscr();
cout<<"\n Enter the Integer number of two number\n";
cin>>x>>y;
cout<<"\n Enter the Floating point of two number\n";
cin>>n>>m;
refer(x,y);
refer(n,m);
getch();
}
OUTPUT:
RESULT:
The Program to implement Call by Reference is successfully verified and executed using
C++.
18
AIM:
To write C++ program to implement inline function.
ALGORITHM:
SOURCE CODE:
//inline function
#include<iostream.h>
#include<conio.h>
inline float mul(float x,float y)
{
return(x*y);
}
inline double div(double p,double q)
{
return(p/q);
}
void main()
{
clrscr();
float a = 12.345;
float b = 9.82;
cout<<"\nINLINE FUNCTION\n";
cout<<"Multiplication:"<< mul(a,b)<<"\n";
getch();
}
OUTPUT:
INLINE FUNCTION
Multiplication:121.23
Division:1.25
RESULT:
The Program to implement the Inline Function has been successfully verified and
executed using C++.
DATE:
AIM:
To write a program in C++ to prepare a student Record using classes with primitive data
members.
ALGORITHM:
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
class record
{
public:
char name[20];
int regno;
int marks,m1,m2,m3;
float avg;
void getdata()
{
cout<<"\nenter the name: " ;
cin>>name;
cout<<"enter the regno: ";
cin>>regno;
cout<<"enter the m1,m2,m3: \n";
cin>>m1>>m2>>m3;
}
void calculate()
{
avg=(m1+m2+m3)/3;
}
void display()
{
cout<<"******************\n";
cout<<"\nName: "<<name;
cout<<"\nRegno: "<<regno;
cout<<"\nMark1: "<<m1;
cout<<"\nMark2: "<<m2;
cout<<"\nMark3: "<<m3;
cout<<"\nAvg: "<<avg;
cout<<"******************\n";
}
};
22
void main()
{
record r;
clrscr();
r.getdata();
r.calculate();
r.display();
getch();
}
OUTPUT:
Enter the name: Raja
Enter the reg no: 1
RESULT:
Thus the program in C++ to prepare a student Record using classes with primitive data
members was verified and executed successfully.
DATE:
AIM:
To write a program in C++ to display product detail using classes with array as data
members.
ALGORITHM:
SOURCE CODE:
#include<iostream.h>
class product
{
int pro_code[50];
float pro_price[50];
int count;
public:
void cnt()
{
count=0;
}
void getproduct();
void displaysum();
void displayproduct();
};
void product::getproduct()
{
cout<<"Enter product Code:";
cin>>pro_code[count];
cout<<"Enter product Cost:";
cin>>pro_price[count];
count++;
}
void product::displaysum()
{
float sum=0;
for(int i=0;i<count;i++)
sum=sum+pro_price[i];
cout<<"Total Value:"<<sum<<"\n";
}
void product::displayproduct()
{
cout<<" \nCode Price\n";
for(int i=0;i<count;i++)
{
cout<<"\n"<<pro_code[i];
cout<<" "<<pro_price[i];
25
}
cout<<"\n";
}
void main()
{
product obj;
obj.cnt();
int x;
do
{
cout<<"Enter choice\n";
cout<<"\n-------------";
cout<<"\n1.Add a product";
cout<<"\n2.Display a product total value";
cout<<"\n3.Display all products";
cout<<"\n4.Quit";
cin>>x;
switch(x)
{
case 1:
obj.getproduct();
case 2:
obj.displaysum();
case 3:
obj.displayproduct();
case 4:break;
default:
cout<<"\n Invalid choice";
}
}
while(x!=4);
}
26
OUTPUT:
Code Price
1234 3000
2345 4000
Enter choice
1.Add a product
2.Display a product total value
3.Display all products
4.Quit
2
Total Value:7000
Code Price
1234 3000
2345 4000
Enter choice
1.Add a product
2.Display a product total value
3.Display all products
4.Quit
4
RESULT:
Thus the C++ program for implementing arrays as data members was created, executed
and verified successfully.
EX.NO.2C CLASSES WITH POINTERS AS DATA MEMBERS
27
DATE:
AIM:
Write a program in C++ to implement the classes with pointers as data members.
ALGORITHM:
SOURCE CODE:
#include<iostream.h>
class data
{
public:
int a;
void print()
{
cout<<"a:"<<a;
}
};
void main()
{
data d,*dp;
dp=&d;
int data::*ptr=&data::a;
d.*ptr=10;
d.print();
dp->*ptr=20;
dp->print();
}
OUTPUT:
a:10
a:20
RESULT:
Thus the C++ program for implementing classes with pointers as data members was
verified and executed successfully.
29
AIM:
To write a program in C++ implements the concept of class with constant data member.
ALGORITHM:
SOURCE CODE:
//constant data member
#include<iostream.h>
#include<conio.h>
class Test
{
const int t;
public:
Test(int t): t(t)
{} //Initializer list must be used
int getT()
{
return t;
}
};
void main()
{
clrscr();
cout<<"constant data member";
Test t1(10);
cout<<"\nDefault t1:"<<t1.getT();
Test t2(20);
cout<<"\nDefault t2:"<<t2.getT();
getch();
}
OUTPUT:
Default t1:10
Default t2:20
RESULT:
Thus the C++ program for implementing classes with constant data members was
verified executed successfully.
31
AIM:
To write a program in C++ to implement the concept of class with static member
functions.
ALGORITHM:
SOURCE CODE:
//STATIC MEMBER FUNCTION
#include<iostream.h>
#include<conio.h>
class test
{
int code;
static int count;
public:
void setcode(void)
{
code=++count;
}
void showcode(void)
{
cout<<"object number:"<<code<<"\n";
}
static void showcount(void)
{
cout<<"count:"<<count<<"\n";
}
};
int test::count;
void main()
{
clrscr();
test t1,t2;
t1.setcode();
t2.setcode();
test::showcount();
test t3;
t3.setcode();
test :: showcount();
t1.showcode();
t2.showcode();
t3.showcode();
getch();
33
OUTPUT:
count:2
count:3
object number:1
object number:2
object number:3
RESULT:
Thus the C++ program for implementing classes with static member function was
verified and executed successfully.
34
AIM:
To write a C++ program to implement the friend function concept.
ALGORITHM:
1. Start the program.
2. Declare the class sample
3. Declare the variables a and b.
4. Define the member function setvalue() to assign the values for a and b.
5. Declare a friend function mean() using the keyword friend.
6. Define a parameterized function mean() with object s as a argument variable.
7. The object s is used to access the private data variables a and b.
8. Create the object x for the class sample.
9. Invoke the member function setvalue using x.
10. Display the value for mean.
11. Stop the program
35
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
class sample
{
int a;
int b;
public:
void setvalue()
{
a=25;
b=40;
}
friend float mean(sample s)
};
float mean(sample s)
{
return float(s.a+s.b)/2.0;
}
void main()
{
sample x;
clrscr();
x.setvalue();
cout<<"FRIEND FUNCTION:\n";
cout<<"Mean value ="<<mean(x)<<"\n";
getch();
}
OUTPUT:
FRIEND FUNCTION:
Mean value =32.5
RESULT:
Thus the Program to implement the Friend Function has been successfully verified and
executed using C++.
36
AIM:
ALGORITHM:
1. Start the Program.
2. Create a class space and declare necessary data members and member functions and
operator function as member function.
3. The operator unary minus is overloaded to perform the operation of changing sign
4. Define member function getdata(), to get three values that is passed as arguments.
5. Define the operator overloading function to change the sign of the values.
6. Define the function display() to display the values before and after sign change.
7. Stop the program.
37
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
class space
{
int x,y,z;
public:
void getdata(int a, int b, int c);
void display(void);
void operator-();
};
void space::getdata(int a,int b,int c)
{
x=a;
y=b;
z=c;
}
void space::display(void)
{
cout<<x<<" ";
cout<<y<<" ";
cout<<z<<"\n";
}
void space::operator-()
{
x=-x;
y=-y;
z=-z;
}
void main()
{ clrscr();
space s;
s.getdata(10,-20,30);
cout<<"s:";
s.display();
-s;
cout<<"s:";
s.display();
getch();
}
38
OUTPUT:
S = 10 -20 30
S = -10 20 -30
RESULT:
Thus the unary operator overloading concept was successfully executed and verified.
AIM :
To write a C++ program to implement the concept of Binary operator overloading.
ALGORITHM:
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
class complex
{
float x;
float y;
public:
complex() {}
complex(float real, float imag)
{
x=real;
y=imag;
}
complex operator+(complex c);
void display(void);
};
complex complex::operator+(complex c)
{
complex temp;
temp.x=x+c.x;
temp.y=y+c.y;
return(temp);
}
void complex::display(void)
{
cout<<x<<"+j"<<y<<"\n";
}
void main()
{
clrscr();
complex c1,c2,c3;
c1=complex(2.5,3.5);
c2=complex(1.6,2.7);
c3=c1+c2;
cout<<"c1=";
c1.display();
41
cout<<"c2=";
c2.display();
cout<<"c3=";
c3.display();
getch();
}
OUTPUT:
C1 = 2.5+j3.5
C2 = 1.6+j2.7
C3 = 4.1+j6.2
RESULT:
Thus the implementation concept of binary operator overloading was successfully
completed.
DATE:
AIM:
ALGORITHM:
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
int volume(int s)
{
return(s*s*s);
}
double volume(double r,int h)
{
return(3.14*r*r*h);
}
long volume(long l,int b,int h)
{
return(l*b*h);
void main()
{
clrscr();
cout<<"!!!VOLUME!!!\n";
cout<<volume(10)<<endl;
cout<<volume(10,20)<<endl;
cout<<volume(10,20,30)<<endl;
getch();
}
OUTPUT:
1000
157.26
112500
RESULT:
Thus the implementation of function overloading was successfully implemented and
verified.
44
AIM:
To implement single inheritance using c++.
ALGORITHM:
1. Start the program.
2. Declare the base class emp.
3. Define and declare the function get() to get the employee details.
4. Declare the derived class salary.
5. Declare and define the function get1() to get the salary details.
6. Define the function calculate() as the member of class salary to find the net pay.
7. Define the function display() as the member of class salary to display the details of the
employee.
8. Create the object s for the derived class.
9. Read the number of employees.
10. Invoke the member functions get(),get1() and calculate().
11. Invoke the member function display().
12. Stop the program.
45
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
class emp
{
public:
int eno;
char name[20],des[20];
void get()
{
cout<<"Enter the Employee Id : ";
cin>>eno;
cout<<"Enter the employee name:";
cin>>name;
cout<<"Enter the designation:";
cin>>des;
}
};
class salary:public emp
{
float bp,hra,da,pf,np;
public:
void get1()
{
cout<<"Enter the basic pay:";
cin>>bp;
cout<<"Enter the House Rent Allowance:";
cin>>hra;
cout<<"Enter the Dearness Allowance :";
cin>>da;
cout<<"Enter the Provident Fund:";
cin>>pf;
}
void calculate()
{
np=bp+hra+da-pf;
}
46
void display()
{
cout<<eno<<"\t"<<name<<"\t"<<des<<"\t "<<bp<<"\t "<<hra<<"\t "
<<da<<"\t"<<pf<<"\t"<<np<<"\n";
}
};
void main()
{
int i,n;
char ch;
salary s[10];
clrscr();
cout<<"\t EMPLOYEE DETAILS\n";
cout<<"\t------------------\n";
cout<<"Enter the number of records :";
cin>>n;
for(i=0;i<n;i++)
{
s[i].get();
s[i].get1();
s[i].calculate();
}
cout<<"EmpId EmpName Designation BasicPay HRA\tDA\tPF\tNetPay\n";
for(i=0;i<n;i++)
{
s[i].display();
}
getch();
}
47
EMPLOYEE DETAILS
------------------------------------
Enter the number of records :2
Enter the Employee Id : 1234
Enter the employee name:Rani
Enter the designation:AP
Enter the basic pay:25000
Enter the House Rent Allowance:4000
Enter the Dearness Allowance :2000
Enter the Provident Fund:1000
RESULT:
The Program to implement Single Inheritance successfully verified and executed.
48
AIM:
To write a C++ program to implement multiple inheritance.
ALGORITHM:
1. Start the program.
2. Declare the base class student.
3. Declare and define the function get() to get the student details.
4. Declare the base class sports.
5. Declare and define the function getsm() to read the sports mark.
6. Declare the class statement derived from class student and class sports.
7. Declare and define the function display() to find out the total and average.
8. Declare the derived class object, call the functions get(),getsm() and display().
9. Stop the program.
49
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
class student
{
protected:
int rollno,m1,m2;
public:
void get()
{
cout<<"Enter the Roll Number :";
cin>>rollno;
cout<<"Enter the mark1 :";
cin>>m1;
cout<<"Enter the mark2 :";
cin>>m2;
}
};
class sports
{
protected:
int sm;
public:
void getsm()
{
cout<<"Enter the sports mark :";
cin>>sm;
}
};
class report: public student, public sports
{
int tot,avg;
public:
void display()
{
tot=(m1+m2+sm);
avg=tot/3;
50
cout<<"\n\tTotal : "<<tot;
cout<<"\n\tAverage : "<<avg;
}
};
void main()
{
clrscr();
report obj;
cout <<"\t STUDENT DETAILS\n";
cout <<"\t-----------------------------\n";
obj.get();
obj.getsm();
obj.display();
getch();
}
OUTPUT:
STUDENT DETAILS
----------------------------
Enter the Roll Number :123456
Enter the mark1 :80
Enter the mark2 :90
Enter the sports mark :78
Total : 248
Average : 82
RESULT:
The Program to implement the Multiple Inheritance has been successfully verified and
executed using C++.
DATE:
AIM:
To write a C++ program to implement multilevel inheritance.
ALGORITHM:
1. Start the program.
2. Declare the base class student.
3. Declare and define the function getdata() to get the student details.
4. Declare and define the function putdata() to display the student details.
5. Declare the class test derived from student.
6. Declare and define the function gettest() to read the marks.
7. Declare and define the function puttest() to display the marks.
8. Declare the class result derived from test.
9. Declare and define the function displayresult() to find out the total marks.
10. Declare the derived class object, call the functions getdata(),gettest() and displayresult().
11. Stop the program.
52
SOURCE CODE:
#include<iostream.h>
#include <conio.h>
class student
{
protected:
int roll_number;
public:
void get_number(int a)
{
roll_number=a;
}
void put_number(void)
{
cout<<"Roll Number :"<<roll_number<<"\n";
}
};
class test :public student
{
protected:
float sub1,sub2;
public:
void get_marks(float x,float y)
{
sub1=x;
sub2=y;
}
void put_marks(void)
{
cout<<"\nMarks in Subject 1 ="<<sub1;
cout<<"\nMarks in Subject 2 ="<<sub2<<"\n";
}
};
class result: public test
{
protected:
53
float total;
public:
void display(void)
{
total=sub1+sub2;
put_number();
put_marks();
cout<<"Total :"<<total<<"\n";
}
};
void main()
{
result s;
clrscr();
cout<<"\t MULTILEVEL INHERITANCE";
cout<<"\n\t------------------------\n";
s.get_number(111);
s.get_marks(80.5,75.5);
s.display();
getch();
}
OUTPUT:
MULTILEVEL INHERITANCE
-----------------------------------------
Roll Number :111
Marks in Subject 1 =80.5
Marks in Subject 2 =75.5
Total :156
RESULT:
The Program to implement the Multilevel Inheritance has been successfully verified and
executed using C++.
DATE:
AIM:
ALGORITHM:
1. Start the program.
2. Define the base class base.
3. Define the base class virtual function display() using the keyword virtual.
4. Derive the classes sub1, sub2 from base class base and define the function display() in
the respective classes.
5. Declare a base class pointer in main function.
6. Declare objects for d1 and d2 for the classes sub1 and sub2.
7. Assign the objects to the base pointer *bptr.
8. Invoke the display() function using -> pointer.
9. Depending upon the object in the bptr the appropriate
display() function is displayed.
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
55
class base
{
public:
virtual void display()
{
cout<<"Base class display is called\n";
}
};
OUTPUT:
VIRTUAL FUNCTION
------------------------------------
Base class display is called
RESULT:
Thus the C++ program for virtual function is verified and executed successfully.
AIM:
ALGORITHM:
1. Start the program
2. Include suitable header files
3. Create a base class student.
4. In the base class student define the function get_number() and put_number().
5. In the class sports define the function get_score() and put_score().
6. Derive a class test form base student and define the function get_mark() and
put_mark().
7. Derive a class result from test and sports class and define function display().
8. Create the object s for the class result using the object invoke the functions
get_number(), get_score(), get_mark() and display().
9. Stop the program
58
SOURCE CODE:
#include<iostream.h>
#include <conio.h>
class student
{
protected:
int roll_number;
public:
void get_number(int a)
{
roll_number=a;
}
void put_number(void)
{
cout<<"ROLL NO:"<<roll_number<<"\n";
}
};
class test :public virtual student
{
protected:
float part1,part2;
public:
void get_marks(float x,float y)
{
part1=x;
part2=y;
}
void put_marks(void)
{
cout<<"Marks Obtained:\n";
cout<<"Part 1 = "<<part1;
cout<<"\nPart 2 = "<<part2;
}
};
class sports: public virtual student
{
protected:
float score;
public:
void get_score(float s)
{
score=s;
}
59
void put_score(void)
{
cout<<"\nSports wt : "<<score;
}
};
float total;
public:
void display(void);
};
void result::display(void)
{
total=part1+part2+score;
put_number();
put_marks();
put_score();
cout<<"\nTotal Score : "<<total<<"\n";
}
void main()
{
result s;
clrscr();
cout<<"\t VIRTUAL BASECLASS";
cout<<"\n\t-------------------\n";
s.get_number(678);
s.get_marks(30.5,25.5);
s.get_score(7.0);
s.display();
getch();
}
60
OUTPUT:
VIRTUAL BASECLASS
--------------------------------
ROLL NO:678
Marks Obtained:
Part 1 = 30.5
Part 2 = 25.5
Sports wt : 7
Total Score : 63
RESULT:
Thus the C++ program for virtual base class is verified and executed successfully.
61
ALGORITHM:
1. Start the program.
2. Create the class template test using the keyword template.
3. Declare the two member variables a and b of type T.
4. Define the parameterized constructor with two variables x and y in the argument list of
type T1 and T2.
5. The variables a and b acts as alias variable for x and y.
6. Objects test1,test2,test3 and test4 are created and the different type of data values are
passed to the constructor test.
7. Display the vales of a and b
8. Stop the process.
62
SOURCE CODE:
#include <iostream.h>
#include <conio.h>
template <class T1, class T2>
class test
{
T1 a;
T2 b;
public :
test (T1 x, T2 y)
{
a= x;
b= y;
cout << "\n\nThe value of a is : "<<a;
cout << "\nThe value of b is : "<<b;
cout <<" \n Sum is :" << a+b;
}
};
void main()
{
clrscr();
cout<< " CLASS TEMPLATES";
cout<<"\n------------------";
test <int,int> test1(10,20);
test <float,float> test2(15.5,25.5);
test <int,float> test3(20,25.5);
test <float,int> test4(15.5,30);
getch();
}
63
OUTPUT:
CLASS TEMPLATES
---------------------------
The value of a is : 10
The value of b is : 20
Sum is :30
The value of a is : 20
The value of b is : 25.5
Sum is :45.5
RESULT:
Thus the program for implementing the concept of class template was successfully
verifies and executed successfully.
64
To write a C++ program for swapping two values using function templates
ALGORITHM:
1. Start the program.
2. Create the template class X using the keyword template.
3. Create the parameterized member function bubble() with two variables in the argument
list to perform bubble sort.
4. Define the member function swap() to swap the values of the variables a and b.
5. Display the values in the array before and after sorting.
6. Stop the program.
65
SOURCE CODE:
#include <iostream.h>
#include <conio.h>
template <class T>
void bubble(T a[],int n)
{
for(int i=0;i<n-1;i++)
for(int j=n-1;i<j;j--)
if ( a[j]<a[j-1])
swap(a[j],a[j-1]);
}
template <class X>
void swap(X &a, X &b)
{
X temp=a;
a=b;
b=temp;
}
void main()
{
int x[5]={6,4,8,2,1};
float y[5]={1.1,3.5,4.5,2.2,3.3};
clrscr();
cout<< " FUNCTION TEMPLATES";
cout<<"\n------------------";
cout <<"\nGiven X Array";
cout <<"\n--------------\n";
for (int i=0;i<5;i++)
cout <<x[i]<<"\t";
bubble(x,5);
cout <<"\nSorted X Array";
cout <<"\n--------------\n";
for ( i=0;i<5;i++)
cout <<x[i]<<"\t";
bubble(y,5);
getch();
}
OUTPUT:
FUNCTION TEMPLATES
----------------------------------
Given X Array
------------------
6 4 8 2 1
Sorted X Array
-------------------
1 2 4 6 8
Given Y Array
-------------------
1.1 3.5 4.5 2.2 3.3
Sorted Y Array
-------------------
1.1 2.2 3.3 3.5 4.5
RESULT:
Thus the C++ program for function template was verified successfully executed.