Write a C++ program to sort integer and float array elements in ascending order by using function overloading.
#include<iostream.h>
#include<conio.h>
class bubble
{
public:
void array(int ans);
void array(float ans);
};
void bubble::array(int ans)
{
cout<<"\n"<<ans;
}
void bubble::array(float ans)
{
cout<<"\n"<<ans;
}
int main()
{
bubble bb;
int i,j,n,a[20],temp=0;
float b[20];
clrscr();
cout<<"\n\nEnter how many integer numbers you want to enter:";
cin>>n;
cout<<"\nEnter the elemenets for integer array:";
for(i=0;i<n;i++)
cin>>a[i];
n=n-1;
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
n++;
cout<<"\nInteger array after sorting:";
for(i=0;i<n;i++)
bb.array(a[i]);
cout<<"\nEnter how many float numbers you want to enter:";
cin>>n;
cout<<"\nEnter array elements for float array:";
for(i=0;i<n;i++)
cin>>b[i];
n=n-1;
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(b[j]>b[j+1])
{
float tem;
tem=b[j];
b[j]=b[j+1];
b[j+1]=tem;
}
}
}
n++;
cout<<"\nFloat array after sorting:";
for(i=0;i<n;i++)
bb.array(b[i]);
getch();
return 0;
}
#include<iostream.h>
#include<conio.h>
class bubble
{
public:
void array(int ans);
void array(float ans);
};
void bubble::array(int ans)
{
cout<<"\n"<<ans;
}
void bubble::array(float ans)
{
cout<<"\n"<<ans;
}
int main()
{
bubble bb;
int i,j,n,a[20],temp=0;
float b[20];
clrscr();
cout<<"\n\nEnter how many integer numbers you want to enter:";
cin>>n;
cout<<"\nEnter the elemenets for integer array:";
for(i=0;i<n;i++)
cin>>a[i];
n=n-1;
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
n++;
cout<<"\nInteger array after sorting:";
for(i=0;i<n;i++)
bb.array(a[i]);
cout<<"\nEnter how many float numbers you want to enter:";
cin>>n;
cout<<"\nEnter array elements for float array:";
for(i=0;i<n;i++)
cin>>b[i];
n=n-1;
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(b[j]>b[j+1])
{
float tem;
tem=b[j];
b[j]=b[j+1];
b[j+1]=tem;
}
}
}
n++;
cout<<"\nFloat array after sorting:";
for(i=0;i<n;i++)
bb.array(b[i]);
getch();
return 0;
}