Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ pleaese helps file Sortable.h . It contains an abstract data type called Sor

ID: 3863002 • Letter: C

Question

C++ pleaese helps

file Sortable.h. It contains an abstract data type called Sortable which will act as a base class for any object a collection of which can be sorted. It has two virtual methods, compare and print. The compare method tells the object how to compare itself with another object. It returns true if the object it is being called from is smaller than the other object. The print method allows the object to display itself.

Modify your Data class so that it operates on Sortable objects instead of int objects. Recall from the textbook that we can not allocate abstract data types. Therefore, in order to accomplish the task in this exercise, you will need to use pointers.

Also, you are not provided with any .cpp files in order to test your code. Testing your code will involve creating a class that extends Sortable and pushing some objects of that class into your Data object and trying to sort and print them. This is the goal of the next exercise.

Explanation / Answer

#include<iostream.h>
#include<conio.h>
class sorting
{
public:
double a1[10];
int n,i,sort;
public:
void sort(int*);
void sort(float*);
};
void sorting::sort(int *a)
{
for(i=0;i<n-1;i++)
{
for(int j=0;j<(n-1)-i;j++)
{
cout<<“ “<<j+1<<” and “<<j+2<<“ ”;
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];
}
}
}
cout<<“ Sorted array element: “;
for(i=0;i<n;i++)
{
cout<<“ “<<a[i];
}
}
void main()
{
int n,i;
int sort[10];
sorting s1;
clrscr();
for(i=0;i<4;i++)
{
cin>>a[i];
}
s1.sort(a);
cout<<“ How many element: ”;
cin>>n;
for( i=0;i<4;i++)
{
cin>>a[i];
}
s1.sort(a);
cout<<“ array element: ”;
getch();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote