Write a C++ program to sort integer and float array elements in ascending order by using function overloading
//Note: If you are not using Borland or Turbo C then add the following line after header files :
//using namespace std;
#include<iostream.h>
#include<conio.h>
class arr
{
public:
int n,i,j; // n=no of elements
float a[10],temp; // a=array for no of elements
void accept()
{
cout<<"\nEnter how many elements: ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"\nEnter elements: ";
cin>>a[i];
}
cout<<"\n============Array is==============\n\n";
for(i=0;i<n;i++)
{
cout<<a[i]<<"\t";
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<"\n===========Sorting Array is===========\n\n";
for(i=0;i<n;i++)
{
cout<<a[i]<<"\t";
}
}
};
int main()
{
arr r; //object created
r.accept();
getch();
return(0);
}
-
Next Create a class MyString which contains a character pointer (Use new and delete operator). Write a C++ program to overload following operators: ! To change the case of each alphabet from given string [ ] To print a character present at specified index
-
Previous Write a C++ program to create two classes Class1 and Class2. Each class contains one float data member. Write following functions: i. To accept float numbers ii. To display float numbers in right justified format with precision of two digits iii. To Exchange the private values of both these classes by using Friend function.
0 Comments