Question
LessThancpp.h template class LessThan{ public: bool operator()(T a, T b){ return a }; main.cpp #include #include #include #include Songcpp.h #include VectorADTcpp.h int populatedataBase(VectorADT &mySongs){ std::ifstream
LessThancpp.htemplate class LessThan{ public: bool operator()(T a, T b){ return a };main.cpp#include #include #include #include "Songcpp.h" #include "VectorADTcpp.h"
int populatedataBase(VectorADT &mySongs){ std::ifstream input("SongsData.txt"); std::string line; std::string title; std::string singer; std::string cp;//chart position in string int chartPosition=0; int dataCount=0; if (!input){ throw new std::string("File Open Error "); exit(-1);} while (std::getline(input,line)){ // std::getline(input,line); std::string token; std::istringstream instream(line); std::getline(instream,title, ','); std::getline(instream, singer, ','); std::getline(instream, cp,' '); // std::cout
VectorADT database;
int dataCount=populatedataBase(database); //database.printVectorADT(); LessThan f; int steps =database.sort(f); std::cout=0) std::coutmakefile;all: g++ main.cpp Songcpp.h VectorADTcpp.h -o SongVector song.h#include class Song{ private: std::string title; std::string singer; int chartPosition; public: Song(); Song(std::string title,std:: string singer, int chartPosition); std::string toString(); std::string getTitle(); void setChartPosition(int pos); friend std::ostream & operatorsongcpp.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& operatortoString(); return str;} //GIVEN int Song::getChartPosition(){ return chartPosition; } //GIVEN void Song::setChartPosition(int pos){ chartPosition=pos; } //GIVEN bool Song::operatorvectorADT.h #include
#include "LessThancpp.h"
#include
template
//template class VectorADT{
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 f);
int searchByTitle(int& steps, T *v);}; VectorADTcpp.h #include #include "VectorADT.h"//GIVEN template VectorADT::VectorADT (){ dataArray= new T*[SIZE]; count=0;} //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 void VectorADT::resizeADT(){ // TODO } //TODO //appends an element to the end of the VectorADT //increments size by 1//if run out of size, resize the vector// REM documentation template void VectorADT::push_back(T *v){ //TODO } //TODO//returns a copy of the element from the end of the VectorAD//does not delete/o resize of the vector// REM documentation template T * VectorADT::pop(){ //TODO } //TODO//removes an element from the end of the VectorADT//decrements size by 1/o resize of the vector// REM documentation template T * VectorADT::pop_back() { ; //TODO} template void VectorADT::printVectorADT(){ for (int i=0;i std::cout=0 && i return dataArray[i]; else { throw new std::string("No such element exception"); exit(-1); } } //GIVEN template void VectorADT::set(int i, T * t){ if (i>=0 && i dataArray[i]=t; else { throw new std::string("No such element exception"); exit(-1) } } //TODO //USE template //inserts the object at the given INDEX position NOT chart position //DOes NOT adjust chart position //THROWS exception if index out of bounds //right adjusts the elements to the right of the inserted object//returns number of adjusted steps template int VectorADT::insert(T * v, int pos){ int adjustSteps=0; // TODO return adjustSteps; } //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 int VectorADT::remove(int pos){ int adjustSteps=0; //TODO return adjustSteps;
} //TODO Linear search //use the overloaded == operator of the Song objects //returns -1 if not found else returns the found index template int VectorADT::searchByTitle(int& steps, T *v){ // TODO return -1; }
(Some songs have been removed due word limit on chegg) SongaData
december,ariana grande,100 lotto,exo,72 butterflies,fiji blue,55 he could be the one,hannah montana,54 eight,iu,52 celebrity,iu,50 poker face,lady gaga,51 hot n cold,katy perry,62 angel,nct 127,67 lemonande,nct 127,66 another world,nct 127,65 chain,nct 127,69 dreaming,nct 127,68 heartbreaker,nct 127,63 mad city,nct 127,64 once again,nct 127,49 paradise,nct 127,48 punch,nct 127,47 running 2 u,nct 127,46 simon says,nct 127,45 summer127,nct 127,44 switch,nct 127,43 wakey wakey,nct 127,42 magic shop,bts,23 mikrokosmos,bts,35 make it right,bts,30
SongsDataDoubledecember,ariana grande,100 ice cream,blackpink,92 blood sweat & tears,bts,91 boy in luv,bts,90 dope,bts,79 dimple,bts,77 mic drop,bts,78 second grade,bts,80 war of hormone,bts,76 hold on,chord overstreet,75 we belong,dove cameron,74 boys will be boys,dua lipa,73 man up,hailee steinfeld,70 ko ko bop,exo,71 lotto,exo,72 butterflies,fiji blue,55 he could be the one,hannah montana,54 eight,iu,52 celebrity,iu,50 poker face,lady gaga,51 love me like you,little mix,53 running 2 u,nct 127,46 simon says,nct 127,45 summer127,nct 127,44 switch,nct 127,43 wakey wakey,nct 127,42 welcome to my playground,nct 127,41 beautiful time,nct dream,81 go go,bts,21 im fine,bts,22 magic shop,bts,23 mikrokosmos,bts,35 make it right,bts,30
Please let me know if you need anything else.
Add an overloaded == operator to compare string titles and return true if they are the same. This is needed for linear search # The driver VectorADTMain.cpp is GIVEN to you and does the following 1. Create a database of Songs called SongsData 2. Populates this database from the file SongsData.txt using push back method 3. Sorts this database using the sort method that uses Selection Sort #Please Note the number of steps taken for this command. 4. Uses a function object from the Less Than class and pass to the ADT. 5. Records the number of steps taken for this sort 6. Push.back and pon.back a new Song. Records the changing size of database 7. Inserts a song at index position 5. Observe successful insertion. # Please Note the number of steps taken for this command. 8. Remove the song from index position 4. Observes successful removal. #Please Note the number of steps taken for this command. 9. Search for removed song by title Record the number of steps taken for this linear search. See if this song is found #Note the number of steps taken for this comman (worth 5 points) Reflection: Write a brief reflection after running the program with both data files and noting from above the number of steps) the complexity class (Big O notation) of the selection sort, linear search, push back.Don.backo, insert and remove functionsStep 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