0% found this document useful (0 votes)
92 views71 pages

RAJIV SAHU C++ Practicle PDF

This document is a practical report submitted by Rajiv Sahu for their BCA program. It contains 21 programming assignments completed by the student between August and October related to C++ programming. The assignments cover topics like pattern printing, number systems, arithmetic operations, classes, structures, matrices, complex numbers, and more. Each assignment is listed with the date of practical and submission. An index at the beginning provides an overview of the assignments and page numbers.

Uploaded by

Vikash Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views71 pages

RAJIV SAHU C++ Practicle PDF

This document is a practical report submitted by Rajiv Sahu for their BCA program. It contains 21 programming assignments completed by the student between August and October related to C++ programming. The assignments cover topics like pattern printing, number systems, arithmetic operations, classes, structures, matrices, complex numbers, and more. Each assignment is listed with the date of practical and submission. An index at the beginning provides an overview of the assignments and page numbers.

Uploaded by

Vikash Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 71

A

PRACTICAL
REPORT
ON
“PROGRAMMING IN C++”
SUBMITTED TO
HEMCHAND YADAV UNIVERSITY, DURG (C.G.)
FOR THE PARTIAL FULLFILLMENT OF THE DEGREE
OF
Bachelor Of Computer Application
Session 2023-2024

Guided By: Submitted By:


Dr. Ashish Tamrakar Rajiv sahu
ASST. PROFESSOR BCA 2nd Year
RUNGTA COLLEGE OF SCIENCE AND TECHNOLOGY

GANGPARA DURG (C.G.)


INDEX
Sno. Aim Page no. Date of Date of Signature
Practical Submission
1. Write a program to generate following 22-08-23
pattern
a) ABCDEFG
ABC EFG
c) *
AB F G * *
A G
* * *
b) 1 d) 1
12 121
123 1331
1234 14641

2. Write a program to display number 1 to 10 22-08-23


in octal, decimal and hexa-decimal system.
3. Write a C++ program to Multiply two 24-08-23
floating point numbers.

4. Write a C++ program to convert Celsius to 24-08-23


Fahrenheit.

5. Write a program using function to add, 31-08-23


subtract and multiply two matrices of
order 3x3 you have to create one function
for addition , which accepts three array
arguments are matrices toad and third
matrix is destination where the resultant
of addition of first two matric4s is
stored .In similar way to create functions
for marks subtraction and multiplication

6. Create a single program to perform 31-08-23


following tasks without using library
functions:

a. To reserve the string accepted as


argument.
b. To count the number of characters in
strings passed as argument in form of
source character array.
c. To copy the one string to other string;
passed as argument in form of source
character array and destination
character array without using library
function.
d. d) To count no. of vowels, consonants
n each word of a sentence passed as
argument in form of character array
7. create a class student having data member 07-09-23
to store roll number, name of student,
name of three subject, max marks, min
marks, obtained marks. Declare an object
of class student. Provide facilities to input
data in data member and display result of
student.

8. Create a class salary having an array of 07-09-23


integer 5 elements as data member
provide followings:

a. Constructor to get number in array


elements.
b. Sort the element.
c. Find largest element.
d. d) Search for presence of particular
value in array element.
9. Create a class simple with static member 12-09-23
functions for following tasks:

a. To find factorial by recursive member


function.
b. To check whether a number is prime
or not.
c. c) To generate Fibonacci series up to
requested terms.
10. Write a program using class having class 12-09-23
name Darray. Darray has pointer to pointer
to integer as data member to implement
double dimension dynamic array and
provide following facilities:
a. Constructor to input value in an array
element. b) Input member function to
get input in array element.
b. Output member function to print
element value.
c. Add member function to perform
matrix addition using objects.
d. Subtract member function to perform
matrix subtraction using objects.
e. f) Multiply member function to
perform matrix multiplication using
objects.

11. Write program to create class complex 21-09-23


having data members to store real and
imaginary part. Provide following facilities:

a. Add two complex no. using objects.


b. Subtract two complexes no. using
objects.
c. Multiply two complexes no. using
objects.
d. d) Divide two complex no. using
objects
12. Write program to create class distance 21-09-23
having data members feet and inch (A
single object will store distance in form
such as 5 feet 3 inch). It contains member
functions for taking input in data members
and member function for displaying value
of data members. Class Distance contains
declaration of friend function add which
accepts two objects of class Distance and
returns object of class Distance after
addition. Class Distance contains
declaration of another friend function.
Subtract accepts two objects of class
Distance and returns object of class
Distance after subtraction. Text the class
using main function and objects of class
Distance.

13. Write a program to create class Mother 26-09-23


having data member to store salary of
Mother, create another class Father having
data member to store salary of Father.
Write a friend function, which accepts
objects of class Mother, and Father and
prints Sum of Salary of Mother and Father
objects.

14. Write a program to create class Mother 26-09-23


having data member to store salary of
Mother, create another class Father having
data member to store salary of Father.
Declare class Father to be friend class of
Mother. Write a member function in
Father, which accepts object of class
Mother and prints Sum of Salary of
Mother and Father Objects. Create
member function in each class to get input
in data member and to display the value of
data member.

15. : Define structure student. Structure 28-09-23


student has data members for storing
name, rollno , name of three subjects and
marks, write member function to store
and print data.

16. Write program to create a class Polar 28-09-23


which has data member radius and angels,
define overloaded constructor to initialize
object and copy constructor to initialize
one object by another existing objects
keep name of parameter of parameterized
constructor same as data members. Test
function of the program in main function.

17. Write program to create a class polar 17-10-23


which has data member radius and angle,
use constructor with default arguments to
avoid constructor overloading and copy
constructor to initialize one data member.
Test functioning of the program in main
function.

18. Write a program using class, which uses 17-10-23


static overloaded function to swap two
integers; two floats’ methods use
parameter passing by address.

19. Create class String having pointer to 19-10-23


