Everything is in Project2.pdf
CECS275-Project2CL.xls CECS 275 Project 2 Checklist Requirements Comments Points Point Value Song Class (.h & .cpp) ___ instance variables (private strings and ints) ___ constructors ___ get methods ___ overloaded >, == ___ overloaded <,>> 15 Linked List Class (.h & .cpp) ___ modified Node and LinkedList to take Songs ___ modified remove to only remove first node ___ added sort method (uses >,doesn't pass in list) ___ added search by artist and title (uses ==) ___ added search by artist - returns vector of matches ___ added search by decade - returns vector of matches ___ overload < to="" display="" all="" songs="" 20="" file="" io="" ___="" fstream="" -="" in="" out="" ___="" read="" &="" write="" to="" 'songs.txt'="" ___="" write="" on="" program="" exit="" ___="" doesn't="" crash="" on="" 2nd="" run="" 15="" sort="" ___="" used="" bubble="" sort="" that="" uses="" overloaded=""> operator ___ does not pass in list to sort function ___ does not call the linked list's get or size functions 5 Main ___ LinkedList of Songs ___ read and add Songs from file to list ___ repeating menu/submenus ___ add new song to LinkedList ___ play song (remove first song) ___ search by title and artist ___ search by artist - display list of matches ___ search by decade - display list of matches ___ display number and sorted songs (by rating, artist, title) ___ write songs back to file on exit ___ made functions to keep code clean 20 Coding Standards & Documentation Docs: ____inst var ____classes ____methods ____main CS: __ var names __ tabs/spacing __ No exceptions thrown __ Error check all user input __ No global variables 25 Early/Late (±10%) Date Submitted: _______________ Errors: -1 -1 Early / Late Total 100 Name: ______________________________________ CECS 275 – Project 2 – Music Library CECS 275 – Project 2 – Music Library Create a program that reads in a list of songs from a text file and stores it in a Linked List. Allow the user to display, add, play, or search for Songs. Song class (.h and .cpp): Data Members (all private): string title, string artist, int year, and int rating (1-5 stars). Methods: 1. Constructor - pass in and set the title and artist (year and rating are 0). 2. Constructor - pass in and set all data members. 3. get methods - for each data member (no set methods). 4. overloaded < -="" all="" data="" on="" one="" line="" in="" the="" same="" format="" as="" the="" file.="" 5.="" overloaded="">> - read in all data from the user. 6. overloaded == - compares by title and artist. 7. overloaded > - compare by rating (5-1 stars). If the ratings are the same, then compare by artist, then title. Node and Linked List class (.h and .cpp from Lectures 17 & 18, modified to use Songs): Methods to have (remove all others): 1. Constructor – create an initially empty Linked List. 2. isEmpty – returns true if the list is empty, false otherwise. 3. add (to end) – add a new Song object to the end of the list. 4. size – return the number of Songs in the list. 5. remove – remove the first Song in the list. 6. searchSong - pass in the title and artist, compare using the Song’s overloaded == operator, return the first matching Song, or null, if it does not exist. 7. searchArtist - pass in the artist’s name, return a vector of matching Songs. 8. searchDecade - pass in a decade, return a vector of matching Songs from that decade (ex. 1980’s = 1980-1989). 9. sort – modify Bubble Sort code to use the Song’s overloaded > operator to sort the list. Do not pass in the list to the method and don’t use get() or size(). 10. overloaded < -="" iterate="" through="" the="" list="" to="" add="" each="" song="" to="" the="" stream="" suitable="" for="" writing="" the="" contents="" of="" the="" linked="" list="" back="" to="" the="" file.="" main="" –="" create="" a="" linked="" list="" of="" songs="" that="" is="" initially="" populated="" from="" “songs.txt”.="" allow="" the="" user="" to="" choose="" from="" the="" following="" functions:="" 1.="" add="" -="" use="" the="">> operator to get the song’s data from the user. Construct the Song and add it to the end of the Linked List. Resort the list. 2. Play - remove the Song from the front of the list (the song removed should always be the highest rated song in the list). Display that Song’s information. 3. Search - a. by Title and Artist – prompt the user to enter a title and artist name, then display the matching Song, or “Not Found” if it does not exist. b. by Artist – prompt the user to enter an artist name, then display all Songs in the list by that artist. c. by Decade – prompt the user to enter a decade, then display all Songs in the list from that decade (ex. 80’s = 1980-1989). 4. Display – display the number of songs, then display each of the Songs in the list (they should already be sorted by rating). 5. Quit - write the edited list of Songs back to the file using the < operator="" overwriting="" the="" old="" one.="" notes="" •="" the="" input="" and="" output="" file="" are="" the="" same="" file.="" overwrite="" the="" old="" contents.="" •="" check="" all="" user="" input="" for="" validity.="" •="" add="" documentation="" to="" your="" classes.="" cecs275-lect17-linkedlist1="" ©2020="" cleary="" cecs="" 275="" –="" lecture="" 17="" –="" linked="" lists="" linked="" list="" –="" a="" linked="" list="" is="" a="" data="" structure="" made="" of="" a="" series="" of="" connected="" nodes.="" each="" node="" in="" the="" list="" contains="" the="" data="" to="" be="" stored="" (either="" a="" value="" or="" an="" object)="" and="" a="" reference="" to="" the="" next="" node="" in="" the="" list.="" the="" first="" item="" in="" the="" list="" is="" often="" referred="" to="" as="" the="" head="" of="" the="" list,="" and="" the="" last="" item="" as="" the="" tail.="" the="" last="" node="" in="" the="" list="" always="" points="" to="" null.="" there="" are="" several="" benefits="" to="" linked="" lists="" over="" arrays:="" they="" expand="" and="" contract="" as="" you="" add="" or="" remove="" items="" from="" the="" list,="" and="" items="" can="" be="" added="" or="" removed="" from="" anywhere="" in="" the="" list="" without="" reorganization.="" however,="" since="" only="" the="" first="" item="" is="" kept="" track="" of,="" you="" cannot="" directly="" access="" any="" of="" the="" other="" items="" in="" it,="" you="" must="" iterate="" across="" the="" list="" to="" it.="" node="" structure="" –="" a="" node="" holds="" an="" element="" to="" be="" stored="" and="" a="" reference="" to="" the="" next="" node.="" struct="" node="" {="" string="" data;="" or="" any="" other="" data="" type="" node="" *next;="" };="" a="" basic="" linked="" list="" class="" –="" the="" linked="" list="" always="" keeps="" track="" of="" the="" first="" node="" in="" the="" list="" so="" that="" it="" can="" be="" traversed.="" functions="" include:="" isempty(),="" size(),="" add(),="" get(),="" and="" print().="" #ifndef="" linkedlist_h="" #define="" linkedlist_h="" #include="">
using namespace std; class LinkedList { private: struct Node { string data; Node *next; }; Node *first; public: LinkedList( ) { first = NULL; } ~LinkedList( ); bool isEmpty( ) { return first == NULL; } void add( string s ); int size( ); void print( ); string get( int i ); void set( int i, string s ); }; #endif ©2020 Cleary #include “LinkedList.h” void LinkedList::add( string s ) { Node *newNode = new Node; newNode->data = s; newNode->next = NULL; if( first == NULL ) { first = newNode; } else { Node *n = first; while( n->next != NULL ) { n = n->next; } n->next = newNode; } } int LinkedList::size( ) { Node *n = first; int count = 0; while( n != NULL ) { n = n->next; count++; } return count; } void LinkedList::print( ) { Node *n = first; while( n != NULL ) { cout< n-="">data < “="" ”;="" n="n-">next; } cout< endl;="" }="" string="" linkedlist::get(="" int="" i="" )="" {="" if(="" i="">= 0 && i < size(="" )="" )="" {="" node="" *n="first;" for(="" int="" j="0;" j="">< i;="" j++="" )="" {="" n="n-">next; } return n->data; } return “”; } void LinkedList::set( int i, string s ) { if( i >= 0 && i < size(="" )="" )="" {="" node="" *n="first;" ©2020="" cleary="" for(="" int="" j="0;" j="">< i;="" j++="" )="" {="" n="n-">next; } n->data = s; } } LinkedList::~LinkedList( ) { Node *nextNode; Node *nodePtr = first; while( nodePtr != NULL ) { nextNode = nodePtr->next; delete nodePtr; nodePtr = nextNode; } } Test the Linked List in Main - #include #include “LinkedList.h” using namespace std; void printIsEmpty( LinkedList &list ) { if( list.isEmpty( ) ) { cout< “list="" is="" empty.”="">< “list="" is="" not="" empty.”="">< “size="”">< list.size(="" )="">< “adding="" items...”="">< “index="" 2="”">< list.get(="" 2="" )="">,>