Question: MYLIST CODE: #ifndef MyList_h #define MyList_h #define MAX_SIZE 100// default size of array #include using namespace std; //MyList class template class MyList{ //declaring array of
MYLIST CODE:
#ifndef MyList_h
#define MyList_h
#define MAX_SIZE 100// default size of array
#include
using namespace std;
//MyList class
template
class MyList{
//declaring array of T
T list[MAX_SIZE];
size_t size;//size of array
public:
//constructor to initialize values
MyList(T array[], size_t size);
//getter to return element at given index
T get (int index)const;
// setter, to mutate element at given index
void set(int index, T value);
//returns the size
size_t getSize()const;
};
#endif
MyList.cpp file
#include "MyList.h"
//inplementation of all methods
template
MyList
size=size;//initializing size
//copying all elements from array to list
for (int i=0);i
list[i]=array[i];
}
}
template
T MyList
//retruning element at given index
return list [index];
}
template
void MyList
//updating element at given index
list [index] = data;
}
template
size_t MyList
//retruning size
return size;
}
//main.cpp file
#include "MyList.h" //including MyList class
#include
using namespace std;
// updating bubble sort method
template
void Bubblesort (MyList
// sorting the list using Bubble sort algorithnm
for (int i =0;i
T value1=list.get(j);
T value2=list.get(j+1);
if (value1>value2){
// swapping values at j and j + 1
list.set(j+1,value1);
list.set(j,value2);
}
}
}
}
//overloaded
template
ostream & operator list){
//printing all elements in list
for (size_t i =0);i
out
}
out
}
void Test () {
//testing
size_t arraySize = 10;
short shortArr [ arraySize ] = { 2, 6, 4, 8, 10, 12, 89, 65, 44, 37 };
double doubleArr [ arraySize ] = { 2.0, 6.0, 4.0, 8.0, 10.0, 12.25, 89.99,
65.0, 45.0, 37.0 };
string::string strArr [ arraySize ] = { "two", "six", "four", "eight", "ten",
"twelve", "eighty nine", "sixty five", "forty four", "thirty seven" };
MyList
MyList
MyList <:string> strList ( strArr, arraySize );
std::cout
BubbleSortT ( shortList );
std::cout
std::cout
BubbleSortT ( doubleList );
std::cout
std::cout
BubbleSortT ( strList );
std::cout
}
int main (){
test();
}

CMPS 370 Fall 2018 Assignment 7 BONUS Assignment (a) Define MyListF as a subclass of MyList so that it can be initialized by data from an external file. (b) Prepare three text files, "shortList.in", "doubleList.in", "stringList.in", and input the same respective array values. For example, contents of "shortlist.in" are: 18 12 89 68 45 3 6 (c) Use the above in the following Test Q function: void Test MyListF
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
