24. 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();
}

2 thoughts on “24. 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.

  1. vineet dhayal says:

    as i have given this code i am not getting output what is the problem???

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s