character as data member and provide
following facilities:
a. Constructor for initialization and
memory allocation.
b. Destructor for memory release.
c. Overloaded operator + to add two
string objects.
d. Overloaded operator = to assign one
string object to other t=string object.
e. Overloaded operator = = to compare
whether the two string objects are
equal or not.
f. Overloaded operator < to compare
whether first-string object is less than
second-string object.
g. Overloaded operator > to compare
whether first-string object is greater
than second-string object or not.
h. Overloaded operator <= to compare
whether first string object is less than
or equal to second string object or
not.
i. Overloaded operator >= to compare
whether first string object is greater
than or equal to second string object.
j. Overloaded operator is != to compare
whether first string object is not object
is not equal to second string object or
not.
k. k) Overloaded insertion and extraction
operator for input in data member and
display output of data members.

20. Create a class Matrix having data member 19-10-23


double dimension array of floats of size
3x3. provide following facilities:

a) Overloaded extraction operator for data


input.
b) Overloaded insertion operator for data
output.
c) Overloaded operator + for adding two using
matrix objects.
d) Overloaded operator – for subtracting two
using matrix objects.
e) Overloaded operator * for multiplying two
using matrix objects.
21. Create a class Polar having radius and 31-10-23
angle as data members. provide following
facilities:

a. Overloaded insertion and extraction


operators for data input and display.
b. Over loaded constructor for
initialization of data members.
c. c) Overloaded operator + to add two
polar co-ordinates using objects of
class Polar.
22. Create a class polar that contains data 31-10-23
member radius and angels. Create another
class Cartesian in the same program and
provide following facilities:

a. It should be possible to assign object


of polar class to object of cartesian
class.
b. It should be possible to assign object
of Cartesian class to object of polar
class.

23. Write a program to find biggest number 21-11-23


among three number using pointer and
function.

24. Write swapping program to demonstrate 23-11-23


call by value , call by address and call by
reference in a simple program.

25. : Write a program using inline function to 30-11-23


calculate area of circle.
26. : Write a program using inline function to 05-12-23
find minimum of two functions. The inline
function should take two arguments and
should return the minimum value.

27. : Create a class circle with data member 07-12-23


radius; provide member function to
calculate area. Derive a class sphere from
class circle; provide member function to
calculate volume. Derive class cylinder
from class sphere with additional data
member for height and member function
to calculate volume.

28. Create a base class shape having two data 26-12-23


members with two-member function get
data (pure virtual function) and print area (
not pure virtual function). Derive classes
triangle and rectangle from class shape
and redefine member function print area
in both classes triangle and rectangle and
test the functioning of classes using
pointer to base class objects and normal
objects.

29. Write a class name having Calculate that 02-01-24


uses static overloaded function to
calculate area of circle, area of rectangle,
area of triangle.

30. Write a class ArraySort that uses static 02-01-24


overloaded function to sort array of floats,
an array of integers.
Practical: 01
AIM: Write a program to generate following pattern.

b) A B C D E F G C) *
ABC EFG
* *
AB F G
* * *
A G

b) 1
d) 1
12
121
123
1331
1234
14641

CODING:-
#include<iostream>
#include<conio.h>
using namespace std;
long fact(int);
int main()
{
int i,j,k,space=1, ctr=1;
char ch1='D', ch2='D',ch;
cout<<"\nPattern 1 :-\n\n";
for(i=1;i<=4; i++)
{
for (ch='A';ch<=ch1;ch++)
cout<<ch;
if (i==1)
cout<<"\b";
for(j=2;j<space;j++)
cout<<" ";
for (ch=ch2;ch<='G';ch++)
cout<<ch;
cout<<"\n";
ch1--;
ch2++;
space+=2;
}
cout<<"\nPress any key !";
getch();
cout<<"\n\nPattern 2 :-\n\n";
space=2;
for (i=1;i<=3;i++)
{
for(j=1;j<=space;j++)
cout<<" ";
for (k=1;k<=ctr;k++)
cout<<"* ";
cout<<"\n";
space--;
ctr++;
}
cout<<"\nPress any key !";
getch();
cout<<"\n\nPattern 3 :-\n\n";
for (i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
cout<<j<<" ";
cout<<"\n";
}
cout<<"\nPress any key !";
getch();
cout<<"\n\nPattern 4 :-\n\n";
for(i=0;i<5;i++)
{
for(j=0;j<=i;j++)
cout<<fact(i)/(fact(j)*fact(i-j))<<" ";
cout<<"\n";
} cout<<"\nPress any key to EXIT!";
getch();
}
long fact (int n){
int i;
long f=1;
for (i=1;i<=n;i++)
f*=i;
return f;
}
OUTPUT:-
Practical: 02
AIM: Write a program to display number 1 to 10 in octal, decimal and hexa-decimal
system.

CODING:-

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
cout<<"Decimal Octal Hexadecimal"<<endl;

for(int i=1; i<=10; i++)


{
cout<<dec<<i<<"\t";
cout<<oct<<i<<"\t";
cout<<hex<<i<<"\n";
}
return 0;
}
OUTPUT:-
Practical: 03
AIM: Write a c++ program to Multiply two floating point numbers.

CODING:-
#include<iostream>

using namespace std;

int main()
{
double num1;
double num2;
double total;
cout << "Enter first number: "<<endl;
cin >> num1;

cout << "Enter second number: "<<endl;


cin >> num2;

total = num2 * num1;


cout << "Total is: " <<total;

return 0;

OUTPUT:
Practical: 04
AIM: Write a c++ program to convert Celsius to Fahrenheit.

CODING:-
#include <iostream>
using namespace std;

int main(){
float c;
cout << "Enter Temperature in celsius\n";
cin >> c;
float f = (9 * c) / 5;
f += 32;
cout << "Temperature in fahrenheit: " << f;
return 0;
}

OUTPUT:
Practical: 05

AIM: Write a program using function to add, subtract and multiply two matrices of order 3x3 you have
to create one function for addition , which accepts three array arguments are matrices toad and third
matrix is destination where the resultant of addition of first two matric4s is stored .In similar way to
create functions for marks subtraction and multiplication.

CODING:-
include<iostream>
#include<conio.h>
using namespace std;
void Add(int[][3],int[][3],int[][3]);
void Sub(int[][3],int[][3],int[][3]);
void Mult(int[][3],int[][3],int[][3]);
int main() {
int a[3][3],b[3][3],c[3][3],i,j;;
cout<<"Enter matrix1:\n";
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>a[i][j];
cout<<"\n Enter matrix 2:\n";
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>b[i][j];
Add(a,b,c);
Sub(a,b,c);
Mult(a,b,c);
}
void Add(int a[][3],int b[][3],int c[][3])
{
cout<<"\n\nAddition of matrices : \n";
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
cout<<c[i][j]<<" ";
}
cout<<"\n";
}
}
void Sub(int a[][3],int b[][3],int c[][3])
{
cout<<"\n\nSubstraction of matrices : \n";
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
c[i][j]=a[i][j]-b[i][j];
cout<<c[i][j]<<" ";
} cout<<"\n";
}
}
void Mult(int a[][3],int b[][3],int c[][3])
{
int sum=0;
cout<<"\n\nMultiplcaition of matrices : \n";
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
for(int k=0;k,3;k++)
sum+=a[i][k]*b[k][j];
c[i][j]=sum;
cout<<c[i][j]<<" ";
sum=0;}
cout<<"\n";
} }
OUTPUT:-
Practical: 06

AIM: Create a single program to perform following tasks without using library functions:

a) To reserve the string accepted as argument.


b) To count the number of characters in strings passed as argument in form of source
character array.
c) To copy the one string to other string; passed as argument in form of source
character array and destination character array without using library function.
d) To count no. of vowels, consonants n each word of a sentence passed as argument
in form of character array.

CODING:-
#include<iostream>
#include<stdio.h>
#include<ctype.h>
#include<conio.h>
using namespace std;
void strRev(char[ ]);
void countChar(char[ ]);
void strCopy(char[ ]);
void countVCP(char[ ]);
int main()
{
char A[50];
cout<<"\nEnter a string: ";
gets(A);
strRev(A);
countChar(A);
strCopy(A);
countVCP(A);
getch( );
}
void strRev(char A[ ])
{
int i,j,temp,ctr=0;
for(i=0;A[i]!='\0';i++)
ctr++;
for(i=ctr-1,j=0;i>=ctr/2;i--,j++)
{
temp=A[j];
A[j]=A[i];
A[i]=temp;
}
cout<<"\n\na.Reserved String: "<<A;
}
void countChar(char A[ ])
{
int i,j,ctr=0;
for(i=0;A[i]!='\0';i++)
{
if(isalpha(A[i]))
ctr++;
}
cout<<"\n\nb.Total characters in string: "<<ctr;
}
void strCopy(char A1[ ])
{
char A2[50];
int i,j,temp,ctr=0;
for(i=0;A1[i]!='\0';i++)
ctr++;
for(i=ctr-1,j=0;i>ctr/2;i--,j++)
{
temp=A1[j];
A1[j]=A1[i];
A1[i]=temp;
}
for(i=0;A1[i]!='\0';i++)
A2[i]=A1[i];
A2[i]='\0';
cout<<"\n\nc.Copies String: "<<A2;
}void countVCP(char A[ ])
{
int vowel,conso,punct;
vowel=conso=punct=0;
for(int i=0;A[i]!='\0';i++)
{
if(ispunct(A[i]))
punct++;
else if(A[i]=='a'||A[i]=='e'||A[i]=='E'||A[i]=='A'||A[i]=='i'||A[i]=='I'||A[i]=='o'||
A[i]=='O'||A[i]=='u'||A[i]=='U')
vowel++;
else if(A[i]!=' ')
conso++;
}
cout<<"\n\nd.Total no. of punctuations: "<<punct;
cout<<"\n\nd.Total no. of vowels: "<<vowel;
cout<<"\n\nd.Total no. of consonants: "<<conso;
}
OUTPUT:-
Practical: 07
AIM: create a class student having data member to store roll number, name of student,
name of three subject, max marks, min marks, obtained marks. Declare an object of class
student. Provide facilities to input data in data member and display result of student.

CODING:-
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
using namespace std;
class student
{
int roll,max,min,obt[3];
char name[20], sub[3][10];

public:
void getResult();
void putResult();
};
void student :: getResult(){
cout<<" student result entry :- \n";

cout<<"\nEnter roll number : ";


cin>>roll;

cout<<"Enter name of student : ";


cin>>name;

for(int i=0; i<3; i++)


{
cout<<"\nEnter subject"<<i+1<<" : \n";
cin>>sub[i];
cout<<"\nEnter narks obtained in subject"<<i+1<<" : \n";
cin>>obt[i];
}
cout<<"\nEnter maximum marks of all subjects : \n";
cin>>max;
cout<<"\nEnter minimum marks of all subjects : \n";
cin>>min;
}
void student :: putResult(){
int total=0;
float maxtotal;
cout<<" student result : "<<endl;

cout<<"\nStudent name : "<<name;


cout<<"\nRoll number : "<<roll<<endl;
cout<<"\nMaximum marks of all subjects :"<<max;
cout<<"\nMinimum marks of all subjects :"<<min;

cout<<"\n\nSubjects obtained"<<endl;
for(int i=0; i<3; i++){
cout<<sub[i]<<obt[i]<<endl;
total += obt[i];
}
maxtotal =max * 3;
cout<<"\nPercentages scored : "<<total/maxtotal * 100<<"m";
}
int main()
{
student s;
s.getResult();
s.putResult();
return 0;
}
OUTPUT:-
Practical: 08
AIM:- Create a class salary having an array of integer 5 elements as data member provide
followings:
a) Constructor to get number in array elements.
b) Sort the element.
c) Find largest element.
d) Search for presence of particular value in array element.

CODING:-
#include<iostream>
using namespace std;
class salary
{
int arr[];
public:
salary()
{
for(int i=0;i<5;i++)
{
cout<<"Enter element"<<i+1 <<" :";
cin>>arr[i];
}
}
void sort();
void largest();
void search(int);
};
int main()
{
int num,ch;
salary ob;
do{
cout<<"****MENU*****"<<endl;
cout<<"\n1. Sort The Array";
cout<<"\n2. Find Largest Element";
cout<<"\n3. Search For An Element";
cout<<"\n4. Exit Program";
cout<<"\n\nEnter Your Choice :";
cin>>ch;
switch(ch)
{
case 1: ob.sort();
break;
case 2: ob.largest();
break;
case 3:cout<<"\nEnter The Element Want To Search : ";
cin>>num;
ob.search(num);
break;
case 4:exit(0);
default:cout<<"\nWrong Choise!!!"<<"\npress any key";
}
}while(1);
}
void salary::sort()
{
int i,j,temp;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(arr[i]>arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
} }
}
cout<<"\nSorted Array(Asending order):\n";
for(int i=0;i<5;i++)
cout<<arr[i]<<endl;}
void salary :: largest()
{
int i,temp;
temp=arr[0];
for(i=0;i<5;i++)
{
if(temp<arr[i])
temp=arr[i];
}
cout<<"\nGreatest Element : "<<temp;
}
void salary :: search(int num)
{
int flag=0,pos,i;
for(i=0;i<5;i++)
{
if(num==arr[i])
{
flag=1;
pos=i+1;
}
}
if(flag==0)
cout<<"\nElent Not Found";
else
cout<<"\nElement Found At Position"<<pos;
}

