1)what i trying to do is to use polymorphism method on changing the sorting function.
a) how to change bubble sort to insertion sort..??what is insertion sort..never heard of it..
b)how to change sequential search to binary search...including the polymorphism method
#include<iostream.h>
class Array
{
protected:
int box[10];
int i;
int total;
int largest;
int hold;
int key;
public:
void calculation()
{
total=0;
largest=0;
for(i=0;i<10;i++)
{
cout<<"Enter number :";
cin>>box[i];
}
for(i=0;i<10;i++)
{
cout<<"\n"<<box[i];
}
for(i=0;i<10;i++)
{
total=total+box[i];
if(largest<box[i])
largest=box[i];
}
cout<<"\nThe total of numbers: "<<total;
cout<<"\nThe largest number: "<< largest;
}
virtual sort()
{
for( int pass=0;pass<10-1;pass++)
for(i=0;i<10-1;i++)
if(box[i]>box[i+1])
{
hold=box[i];
box[i]=box[i+1];
box[i+1]=hold;
}
cout<<"\nThe ascending number:\n";
for(i=0;i<10;i++)
cout<<box[i];
cout<<endl;
}
virtual search()
{
cout<<"Enter integer search key:"<<endl;
cin>>key;
for(i=0;i<10;i++)
if(box[i]==key)
if(i<10)
cout<<"Integer: "<<key<<" found at array element "<<i<<"\n";
}
};
main()
{
Array t;
t.calculation();
t.sort();
t.search();
return 0;
}