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

Your task is to write a class called Data, stored in a file named Data.h. Your c

ID: 3684090 • Letter: Y

Question

Your task is to write a class called Data, stored in a file named Data.h. Your class should be able to store a collection (vector) of integers. In addition to the appropriate constructors, your class should also have the following methods. void add (int number); Adds a number to the data set. void print (); Prints out the entire data set on a single line, separated by space. void sort (); Sorts the data set in ascending order. You may implement any sorting algorithm here, for example, max sort, bubble sort, insertion sort, merge sort, quick sort, etc... There is no need to try to implement the most efficient one, any one will do.

IN C++

Explanation / Answer

#include <iostream>

using namespace std;
class Data
{
int number[10]={2,4,3,4,5,10,6,7,8,9};
public:
void add(int n)
{
for(int i=0;i<10;i++)
number[i]=number[i]+n;
}
void print()
{
for(int i=0;i<10;i++)
cout<<number[i]<<" ";
}
void sort()
{ int temp;
for(int i=1;i<10;++i)
{
for(int j=0;j<9;++j)
if(number[j]>number[j+1])
{
temp=number[j];
number[j]=number[j+1];
number[j+1]=temp;
}
}
  
  
}
};
int main()
{
Data d1;
d1.add(12);
d1.sort();
d1.print();
return 0;
}