OUTPUT:-
Practical: 09
AIM: create a class Simple with static member functions for following tasks:
a) To find factorial by recursive member function.
b) To check whether a no. is prime or not.
c) To generate Fibonacci series up to requested terms.
CODING:-

#include<iostream>
#include<stdlib.h>
using namespace std;

class Simple
{
public:
static long int fact(int);
static void Cprime();
static void fab();
};

int main()
{
int num,ch;
do{
cout<<"*MENU*"<<endl;
cout<<"\n1. Find factorial of a number";
cout<<"\n2. Check for a prime number";
cout<<"\n3. Print fibonacci series";
cout<<"\n4. Enter your choice :";
cin>>ch;

switch(ch)
{
case 1: cout<<"\nEnter a number :";
cin>>num;
cout<<"\nFactorial of "<<num<<" is :"<<Simple::fact(num);
return 0;
break;
case 2: Simple::Cprime();
return 0;
break;
case 3:Simple::fab();
return 0;
break;
case 4: exit(0);

default: cout<<"\nWrong choice !!!"<<"\nPress any key";


return 0;
}
}while(1);
}

long int Simple::fact(int num)


{
if(num==0)
return 1;
else
return num*fact(num-1);
}

void Simple::Cprime()
{
int num,flag=0;
cout<<"\n Enter a number:";
cin>>num;

for(int i=2;i<=num/2; i++)


{
if(num%i==0)
{
flag=1;
break;
}
}

if(flag==0)
cout<<"\n"<<num<<" is a Prime Number ";
else
cout<<"\n"<<num<<" Is Not A Prime Number";
}
void Simple::fab()
{
int n1=-1, n2=1, n3, num, i;
cout<<"\nEnter Number of Terms :";
cin>>num;

for(i=0; i<num; i++)


{
n3= n1+n2;
cout<<n3<<" ";
n1=n2;
n2=n3;
}
}
OUTPUT:-
Practical: 10
AIM: Write a program using class having class name darray. darray has pointer to pointer to integer as
data member to implement double dimension dynamic array and provide following facilities:

a) Constructor to input value in an array element.


b) Input member function to get input in array element.
c) Output member function to print element value.
d) Add member function to perform matrix addition using objects.
e) Subtract member function to perform matrix subtraction using objects.
f) Multiply member function to perform matrix multiplication using objects.

CODING:-

