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::MyList(T array[], size_t_size){

size=size;//initializing size

//copying all elements from array to list

for (int i=0);i

list[i]=array[i];

}

}

template

T MyList::get(int index)const{

//retruning element at given index

return list [index];

}

template

void MyList::set(int index T, data){

//updating element at given index

list [index] = data;

}

template

size_t MyList::getSize()const{

//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&list){

// 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 shortList ( shortArr, arraySize );

MyList doubleList ( doubleArr, arraySize );

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();

}

MYLIST CODE: #ifndef MyList_h #define MyList_h #define MAX_SIZE 100// default size of

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 shortList "shortList.in"); MyListF doubleList "doubleList.in" MyListF <:string> strList ("stringList.in") std: :cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!