22CST202-OOPS Lab Record
22CST202-OOPS Lab Record
NAME :
REGISTER NO. :
YEAR/ SEMESTER : I Year / II Sem
ACADEMIC YEAR : 2023-2024
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LABORATORY RECORD
BONAFIDE CERTIFICATE
Mr. /Ms Register Number of the Year 2023-2024 B.E. Department of Computer
Science and Engineering in the 22CST202 - Object Oriented Programming
Laboratory for the Second Semester University Examination held on .
Signature of Examiners:
Mission of JNNIE:
1. To develop the required resources and infrastructure and to establish a
conducive ambience for the teaching-learning process.
2. To nurture professional and ethical values in the students and to instils in them a
spirit of innovation and entrepreneurship.
3. To encourage a desire for higher learning and research in the students and to
equip them to face global challenges.
Department of Mission:
M1. Establish closer relationship with IT industries and expose the students to the cutting
edge technological advancements.
M2. Provide impetus and importance to beyond curriculum learning and thereby provide
an opportunity for the student community to keep them updated with latest and socially
relevant technology.
Our graduates will have the ability and attitude to adapt to emerging 3 3 2
technological changes.
PO2 Problem analysis: Identify, formulate, review research literature, and analyze
complex engineering problems reaching substantiated conclusions using first
principles of mathematics, natural sciences, and engineering sciences.
PO5 Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.
PO6 The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.
PO7 Environment and sustainability: Understand the impact of the professional
engineering solutions in societal and environmental contexts, and demonstrate the
knowledge of, and need for sustainable development.
PO8 Ethics: Apply ethical principles and commit to professional ethics and
responsibilities and norms of the engineering practice.
PO9 Individual and team work: Function effectively as an individual, and as a member
or leader in diverse teams, and in multidisciplinary settings.
PO12 Life-long learning: Recognize the need for, and have the preparation and ability
to engage in independent and life-long learning in the broadest context of
technological change.
OBJECTIVES: This lab manual demonstrates familiarity with various concepts of OOPS.
CO 2 3 3 3 2 2 2 3 3 3 3 3
1
CO 2 3
2
CO 3 3 2 2 3 3 3 3 3
3
CO 2 1 2 2 3
4
CO 2 3 2 2 2 2 2 3
5
CO 1 2 2 2 2 1 2 2 3 3
6
LIST OF EXPERIMENTS
PROGRAMMING IN C++
f) Inline Function
f) Friend Function
c) Function Overloading
4 a) Single Inheritance
b) Multiple Inheritance
c) Multilevel Inheritance
d) Virtual Function
f) Class Templates
g) Function Template
AIM:
To write a C++ program to find the sum of the given variables using function with
default arguments.
ALGORITHM:
#include <iostream>
using namespace std;
// Function with default arguments to calculate the area of a rectangle
double calculateArea(double length = 1.0, double width = 1.0)
{
return length * width;
}
int main()
{
double length, width;
// Prompting the user to enter length and width or providing default
values cout << "Enter length of rectangle (default is 1.0): ";
cin >> length;
cout << "Enter width of rectangle (default is 1.0): ";
cin >> width;
// Calculate area using function with default arguments
double area = calculateArea(length, width);
// Displaying the area of the rectangle
cout << "Area of rectangle: " << area << endl;
return 0;
}
Output:
Enter length ofrectangle (default is 1.0): 4.5
Enter width of rectangle (default is 1.0): 2.5
Area of rectangle: 11.25
RESULT:
The program to implement the variables using function with default arguments has
been executed successfully using C++.
EX. NO. 1B FUNCTIONS WITH DEFAULT ARGUMENTS DATE:
AIM:
To implement the concept of function with default arguments.
ALGORITHM:
1. Start the program.
2. Include the iostream library for input/output operations.
3. Define a function named printLine with two parameters: ch (a character, defaulted to '_')
and Repeatcount (an integer, defaulted to 70).
4. Inside the function, print a newline character (endl) to start a new line.
5. Use a for loop to iterate Repeatcount times.
6. Inside the loop, print the character ch.
7. Define the main function, the entry point of the program.
8. Call printLine function multiple times with different arguments to print lines of
characters with specified repetitions:
▪ Call printLine with no arguments to print a line of default characters ('_')
repeated 70 times.
▪ Call printLine with the character '/' to print a line of '/' repeated 70 times. ▪
Call printLine with the character '' and repeat count 40 to print a line of ''
repeated 40 times.
▪ Call printLine with the character 'R' and repeat count 55 to print a line of 'R'
repeated 55 times.
9. Implement the printLine function according to its definition, providing the logic to print
lines of characters with specified repetitions.
10. Compile and execute the program to observe its behavior and output.
SOURCE CODE:
#include <iostream>
using namespace std;
void printLine(char ='_', int =40);
int main() {
printLine();
printLine('/');
printLine('*', 30);
printLine('S', 35);
return 0;
}
void printLine(char ch, int Repeatcount)
{
int i;
cout << endl;
for(i = 0; i < Repeatcount; i++)
cout << ch;
}
OUTPUT:
////////////////////////////////////////
******************************
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
RESULT:
The program to implement the concept of function with default arguments
has been executed successfully using C++.
EX NO . 1C IMPLEMENTATION OF CALL BY VALUE DATE:
AIM:
To write a C++ program to find the value of a number raised to its power using call
by value.
ALGORITHM:
1. Start the program.
2. Declare two integer type variables X and Y.
3. Get the values for the variables X and Y.
4. Call the function power() to which a copy of the two variables is passed. 5. The function
power() is defined to calculate the value of x raised to power y and result is saved in p.
6. Return the value of p to the main function.
7. Display the result.
8. Stop the program.
SOURCE CODE:
#include <iostream>
using namespace std;
double power(int x, int y);
int main()
{
int x, y;
cout << "Enter x, y:" << endl;
cin >> x >> y;
cout << x << " to the power " << y << " is " << power(x, y);
return 0;
}
double power(int x, int y)
{
if (x == 0 && y < 0)
{
cout << "Error: Cannot raise 0 to a negative power." <<
endl; exit(1); // Exit the program with an error code
}
double p = 1.0;
if (y >= 0)
{
while (y--)
p *= x;
}
else
{
while (y++)
p /= x;
}
return p;
}
OUTPUT:
Enter x, y:
23
2 to the power 3 is 8
RESULT:
The program to implement the concept of Call by Value has been executed
successfully using C++.
EX. NO. 1D IMPLEMENTATION OF CALL BY ADDRESS DATE:
AIM:
To write a C++ program to implement the concept of Call by
Address. ALGORITHM:
SOURCE CODE:
#include <iostream>
using namespace std;
void swap(int *x, int *y); // Function prototype declaration
int main()
{
int i, j;
i = 10;
j = 20;
cout << "\nThe value of i before swapping is: " << i;
cout << "\nThe value of j before swapping is: " << j;
swap(&i, &j); // Call the swap function
cout << "\nThe value of i after swapping is: " << i;
cout << "\nThe value of j after swapping is: " << j;
return 0;
}
void swap(int *x, int *y)
{
// Function definition
int temp = *x;
*x = *y;
*y = temp;
}
OUTPUT:
The value of i before swapping is: 10
The value of j before swapping is: 20
The value of i after swapping is: 20
The value of j after swapping is: 10
RESULT:
The program to implement the concept of Call by Address has been executed
successfully using C++.
EX.NO:1E IMPLEMENTATION OF CALL BY REFERENCE DATE:
AIM:
To write a program in C++ to implement the concept of call by
reference. ALGORITHM:
#include <iostream>
using namespace std;
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;
}
int main()
{
int x, y;
float n, m;
cout << "\n Enter the Integer number of two numbers\
n"; cin >> x >> y;
refer(x, y);
refer(n, m);
return 0;
}
OUTPUT:
RESULT:
The program to implement Call by Reference has been executed successfully using C++.
EX.NO:1F INLINE FUNCTION
DATE:
AIM:
To write C++ program to implement inline function.
ALGORITHM:
//inline function
#include <iostream>
using namespace std;
inline float mul(float x, float y)
{
return (x * y);
}
int main() {
float x ;
float y ;
return 0;
}
OUTPUT:
INLINE FUNCTION
Enter the value x:
25.2
Enter the value y:
35.3
Multiplication: 889.56
Division: 0.713881
RESULT:
The program to implement the Inline Function has been executed successfully using C++.
EX.NO.2A CLASSES WITH PRIMITIVE DATA MEMBERS DATE:
AIM:
To write a program in C++ to prepare a student record using classes with primitive
data members.
ALGORITHM:
#include<iostream>
using namespace std;
class record
{
public:
char name[20];
int regno;
int marks,m1,m2,m3,m4,m5;
float avg;
void getdata()
{
cout<<"Enter the name:\n";
cin>>name;
cout<<"Enter the regno:";
cin>>regno;
cout<<"Enter the Subject marks m1,m2,m3,m4,m5:\
n"; cin>>m1>>m2>>m3>>m4>>m5;
void calculate()
{
avg=(m1+m2+m3+m4+m5)/5;
}
void display()
{
void display() {
cout << "******************\n";
cout << "\nName: " << name;
cout << "\nRegno: " <<
regno; cout << "\nMark1: "
<< m1;
cout << "\nMark2: " << m2;
cout << "\nMark3: " << m3;
cout << "\nMark4: " << m4;
cout << "\nMark5: " << m5;
cout << "\nAvg: " << avg;
cout << "\n******************\
n"; }};
int main()
{
record r;
r.getdata();
r.calculate();
r.display();
return 0;
}
OUTPUT:
Enter the name: lokesh
Enter the regno: 1107
Enter the Subject marks m1,m2,m3,m4,m5:
58
96
78
96
98
******************
Name: Lokesh
Regno: 11072404001
Mark1: 58
Mark2: 96
Mark3: 78
Mark4: 96
Mark5: 98
Avg: 85
******************
RESULT:
The program in C++ to prepare a student Record using classes with primitive
data members was verified and executed successfully.
EX.NO.2B CLASSES WITH ARRAYS AS DATA MEMBERS DATE:
AIM:
To write a program in C++ to display product detail using classes with array as
data members.
ALGORITHM:
while(x!=4);
}
OUTPUT:
1.Add a product
2.Display a product total
value 3.Display all products
4.Quit
1
Enter product
Code:4002 Enter
product Cost:2500 Total
Value:2500
Code Price
4002 2500
1.Add a product
2.Display a product total
value 3.Display all products
4.Quit
1
Enter product
Code:4005 Enter
product Cost:6500 Total
Value:9000
Code Price
4002 2500
4005 6500
1.Add a product
2.Display a product total
value 3.Display all products
4.Quit
2
Total Value:9000
Code Price
4002 2500
4005 6500
Enter your choice
1.Add a product
2.Display a product total value
3.Display all products
4.Quit
3
Code Price
4002 2500
4005 6500
Enter your choice
1.Add a product
2.Display a product total value
3.Display all products
4.Quit
4
RESULT:
The program in C++ to implement arrays as data members was created and
executed successfully.
EX.NO.2C CLASSES WITH POINTERS AS DATA MEMBERS DATE:
AIM:
Write a program in C++ to implement the classes with pointers as data
members. ALGORITHM:
a:10 a:20
RESULT:
The program in C++ to implement classes with pointers as data members was
verified and executed successfully.
EX.NO.2D CLASSES WITH CONSTANT DATA MEMBER DATE:
AIM:
To write a program in C++ implements the concept of class with constant data member.
ALGORITHM:
RESULT:
The program in C++ to implement classes with constant data members was verified
and executed successfully.
EX.NO.2E CLASSES WITH STATIC MEMBER FUNCTION DATE:
AIM:
To write a program in C++ to implement the concept of class with static member
functions. ALGORITHM:
OUTPUT:
count:2
count:3
object number:1
object number:2
object number:3
RESULT:
The program in C++ to implement classes with static member function was verified and
executed successfully.
EX.NO:2F FRIEND FUNCTION
DATE:
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.
}
OUTPUT:
FRIEND FUNCTION:
Mean value =32.5
RESULT:
The program in C++ to implement the Friend Function was verified and
executed successfully.
EX.NO.3A UNARY OPERATOR OVERLOADING DATE:
AIM:
To implement the concept of unary operator overloading using c++.
ALGORITHM:
void operator-();
};
void space::getdata(int a,int b,int
c) {
OUTPUT:
s: 10 -20 30
s: -10 20 -30
RESULT:
The program in C++ to implement unary operator overloading concept was verified
and executed successfully.
EX.No. 3B BINARY OPERATOR OVERLAODING DATE:
AIM :
To write a C++ program to implement the concept of Binary operator
overloading. ALGORITHM:
complex temp;
temp.x = x+c.x;
temp.y = y+c.y;
return(temp);
}
void complex::display(void)
{
cout<<x<<"+j"<<y<<"\n";
}
int main()
{
complex c1,c2,c3;
c1=complex(2.5,3.5);
c2=complex(1.6,2.7);
c3=c1+c2;
cout<<"c1="; c1.display(); cout<<"c2=";
c2.display();
cout<<"c3="; c3.display();
return 0;
}
OUTPUT:
c1=2.5+j3.5
c2=1.6+j2.7
c3=4.1+j6.2
RESULT:
The program in C++ to implement binary operator overloading concept was verified and
executed successfully.
EX.NO.3C FUNCTION OVERLOADING
DATE:
AIM:
To write a C++ program to implement the concept of Function
Overloading. ALGORITHM:
int volume(int s)
{
return (s * s * s);
}
int main()
{
int s, l, b, h;
double r;
cout << "Enter the value of length, breadth and height: ";
cin >> l >> b >> h;
cout << "Volume of a Rectangle: " << volume(l, b, h) << endl;
return 0;
}
OUTPUT:
!!VOLUME!!!
Enter the value of s: 5
Volume of a Cube: 125
Enter the value of radius and height: 5 10
Volume of a Cylinder: 785
Enter the value of length, breadth and height: 12 6 4
Volume of a Rectangle: 288
RESULT:
The program in C++ to implement function overloading concept was verified
and executed successfully.
EX.NO:4A SINGLE INHERITANCE
DATE:
AIM:
To write a C++ program 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.
SOURCE CODE:
#include<iostream>
using namespace std;
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;
}
};
int main()
{
int i,n;
char ch;
salary s[10];
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();
}
return 0;
}
EMPLOYEE DETAILS
RESULT:
The program in C++ to implement Single Inheritance concept was verified and executed
successfully.
EX.NO:4B MULTIPLE INHERITANCE DATE:
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.
SOURCE CODE:
#include<iostream>
using namespace std;
class student
{
protected:
int rollno, m1, m2;
public:
void get()
{
cout << "Enter the Roll Number :";
cin >> rollno;
cout << "Enter mark1 :";
cin >> m1;
cout << "Enter mark2 :";
cin >> m2;
}
int getMark1() const
{
return m1;
}
int getMark2() const
{
return m2;
}
};
class sports
{
protected:
int sm;
public:
void getsm()
{
cout << "Enter the sports
mark :"; cin >> sm;
}
int getSportsMark() const
{
return sm;
}
};
class report : public student, public sports
{
int tot;
float avg;
public:
void display() {
tot = (getMark1() + getMark2() +
getSportsMark()); avg = static_cast<float>(tot) / 3;
cout << "\n\tTotal : " << tot;
cout << "\n\tAverage : " << avg;
}
};
int main()
{
report obj;
cout << "\t STUDENT DETAILS\n";
cout << "\t \n";
obj.get();
obj.getsm();
obj.display();
return 0;
}
OUTPUT:
STUDENT DETAILS
Total 248
Average 82
RESULT:
The Program in C++ to implement the Multiple Inheritance has been verified
and executed successfully
EX.NO:4C MULTILEVEL INHERITANCE
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.
SOURCE CODE:
#include<iostream>
using namespace std;
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:
float total;
public:
void display(void)
{
total=sub1+sub2;
put_number();
put_marks();
cout<<"Total :"<<total<<"\n";
}
};
int main()
{
result s;
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 verified and
executed successfully using C++.
EX. NO. 4D VIRTUAL FUNCTION
DATE:
AIM:
To write a C++ program to implement the concept of Virtual functions
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>
using namespace std;
class base {
public:
virtual void display() {
cout << "Base class display is called\
n"; }
};
};
int main() {
base *bptr, b;
sub1 d1;
sub2 d2;
cout << "\t VIRTUAL FUNCTION\n";
cout << "\t \n";
bptr = &b;
bptr->display();
bptr = &d1;
bptr->display();
bptr = &d2;
bptr->display();
return 0;
}
OUTPUT:
VIRTUAL FUNCTION
RESULT:
The program to implement the virtual function has been verified and executed
successfully using C++.
EX. NO:4E VIRTUAL BASE CLASS
DATE:
AIM:
To write a C++ program to implement the concept of virtual base class.
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
SOURCE CODE:
#include<iostream>
using namespace std;
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"; }
};
score = s;
}
void put_score(void)
{
cout << "Sports wt : " << score << "\
n"; }
};
class result : public test, public
sports {
float total;
public:
void display(void);
};
void result::display(void)
{
total = part1 + part2 + score;
put_number(); // Call base class member function first
put_marks(); // Call test class member function next
put_score(); // Call sports class member function last
cout << "Total Score : " << total << "\n";
}
int main()
{
result s;
cout << "\tVIRTUAL BASECLASS";
cout << "\n\t -----------------\n";
s.get_number(678);
s.get_marks(30.5, 25.5);
s.get_score(7.0);
s.display();
return 0;
}
OUTPUT:
VIRTUAL BASECLASS
ROLL NO:678
Marks Obtained:
Part 1 = 30.5
Part 2 = 25.5
Sports wt : 7
Total Score : 63
RESULT:
The Program to implement the virtual base class has been verified and executed
successfully using C++.
EX.NO:4F CLASS TEMPLATES
Date:
AIM:
To write a C++ program to implement the concept of class template.
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.
SOURCE CODE:
#include <iostream.h>
using namespace std;
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; }
};
int main()
{
cout<< " CLASS
TEMPLATES"; cout<<"\n ";
}
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:
The Program to implement the class templates has been verified and executed
successfully using C++.
EX. NO:4G FUNCTION TEMPLATE
DATE:
AIM:
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.
SOURCE CODE:
#include <iostream.h>
using namespace std;
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]);
}
emplate <class X> void
swap(X &a, X &b)
{
X temp=a;
a=b;
b=temp;
}
int main()
{
int x[5]={6,4,8,2,1};
float y[5]={1.1,3.5,4.5,2.2,3.3};
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";
cout <<"\nGiven Y Array";
cout <<"\n-------------\n";
for (int j=0;j<5;j++)
cout <<y[j]<<"\t";
bubble(y,5);
cout <<"\nSorted Y Array";
cout <<"\n------------ \n";
for ( j=0;j<5;j++)
cout <<y[j]<<"\t";
return;
}
OUTPUT:
FUNCTION TEMPLATES
Given X Array
64821
Sorted X Array
12468
Given Y Array
RESULT:
The Program to implement the function templates has been verified and executed
successfully using C++.