#include <iostream>
using namespace std;
class darray {
private:

int** arr;

int rows, cols;

public:

darray(int r, int c) {

rows = r;

cols = c;

arr = new int*[rows];

for (int i = 0; i < rows; i++) {

arr[i] = new int[cols];

void input() {

cout << "Enter the elements of the array:" << endl;

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

cin >> arr[i][j];

}
void output() {

cout << "Array elements:" << endl;

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

cout << arr[i][j] << " ";

cout << endl;

darray add(darray obj) {

darray result(rows, cols);

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

result.arr[i][j] = arr[i][j] + obj.arr[i][j];

return result;

darray subtract(darray obj) {

darray result(rows, cols);

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

result.arr[i][j] = arr[i][j] - obj.arr[i][j];

} return result;

darray multiply(darray obj) {

darray result(rows, obj.cols);

for (int i = 0; i < rows; i++) {

for (int j = 0; j < obj.cols; j++) {

result.arr[i][j] = 0;
for (int k = 0; k < cols; k++) {

result.arr[i][j] += arr[i][k] * obj.arr[k][j];

return result;

};

int main() {

int rows, cols;

cout << "Enter the number of rows: ";

cin >> rows;

cout << "Enter the number of columns: ";

cin >> cols;

darray array1(rows, cols);

darray array2(rows, cols);

cout << "For Array1:" << endl;

array1.input();

cout << "For Array2:" << endl;

array2.input();

cout << "Array1:" << endl;

array1.output();

cout << "Array2:" << endl;

array2.output();

darray sum = array1.add(array2);

cout<<"Addition Result:"<<endl;

sum.output();

darray diff = array1.subtract(array2);

cout<<"Subtraction Result:"<<endl;

diff.output();

darray product = array1.multiply(array2);


cout<<"Multiplication Result:"<<endl;

product.output();

return 0;

}
OUTPUT:-
Practical: 11
AIM: Write program to create class complex having data members to store real and
imaginary part. Provide following facilities:

a) Add two complex no. using objects.


b) Subtract two complexes no. using objects.
c) Multiply two complexes no. using objects.
d) Divide two complex no. using objects.

CODING:-

#include<iostream>
#include<conio.h>
#include<stdio.h>
using namespace std;

class complex
{
int real, image;
public:
void get()
{
cout<<"Enter Real Part: ";
cin>>real;
cout<<"Enter Imaginary Part: ";
cin>>image ;

}
complex add(complex c2)
{
complex c3;
c3.real=real+c2.real;
c3.image=image-c2.image ;
return c3;
}
complex subtract(complex c2)
{
complex c3;
c3.real=real-c2.real;
c3.image=image-c2.image ;
return c3;
}
complex multiply(complex c2)
{
complex c3;
c3.real=real*c2.real;
c3.image=image*c2. image;
return c3;
}
complex division(complex c2)
{
complex c3;
c3. real=real/c2. real;
c3. image=image/c2.image ;
return c3;
}
void show1()
{
cout<<"\n\n1.Addition : "<<real<<"+"<<image<<"i\n";
}
void show2()
{
if(image>0)
cout<<"\n2. Subtraction :"<<real<<"- "<<image<<"i\n";
else
cout<<"\n2.Subtraction :"<<real<<"+"<<-1*image<<"i\n";
}
void show3()
{
cout<<"\n3. Multiplication :"<<real<<" * "<<image<<"i\n";
}
void show4()
{
cout<<"\n4. Division: "<<real<<" / " <<image<<"i\n";
}
};
int main()
{
complex c1,c2,c3;

cout<<"\n Enter First Complex Number : \n";


c1.get();
cout<<"\n Enter Second Complex Number : \n";
c2.get();

c3=c1.add(c2);
c3.show1();

c3=c1.subtract(c2);
c3.show2();

c3=c1.multiply(c2);
c3.show3();

c3=c1.division(c2);
c3.show4();
return 0;

}
OUTPUT:-
Practical: 12
AIM: Write program to create class distance having data members feet and inch (A single
object will store distance in form such as 5 feet 3 inch). It contains member functions for
taking input in data members and member function for displaying value of data
members. Class Distance contains declaration of friend function add which accepts two
objects of class Distance and returns object of class Distance after addition. Class Distance
contains declaration of another friend function. Subtract accepts two objects of class
Distance and returns object of class Distance after subtraction. Text the class using main
function and objects of class Distance.

CODING:-
#include <iostream>
using namespace std;
class Distance {
private:
int feet;
int inch;
public:
void inputDistance() {
cout << "Enter the distance in feet: ";
cin >> feet;
cout << "Enter the distance in inches: ";
cin >> inch;
}

void displayDistance() {
cout << "The distance is " << feet << " feet " << inch << " inches." << endl;
}
friend Distance add(Distance d1, Distance d2) {
Distance result;
result.feet = d1.feet + d2.feet;
result.inch = d1.inch + d2.inch;
if (result.inch >= 12) {
result.feet += result.inch / 12;
result.inch %= 12;
}
return result;
}
friend Distance subtract(Distance d1, Distance d2) {
Distance result;
int totalInchesD1 = (d1.feet * 12) + d1.inch;
int totalInchesD2 = (d2.feet * 12) + d2.inch;

if (totalInchesD1 >= totalInchesD2) {


int diffInches = totalInchesD1 - totalInchesD2;
result.feet = diffInches / 12;
result.inch = diffInches % 12;
}
return result;
}
};
int main() {
Distance distance1, distance2;
cout << "Enter details for first distance:" << endl;
distance1.inputDistance();
cout << "Enter details for second distance:" << endl;
distance2.inputDistance();
cout << "\nFirst Distance:" << endl;
distance1.displayDistance();

cout << "\nSecond Distance:" << endl;


distance2.displayDistance();
Distance sumDistance = add(distance1, distance2);
cout << "\nSum of Distances:" << endl;
sumDistance.displayDistance();
Distance diffDistance = subtract(distance1, distance2);
cout << "\nDifference of Distances:" << endl;
diffDistance.displayDistance();
return 0;
}

OUTPUT:-
Practical: 13
AIM: Write a program to create class Mother having data member to store salary of
Mother, create another class Father having data member to store salary of Father. Write
a friend function, which accepts objects of class Mother, and Father and prints Sum of
Salary of Mother and Father objects.

CODING:-
#include<iostream>
#include<conio.h>
using namespace std;
class father;

class mother
{
long int msal;
public:
mother()
{
cout<<"\nEnter Mother's Salary : ";
cin>>msal;
}
friend void add(mother, father);
};
class father
{
long int fsal;
public:
father()
{
cout<<"\nEnter Father's Salary : ";
cin>>fsal;
}
friend void add(mother m, father f);
};
void add(mother m,father f)
{
cout<<"\n\nSum of salaries of Mother & Father = "<<m.msal+f.fsal;
}

int main()
{
mother m;
father f;

add(m,f);

return 0;
}
OUTPUT:-
Practical: 14
AIM: Write a program to create class Mother having data member to store salary of
Mother, create another class Father having data member to store salary of Father.
Declare class Father to be friend class of Mother. Write a member function in Father,
which accepts object of class Mother and prints Sum of Salary of Mother and Father
Objects. Create member function in each class to get input in data member and to display
the value of data member.

CODING:-

#include<iostream>
#include<conio.h>
using namespace std;
class father;

class mother
{
long int msal;
public:
void get()
{
cout<<"\nEnter Mother's Salary : ";
cin>>msal;
}
friend class father;
};
class father
{
long int fsal;
public:
void get()
{
cout<<"\nEnter Father's Salary : ";
cin>>fsal;
}
void add(mother m)
{
cout<<"\n\nSum of salaries of Mother & Father = "<<m.msal+fsal;
}
};
int main()
{
mother m;
father f;
m.get();
f.get();
f.add(m);
return 0;
}
OUTPUT:-
Practical: 15
AIM: Define structure student. Structure student has data members for storing name,
rollno, name of three subjects and marks. Write member function to store and print data.

CODING:-

#include<iostream>
#include<stdio.h>
using namespace std;
struct student
{
private:
char name[40],sub1[20],sub2[20],sub3[30];
int rollno,sub1mark,sub2mark,sub3mark;
public:
void get();
void show();
};
int main()
{
struct student s;
s.get();
s.show();
return 0;
}
void student::get()
{
cout<<"\nEnter Student Deatails :-\n\n";
cout<<"\nEnter Name of student : ";
gets(name);

cout<<"\nEnter Rollno of student : ";


cin>>rollno;

cout<<"\nEnter Name of subject 1 : ";


cin>>sub1;
cout<<"\nEnter Mark of subject 1 : ";
cin>>sub1mark;

cout<<"\nEnter Name of subject 2 : ";


cin>>sub2;
cout<<"\nEnter Mark of subject 2 : ";
cin>>sub2mark;
cout<<"\nEnter Name of subject 3 : ";
cin>>sub3;
cout<<"\nEnter Mark of subject 3 : ";
cin>>sub3mark;
}
void student :: show()
{
cout<<"\nStudent Details :-\n\n";
cout<<"\nstudent's Name : "<<name<<endl;

cout<<"\nStudent's Rollno :"<<rollno<<endl;


cout<<"\nFirst Subject : "<<sub1<<endl;
cout<<"Mark in First Subject : "<<sub1mark<<endl;

cout<<"\nSecond Subject : "<<sub2<<endl;


cout<<"Mark in second Subject : "<<sub2mark<<endl;

cout<<"\nThird Subject : "<<sub3<<endl;


cout<<"Mark in Third Subject : "<<sub3mark<<endl;
}
OUTPUT:-

Practical: 16
AIM: Write program to create a class Polar which has data member radius and angle,
define overloaded constructor to initialize object and copy constructor to initialize one
object by another existing object keep name of parameter of parameterized constructor
same as data members. Test function of the program in main function.

CODING:-

#include<iostream>
using namespace std;
class polarss
{
int radius, angle;
public:
polar()
{
radius=10;
angle=20;
}
polar(int radius, int angle)
{
this->radius=radius;
this->angle=angle;
}
polar(polar &p)
{
radius=p.radius;
angle=p.angle;
}
void show()
{
cout<<"Radius = "<<radius<<"\t"
<<"angle = "<<angle;
}
};
int main()
{
polar p1;
polar p2(20,30);
polar p3(p2);

cout<<"\n\nDefault Values :-\n";


p1.show();

cout<<"\n\nOverloaded Values :-\n";


p2.show();

cout<<"\n\nCopied Values :-\n";


p3.show();
return 0;
}
OUTPUT:-

Practical: 17
AIM: Write program to create a class Polar which has data member radius and angle,
define overloaded constructor to initialize object and copy constructor to initialize one
object by another existing object keep name of parameter of parameterized constructor
same as data members. Test function of the program in main function.

CODING:-

#include<iostream>
using namespace std;
class polar
{
int radius, angle;
public:
polar(int radius=40, int angle=50)
{
this->radius=radius;
this->angle=angle;
}
void show()
{
cout<<"Radius = "<<radius<<"\t"
<<"angle = "<<angle;
}
};
int main()
{
polar p1;
polar p2(50,40);
cout<<"\n\nDefault Values :-\n";
p1.show();

cout<<"\n\nOverloaded Values :-\n";


p2.show();

return 0;
}
OUTPUT:-

Practical: 18
AIM: write a program using class, which uses static overloaded function to swap two
integers; two floats methods use parameter passing by address.

CODING:-

#include<iostream>
using namespace std;
class sample
{
public:
static void swap(int *x,int *y)
{
int t;
t = *x;
*x = *y;
*y = t;
}
static void swap(float *x,float *y)
{
float t;
t = *x;
*x = *y;
*y = t;
}
};
int main()
{
static int a,b;
static float f1,f2;

cout<<"\nEnter Integer 1 : ";


cin>>a;
cout<<"\nEnter Integer 2 : ";
cin>>b;

cout<<"\n\nValues Before Swapping :-\n ";


cout<<"a = "<<a
<<"\nb= "<<b;

sample::swap(&a,&b);
cout<<"\n\nValues After Swapping :-\n ";
cout<<"a = "<<a
<<"\nb= "<<b ;

cout<<"\n----------------------------------------------";

cout<<"\n\nEnter Float 1: ";


cin>>f1;
cout<<"Enter Float 2 : ";
cin>>f2;
cout<<"\n\nValues Before Swapping :-\n";
cout<<"f1 = "<<f1
<<"\nf2 = "<<f2 ;

sample::swap(&f1,&f2);
cout<<"\n\nValues After Swapping :- \n";
cout<<"f1 ="<<f1
<<"\nf2 = "<<f2 ;
return 0;
}

OUTPUT:-

Practical: 19
AIM: Create class String having pointer to character as data member and provide
following Facilities:

a) Constructor for initialization and memory allocation.


b) Destructor for memory release.
c) Overloaded operators + to add two string object.
d) Overloaded operator = to assign one string object to other string object.
e) Overloaded operator == to compare whether the two string objects are equal or not.
f) Overloaded operator < to compare whether first-string object is less than second-
string object
g) Overloaded operator > to compare whether first-string object is greater than second-
string object or not.
h) Overloaded operator <= to compare whether first-string object is less than or equal to
second-string object or not.
i) Overloaded operator >= to compare whether first-string object is greater than or equal
to second-string object or not.
j) Overloaded operator ≠ to compare whether first-string object is not equal to second-
string object or not.
k) Overloaded insertion and extraction operators for input in data member and display
output of data members.

