Write a c++ program using class to sort an integer array and float array element in ascending order using bubble sort method use function overload.
#include<iostream.h>
#include<conio.h>
class sorting
{
public:
double a1[10];
int n,i;
public:
void sort(int*);
void sort(float*);
};
void sorting::sort(float *a)
{
float sw;
for(i=0;i<n-1;i++)
{
cout<<"\n\n\nRound: "<<i+1;
for(int j=0;j<(n-1)-i;j++)
{
cout<<"\n\n Comparing "<<j+1<<" and "<<j+2<<"\n\n";
if(a1[j]>a1[j+1])
{
sw=a[j];
a[j]=a[j+1];
a[j+1]=sw;
}
for(int k=0;k<n;k++)
{
cout<<a[k]<<"\t";
}
}
}
cout<<"\nSorted array element: ";
for(i=0;i<n;i++)
{
cout<<"\n\n "<<a[i]<<"\t";
}
}
void main()
{
int n,i;
float a[10];
sorting s1;
clrscr();
cout<<"\nFor integer array: \n";
for(i=0;i<4;i++)
{
cin>>a[i];
}
s1.sort(a);
cout<<"\nHow many element: \n";
cin>>n;
for( i=0;i<4;i++)
{
cin>>a[i];
}
s1.sort(a);
cout<<"\nFor floated array: \n";
cout<<"\nHow many element: \n";
cin>>n;
for( i=0;i<n;i++)
{
cin>>a[i];
}
s1.sort(a);
cout<<"\nInteger array element: \n";
cout<<"\nFloated array element: \n";
getch();
}