Question
Please solve the to do parts of the following problem. Thank you in advance. This assignment involves review of template classes, implementation of vector data
Please solve the to do parts of the following problem.
Thank you in advance.
This assignment involves review of template classes, implementation of vector data type and function objects. Students are expected to review the vector template class that is available in the C++ STL and complete the practice lab before embarking on the assignment.
#Create a Vector Template Class (Vector Abstract Data Type) that is implemented as a dynamic array with an initial size of 2.
Implement a default constructor - a copy constructor as well as a destructor for this Vector ADT will be done in Assignment 2.
Implement typical Vector functions like push_back,pop, pop_back, insert, remove, size, resize, search and sort and other functions as given below and in the template
#The main driver is given to you. Run the program first time with SongsData.txt and then with the larger file SongsDataDouble.txt.
#Use the template given to you for further guidance and support
//default constructor
VectorADT();
// return address of element at index position i
T* get(int i) const;
// print the entire database
void printVectorADT();
// print the number of items specified
void printVectorADT(int number);
// double the size of the database by
//creating another database twice the size and copying
//the existing database into it. The existing one is then deleted
void resizeADT();
// returns true if database is empty, false otherwise
bool empty();
//returns the number of items in the database
int size() const;
// add an item to the end of the database
void push_back(T *);
// remove and return the last element of the database if there is one
T* pop_back();
// "peeks" ie returns a pointer to the last element without removing or deleting it
T* pop();
// inserts at the proper position, no sorting necessary
// element is inserted at index =pos
//if pos is negative or unacceptable number throws exception and exits
void insert(T * v, int pos);
// deletes the item at index position =pos
//if database is empty or pos is negative or an unacceptable number throws exception and exits
void remove(int pos);
void topTen();
// prints top 10 items
// kept sorted according to position - use function objects - selection sort
int sort(LessThan
main.cpp
#include
int populatedataBase(VectorADT } return dataCount; } int main() { VectorADT int dataCount=populatedataBase(database); //database.printVectorADT(); LessThan Song *insertThis2= new Song("fifth place","BTS",5);//chartposition int insertSteps=database.insert(insertThis2, 5);//will go into 6th position std::cout<<"inserted song at index 6 "< LessThencpp.h template < class T> class LessThan{ public: bool operator()(T a, T b){ return a Song.h #include Songcpp.h #include "Song.h" Song::Song(){ title=""; singer=""; chartPosition=0; } //GIVEN Song::Song(std::string title, std::string singer, int chartPosition){ this->title=title; this->singer=singer; this->chartPosition=chartPosition; } //GIVEN std::string Song::toString(){ return "Title: "+title+ " Singer: "+singer+ " ChartPosition: "+std::to_string(chartPosition); } // //GIVEN std::ostream& operator<<(std::ostream & str, Song *s){ str<< s->toString(); return str; } //GIVEN int Song::getChartPosition(){ return chartPosition; } //GIVEN void Song::setChartPosition(int pos){ chartPosition=pos; } //GIVEN bool Song::operator<(Song b){ return chartPosition bool Song::operator==(Song b){ //TODO return""; // } //GIVEN std::string Song::getTitle(){ return title; } VectorADT.h #include #include "LessThancpp.h" #include template //template const size_t SIZE = 2; private: T ** dataArray = nullptr; int count; public: //default constructor VectorADT(); // return address of element at index position i T* get(int i) const; // set the element e at position i void set(int i, T *); // print the entire database void printVectorADT(); // print the number of items specified void printVectorADT(int number); // double the size of the database by //creating another database twice the size and copying //the existing database into it. The existing one is then deleted void resizeADT(); // returns true if database is empty, false otherwise bool empty(); //returns the number of items in the database int size() const; // add an item to the end of the database void push_back(T *); // remove and return the last element of the database if there is one T* pop_back(); // "peeks" ie returns a pointer to the last element without removing or deleting it T* pop(); // inserts at the proper position, no sorting necessary // element is inserted at index =pos //if pos is negative or unacceptable number throws exception and exits //returns the number of adjustments done to shift data to right int insert(T * v, int pos); // deletes the item at index position =pos //if database is empty or pos is negative or an unacceptable number throws exception and exits //returns the number of adjustments done to shift data left int remove(int pos); void topTen(); // prints top 10 items // kept sorted according to position - use function objects - selection sort int sort(LessThan int searchByTitle(int& steps, T *v); }; VectorADTcpp.h #include //GIVEN template //TODO //double the size of the dataArray //create a temporary dataArray of double the size //copy over the current data Array and then delete it //use REM documentation template //GIVEN template //GIVEN template //TODO //TODO //USE template //removes the object at the given INDEX position NOT chart position //DOes NOT adjust chart position //THROWS exception if index out of bounds //left adjusts the elements to the right of the inserted object //returns number of adjusted steps template //TODO Linear search //use the overloaded == operator of the Song objects //returns -1 if not found else returns the found index template
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started