CODING:-

#include <iostream>
#include <cstring>
class String {
private:
char* str;
public:
String(const char* s = nullptr) {
if (s != nullptr) {
str = new char[strlen(s) + 1];
strcpy(str, s);
} else {
str = new char[1];
str[0] = '\0';
}
}

~String() {
delete[] str;
}
String operator+(const String& other) const {
String result;
result.str = new char[strlen(str) + strlen(other.str) + 1];
strcpy(result.str, str);
strcat(result.str, other.str);
return result;
}
String& operator=(const String& other) {
if (this != &other) {
delete[] str;
str = new char[strlen(other.str) + 1];
strcpy(str, other.str);
}
return *this;
}
bool operator==(const String& other) const {
return (strcmp(str, other.str) == 0);
}
bool operator<(const String& other) const {
return (strcmp(str, other.str) < 0);
}
bool operator>(const String& other) const {
return (strcmp(str, other.str) > 0);
}
bool operator<=(const String& other) const {
return (strcmp(str, other.str) <= 0);
}
bool operator>=(const String& other) const {
return (strcmp(str, other.str) >= 0);
}
bool operator!=(const String& other) const {
return (strcmp(str, other.str) != 0);
}
friend std::istream& operator>>(std::istream& in, String& s) {
char buffer[1000];
in >> buffer;
s = buffer;
return in;
}
friend std::ostream& operator<<(std::ostream& out, const String& s) {
out << s.str;
return out;
}
};
int main() {
String s1("Hello ");
String s2("RAJIV");
String s3 = s1 + s2;
std::cout << "Concatenation: " << s3 << std::endl;
String s4;
std::cout << "Enter a string: ";
std::cin >> s4;
std::cout << "Comparison: " << (s1 == s2 ? "Equal" : "Not Equal") << std::endl;
std::cout << "Comparison: " << (s1 < s2 ? "Less Than" : "Not Less Than") << std::endl;

return 0;
}

OUTPUT:-

