Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can somebody solve the TODO parts of the following problem. Thanks Description This assignment builds on top of the ListNode class designed and tested in

Can somebody solve the TODO parts of the following problem.

Thanks

Description

This assignment builds on top of the ListNode class designed and tested in Assignment 4 where constructionand testing of the ListNode class has already been done. Recall that a ListNode object contains a data field and a pointer to the next ListNode object.

We now encapsulate the functions to create, search and update the database into a LinkedList class. There are two members in this class. A pointer called front that points to a ListNode object and an integer count of the total number of objects currently in the list.

As before, we are not going to use pre-fabricated classes from the c++ library, but construct the LinkedList ADT from scratch.

We can now use this class to create a LinkedList object which contains a collection of ListNodes each having a Song object in the data field. The api is put through its paces by initially testing it on a dummy database containing four songs. The main program then repeats the testing process with the song list in the file SongData.txt and then again with the song list in the file SongDataDouble.txt.

The number of steps taken to populate the database for both files is recorded.

Instruction

#This assignment requires you to

Read the Assignment 5 Notes

Watch the Assignment 5 Support video

Implement the following methods of the LinkedList class

-custom constructor

-setters for next pointer and data

Implement the insert, remove and get method in the LinkedListcpp.h file

Scan the given template to find the above //TODO and implement the code needed

//Requires: Song for inserting

//Effects: creates a new ListNode with input value and inserts in proper position (increasing order of chart position)in the chain. If LinkedList, adds to the beginning

//Modifies: front, if node is added at the beginning.

//Also changes the next pointer of the previous node to point to the newly inserted list node. the next pointer of the newly inserted pointer points to what was the next of the previous node. This way both previous and current links are adjusted

//TODO

template

int LinkedList::insert( T value, SortBy f){

int steps=0;

//TODO

return steps;

}

//Requires: Song title for searching

//Effects: traverses the LinkedList (database) starting from front until the end comparing titles Returns the original search value if found otherwise returns an empty song with blank title

//Modifies: Nothing

//TODO

template

T LinkedList::get(T value){

ListNode * current = front;//this may need to change

//TODO

return current->getData();

}

//TODO

template

int LinkedList::remove(T value){

//TODO

int steps=0;

return steps;

}

/ /Requires: index position of Song to be found

//Effects: traverses the LinkedList starting from front and travels to the index position (if valid) and returns the song at that index position. Note index position may NOT be the same as chart position

//Modifies: Nothing

//TODO

template

T LinkedList::get(int index){

ListNode * current = front;

//TODO

return current->getData();

}

Guidance

# The driver is given LinkedListMain.cpp is given to you that does the following tests

Calls a method testDummyData that creates a LinkedList type database to hold four songs. It tests the api by adding, removing, inserting and searching for songs. It also prints the database..

Creates an object called database of type LinkedList to hold object of Song type.

Constructs a SortBy function object and sets search by title to true in the constructor

Calls the populateDatabase method to read songs from the SongData file and insert into the database using title as search key

. It tests the api by adding, removing and inserting (from different positions) and searching for existing and missing songs. It also prints the database.

Todo List:

Use the templates given to you. You are not obliged to use my template. You may modify it as needed. for

Code marked GIVEN CODE is given to you for free

You are also given a makefile if needed

Comments marked //TODO indicated you need to fill in code.

These templates are a guide and you may tweak them if needed

Run and test the project for edge cases, average and load cases

Your output must exactly match the output.txt given to you You may run the program on the college server, OR on your

Personal platform (Visual Studio, Xcode, Replit)

Take screen shots of the output, paste them into a MS word file or direct your output to a textfile and copy this into your document

#include "ListNodecpp.h" #include "SortBycpp.h" #include template class LinkedList{

private: ListNode * front; int count;

public: LinkedList(); public: bool empty(); public: int size(); public: void add( T t); public: T get(T value); public: T get(int index); public: int insert( T t, SortBy f); //public: void insert( T t); public: int remove( T t); public: std::string toString(); public: void printList();

};

#include "LinkedList.h"