Practical: 20
AIM: Create a class Matrix having data member double dimension array of floats of size
3x3. provide following facilities:
a) Overloaded extraction operator for data input.
b) Overloaded insertion operator for data output.
c) Overloaded operator + for adding two using matrix objects.
d) Overloaded operator – for subtracting two using matrix objects.
e) Overloaded operator * for multiplying two using matrix objects.

CODING:-

#include <iostream>
using namespace std;
class Matrix {
private:
double data[3][3];

public:
// Overloaded extraction operator for data input
friend std::istream& operator>>(std::istream& in, Matrix& mat) {
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
in >> mat.data[i][j];
return in;
}

// Overloaded insertion operator for data output


friend std::ostream& operator<<(std::ostream& out, const Matrix& mat) {
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j)
out << mat.data[i][j] << " ";
out << std::endl;
}
return out;
}

// Overloaded operator + for addition


Matrix operator+(const Matrix& other) const {
Matrix result;
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
result.data[i][j] = data[i][j] + other.data[i][j];
return result;
}
// Overloaded operator - for subtraction
Matrix operator-(const Matrix& other) const {
Matrix result;
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
result.data[i][j] = data[i][j] - other.data[i][j];
return result;
}

// Overloaded operator * for multiplication


Matrix operator*(const Matrix& other) const {
Matrix result;
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
for (int k = 0; k < 3; ++k)
result.data[i][j] += data[i][k] * other.data[k][j];
return result;
}
};

int main() {
Matrix mat1, mat2;

std::cout << "Enter Matrix 1 (3x3):\n";


std::cin >> mat1;

std::cout << "Enter Matrix 2 (3x3):\n";


std::cin >> mat2;

Matrix sum = mat1 + mat2;


Matrix diff = mat1 - mat2;
Matrix product = mat1 * mat2;

std::cout << "\nPrinting Matrix 1 :\n" << mat1;


std::cout << "\nPrinting Matrix 2 :\n" << mat2;

std::cout << "\nAddition of Matrix :\n" << sum;


std::cout << "\nSubtraction of Matrix :\n" << diff;
std::cout << "\nMultiplication of Matrix :\n" << product;

return 0;
}

OUTPUT:-
Practical: 21
AIM: Create a class Polar having radius and angle as data members. provide following
facilities:

a) Overloaded insertion and extraction operators for data input and display.
b) Over loaded constructor for initialization of data members.
c) Overloaded operator + to add two polar co-ordinates using objects of class Polar.

CODING:-

#include<iostream>
using namespace std;
class polar
{
int radius, angle;
public:
void get()
{
cout<<"Enter radius: ";
cin>>radius;
cout<<"enter Angle: ";
cin>>angle;
}
void show()
{
cout<<"radius = "<<radius<<"\n"
<<"angle = "<<angle;
}
friend polar add(polar, polar);
};
polar add(polar p1,polar p2)
{
polar p3;
p3.radius=p1.radius+p2.radius;
p3.angle=p1.angle+p2.angle;
return p3;
}
int main()
{
polar p1,p2,p3;
cout<<"\nEnter First polar :-\n";
p1.get();
cout<<"\nEnter second polar :-\n";
p2.get();
cout<<"\n value of first polarP: -\n";
p1.show();
cout<<"\n value of first polarP: -\n";
p2.show();
p3=add(p1,p2);
cout<<"\nAfter addtion value is:-\n";
p3.show();
return 0;
}
OUTPUT:
Practical: 22
AIM: Create a class polar that contains data member radius and angels. Create another
class Cartesian in the same program and provide following facilities:
a) It should be possible to assign object of polar class to object of cartesian class.
b) It should be possible to assign object of Cartesian class to object of polar class.
CODING:-

#include<iostream>
#include<conio.h>
using namespace std;
class circle
{
public:
float radius;
circle()
{
cout<<"\n Enter Radius of Circle: ";
cin>>radius;
}
void Acircle()
{
cout<<"\n\nArea of Circle = "<< 3.14 * radius * radius;
}
};
class sphere: public circle
{
public:
void Svol()
{
cout<<"\n\nVolume of Sphere = "<< 1.33 * 3.14 * radius * radius * radius;
}
};

class cylinder: public sphere


{
int height;

public:

cylinder()
{
cout<<"\nEnter Height of Cylinder:";
cin>>height;
}
void Cvol()
{
cout<<"\n\nVolume of Cylinder = "<< 3.14 * radius * radius * height;
}
};
int main()
{

cylinder c;

c.Acircle();
c.Svol();
c. Cvol();
return 0;
}

OUTPUT:-
Practical: 23
AIM: Write a program to find biggest number among three number using pointer and
function.

CODING:-

#include<iostream>
using namespace std;
void max(int *,int *,int *);
int main()
{
int a,b,c;

cout<<"\nEnter First Value : ";


cin>>a;
cout<<"\nEnter Second Value : ";
cin>>b;
cout<<"\nEnter Third Value : ";
cin>>c;
max(&a,&b,&c);
return 0;
}
void max(int *p,int *q,int *r)
{
int max=*p;
if(*q>max)
max=*q;
if(*r>max)
max=*r;
cout<<"\n\nThe Biggest Number is : "<<max;
}

OUTPUT:-
Practical: 24
AIM: Write swapping program demonstrate call by value, call by address, call by
reference in a simgle program.

CODING:-

#include<iostream>
using namespace std;

void swapvalue(int,int);
void swapref(int &,int &);
void swappad(int *,int *);
int main()
{
int a,b;
cout<<"\nEnter value of a : ";
cin>>a;
cout<<"\nEnter value of b : ";
cin>>b;
swapvalue(a,b);

swapref(a,b);
cout<<"\n\nCALL BY REFERENCE :-";
cout<<"\n\nValue of a after swap "<<a;
cout<<"\nValue of b after swap "<<b;

swappad(&a,&b);
cout<<"\n\nCALL BY ADDRESS :-";
cout<<"\n\nValue of a after swap "<<a;
cout<<"\nValue of b after swap "<<b;

return 0;
}
void swapvalue(int a,int b)
{
int t;
t=a;
a=b;
b=t;
cout<<"\n\nCALL BY VALUE :-";
cout<<"\n\nValue of a after swap "<<a;
cout<<"\nValue of b after swap "<<b;
}
void swapref(int &a,int &b)
{
int t;
t=a;
a=b;
b=t;
}
void swappad(int *a,int *b)
{
int t;
t=*a;
*a=*b;
*b=t;
}

OUTPUT:-
Practical: 25
AIM: Write a program using inline function to calculate area of circle.

CODING:-
#include<iostream>
#include<conio.h>
using namespace std;

class circle
{
float cir;

public:
void area(float r);

void show()
{
cout<<"\n\nArea of Circle is : "<<cir;
}
};
inline void circle :: area(float r)
{
cir=(3.14*r*r);
}
int main()
{
circle c;
float p;

cout<<"\nEnter the Radius : ";


cin>>p;

c.area(p);
c.show();

return 0;
}
OUTPUT:-
Practical: 26
AIM: Write a program using inline function to find minimum of two functions. The inline
function should take two arguments and should return the minimum value.

CODING:-

#include<iostream>
#include<conio.h>
using namespace std;
class small{
int a;
public:
void min(int x,int y);
void show()
{
cout<<"\n\nsmallest Number Is : "<<a;
}
};
inline void small::min(int x,int y)
{
a=x<y?x:y;
}
int main()
{
small s;
int p,q;
cout<<"\nEnter Integer 1 : ";
cin>>p;

cout<<"\nEnter Integer 2 :";


cin>>q;
s.min(p,q);
s.show();
return 0;
}
OUTPUT:-
Practical: 27
AIM: create a class circle with data member radius; provide member function to calculate
area. Derive a class sphere from class circle; provide member function to calculate
volume. Derive class cylinder from class sphere with additional data member for height
and member function to calculate volume.
CODING:-

#include<iostream>
#include<conio.h>
using namespace std;
class circle
{
public:
float radius;
circle()
{
cout<<"\n Enter Radius of Circle: ";
cin>>radius;
}
void Acircle()
{
cout<<"\n\nArea of Circle = "<< 3.14 * radius * radius;
}
};
class sphere: public circle
{
public:
void Svol()
{
cout<<"\n\nVolume of Sphere = "<< 1.33 * 3.14 * radius * radius * radius;
}
};

class cylinder: public sphere


{
int height;

public:

cylinder()
{
cout<<"\nEnter Height of Cylinder:";
cin>>height;
}
void Cvol()
{
cout<<"\n\nVolume of Cylinder = "<< 3.14 * radius * radius * height;
}
};
int main()
{

cylinder c;

c.Acircle();
c.Svol();
c. Cvol();
return 0;
}

OUTPUT:-
Practical: 28
AIM: Create a base class shape having two data members with two-member function get
data (pure virtual function) and print area (not pure virtual function). Derive classes
triangle and rectangle from class shape and redefine member function print area in both
classes triangle and rectangle and test the functioning of classes using pointer to base
class objects and normal objects.

CODING:-

#include <iostream>
using namespace std;
class Shape {
protected:
double base;
double height;
public:
virtual void getData() = 0;
void printArea() {
cout << "Area: " << calculateArea() << endl;
}
virtual double calculateArea() const {
return 0.0;
}
};
class Triangle : public Shape {
public:

void getData() override {


cout << "Enter base and height of the triangle: ";
cin >> base >> height;
}
double calculateArea() const override {
return 0.5 * base * height;
}
};
class Rectangle : public Shape {
public:
void getData() override {
cout << "Enter length and width of the rectangle: ";
cin >> base >> height;
}
double calculateArea() const override {
return base * height;
}
};

int main()
{
Shape* shapePtr;
Triangle triangle;
Rectangle rectangle;

shapePtr = &triangle;
shapePtr->getData();
shapePtr->printArea();

shapePtr = &rectangle;
shapePtr->getData();
shapePtr->printArea();

Triangle anotherTriangle;
Rectangle anotherRectangle;

anotherTriangle.getData();
anotherTriangle.printArea();

anotherRectangle.getData();
anotherRectangle.printArea();

return 0;
}

OUTPUT:-

Practical: 29
AIM: Write a class having name Calculate that uses static overload function to calculate
area of circle, area of rectangle and area of triangle.
CODING:-

#include <iostream>
#include <cmath>
class ArraySort {
public:

static double calculateArea(double radius) {


return 3.14159 * radius * radius;
}
static double calculateArea(double length, double width) {
return length * width;
}
static double calculateArea(double base, double height, double side1, double side2) {
double s = (base + side1 + side2) / 2.0;
return sqrt(s * (s - base) * (s - side1) * (s - side2));
}
};

int main() {

double circleRadius = 5.0;


double rectangleLength = 4.0;
double rectangleWidth = 6.0;
double triangleBase = 3.0;
double triangleHeight = 4.0;
double triangleSide1 = 5.0;
double triangleSide2 = 7.0;

std::cout << "Area of Circle: " << ArraySort::calculateArea(circleRadius) << std::endl;

std::cout << "Area of Rectangle: " << ArraySort::calculateArea(rectangleLength, rectangleWidth) <<


std::endl;

std::cout << "Area of Triangle: " << ArraySort::calculateArea(triangleBase, triangleHeight, triangleSide1,


triangleSide2) << std::endl;

return 0;

OUTPUT:-
Practical: 30
AIM: Write a class Array Sort that uses static overload function to sort an array of floats,
an array of integers.
CODING:-

#include <iostream>
#include <algorithm>
class ArraySort {
public:
static void sortArray(float arr[], int size) {
std::sort(arr, arr + size);
}
static void sortArray(int arr[], int size) {
std::sort(arr, arr + size);
}
};

int main() {
const int sizeFloat = 5;
float floatArray[sizeFloat] = {4.5, 2.0, 8.1, 1.7, 5.3};

const int sizeInt = 6;


int intArray[sizeInt] = {10, 3, 7, 1, 9, 4};

ArraySort::sortArray(floatArray, sizeFloat);
ArraySort::sortArray(intArray, sizeInt);

std::cout << "Sorted Float Array: ";


for (int i = 0; i < sizeFloat; ++i) {
std::cout << floatArray[i] << " ";
}
std::cout << std::endl;

std::cout << "Sorted Integer Array: ";


for (int i = 0; i < sizeInt; ++i) {
std::cout << intArray[i] << " ";
}
std::cout << std::endl;

return 0;
}

OUTPUT:-

You might also like