//GIVEN template LinkedList::LinkedList(){ front = nullptr; count=0; } //GIVEN template bool LinkedList::empty(){ return (front == nullptr); } //GIVEN template int LinkedList::size(){ return count; } //GIVEN //add is more efficient since it adds at the front //this is different from add of the Assignment 4 which adds at the end of List, so really the question is if we are going to add in order, then why make it more inefficient template void LinkedList::add( T t){ ListNode* e = new ListNode(t,front); front=e; count++; } /* template std::string LinkedList:: toString(int i){ return get(i).toString(); } */ //GIVEN template void LinkedList::printList(){ ListNode * cur =front; while (cur!=nullptr){ std::cout<toString()<<" "; cur=cur->next; } } //Requires: Song for inserting //Effects: creates a new ListNode with input value and inserts in proper position (increasing order of chart position)in the chain. If LinkedList, adds to the beginning //Modifies: front, if node is added at the beginning. //Also changes the next pointer of the previous node to point to the newly inserted list node. the next pointer of the newly inserted pointer points to what was the next of the previous node. This way both previous and current links are adjusted //TODO template int LinkedList::insert( T value, SortBy f){ int steps=0; //TODO return steps; } //Requires: Song title for searching //Effects: traverses the LinkedList (database) starting from front until the end comparing titles Returns the original search value if found otherwise returns an empty song with blank title //Modifies: Nothing

//TODO

template T LinkedList::get(T value){ ListNode * current = front;//this may need to change //TODO return current->getData(); } //TODO template int LinkedList::remove(T value){ //TODO int steps=0; return steps; }

//Requires: index position of Song to be found //Effects: traverses the LinkedList starting from front and travels to the index position (if valid) and returns the song at that index position. Note index position may NOT be the same as chart position //Modifies: Nothing //TODO template T LinkedList::get(int index){ ListNode * current = front; //TODO return current->getData(); }

#include #include template

//template class ListNode{ public: T data; ListNode * next;

// post: constructs a node with data 0 and null link public: ListNode(); public: ListNode(T data); public: ListNode(T idata, ListNode * newNext); public:std::string toString(); public: ListNode * getNext(); public: void setNext(ListNode * newNext); public: T getData(); public: void setData(T newData); };

#include "ListNode.h" template #include "ListNode.h" template ListNode::ListNode(){ //T t; next = nullptr; } template ListNode::ListNode(T iData){ data = iData; next = nullptr; } template ListNode::ListNode(T newData, ListNode* newNext){ data = newData; next = newNext; } //Getter method, returns the next pointer. template ListNode* ListNode::getNext(){ return next; } template void ListNode::setNext(ListNode* newNext){ next = newNext; } //Getter method, returns data. template T ListNode::getData(){ return data; } template void ListNode::setData(T newData){ data = newData; } template std::string ListNode::toString(){ return data.toString(); }

#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 setTitle(std::string newTitle); void setSinger(std::string newSinger); void setChartPosition(int pos); friend std::ostream & operator<<(std::ostream&, Song* s); int getChartPosition(); bool operator<(Song b);//used for search compare chartpositions bool operator<=(Song b);// used for binary search compare titles bool operator!=(Song b);// used for remove method compare titles bool operator==(Song b);// used for remove method compare titles };

#include "Song.h" Song::Song(){ title=""; singer=""; chartPosition=0; } Song::Song(std::string title, std::string singer, int chartPosition){ this->title=title; this->singer=singer; this->chartPosition=chartPosition; } std::string Song::toString(){ return "Title: "+title+ " Singer: "+singer+ " ChartPosition: "+std::to_string(chartPosition); } // std::ostream& operator<<(std::ostream & str, Song *s){ str<< s->toString(); return str; } int Song::getChartPosition(){ return chartPosition; } void Song::setChartPosition(int pos){ chartPosition=pos; } void Song::setTitle(std::string newTitle){ title=newTitle; } void Song::setSinger(std::string newSinger){ singer=newSinger; } bool Song::operator<(Song b){ return chartPosition

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 3 Lnai 8726

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448440, 978-3662448441

More Books

Students also viewed these Databases questions