Question
Problem 1: Maintain a Catalog of Songs This problem focuses on implementing a linked list. Turn in a file named SongCatalog.cpp zipped in a folder
Problem 1: Maintain a Catalog of Songs
This problem focuses on implementing a linked list. Turn in a file named SongCatalog.cpp zipped in a folder called problem1. You will need to support classes Song, and SongList (skeleton classes are provided below and in a skeleton.cpp file along with a possible driver), and songs.txt (provided along with this assignment). The provided skeleton file will not compile without your solution or commenting some functions. Feel free to add methods to class when needed and to modify the driver.
You are required to develop a software that will let a user organize his or her music collection. Instead of a database you will be storing all the information in a file. Your program will be an interface to this file and provide a database-like functionality. The user of your program will be able to add songs to the file, delete songs, search for songs, or display everything on file.
The songs will be stored in a file called songs.txt. The format of each song has been deliberately kept simple. The songs are kept in sorted order in the file. Songs are sorted by artist and then title.
Artist: The Beatles Title: The Fool on the Hill
In your program you will read in the data from the file, create a Song object for each song and store these objects in aLinked List that you develop. Your program will be menu driven. The menu will be of the following form:
Song Catalog Menu 1. Import songs from a file 2. Add a song 3. Delete a song 4. Search for a song 5. Get a song by title 6. Get all songs by artist 7. Display all songs 8. Exit program Enter selection (1 - 8):
If the user does not enter a valid selection, i.e. a number between 1 and 8 inclusive you will reprint the menu. For valid menu selection you will handle each case separately.
1
1. Import Songs from a File: You will prompt the user to enter the absolute path name to the file. Check if the file exists and is readable. The format for the data must be in the same form as songs.txt. Read the contents of the file and populate the List. Once you have processed the request reprint the menu.
2. Add a new song: You will prompt the user to enter the name of the artist and the title of the song.Enter artist:
Enter title:
If that song is already there, print a message to that effect. If the song is not there you will insert the song in its rightful place in the sorted list of songs. You will be using a variation of insertion sort for doing that. After you have processed this request you will reprint the main menu.
3. Delete a song: You will prompt the user to enter if the deletion will be by artist or title. For invalid entries prompt the user again. Depending on the valid response that you get, prompt the user to enter either the name of the artist or the title of the song.
Delete by artist or title (A or T): A Enter artist:
If the deletion is by artist name you will delete all songs by that artist. If the deletion is by song title, then you will delete only the entry for that song. If the artist or the title does not exist, you will write a message to that effect. After you have processed this request you will reprint the main menu.
4. Search for (a) song(s): You will prompt the user to enter if the search will be by artist or title. For invalid entries prompt the user again. Depending on the valid response that you get, prompt the user to enter either the name of the artist or the title of the song.
Search by artist or title (A or T): T Enter title:
If the search is by artist name, you will display all songs by that artist in the collection. If the search is by title you will display the name of the artist and the title in the collection. If the artist or the title does not exist then you will write a message to that effect. After you have processed this request you will reprint the main menu.
5. Get a song by title: You will prompt the user to enter a title then return a Song object of this title without deleting it from the main song list. Return null of such a song does not exist. After you have processed the request you will reprint the main menu.
Enter title:
6. Get all songs by artist: You will prompt the user to enter an artist then you will return a list of all songs by a given artist without deleting them from the main list. Return null if the artist does not have any song. After getting the list you should display it by invoking on the returned SongList object the displayCatalogue() method from the SongListclass (see skeleton below) After you have processed the request you will reprint the main menu.
Enter artist:
7. Display all songs: You will display all songs in the list. After you have processed the request you will reprint the main menu.
8. Exit program: You will over-write the file songs.txt with the modified list of songs in the original format. You will write a message thanking the user for using the software.
2
A skeleton of the code (classes Song and SongList) is provided below to get you started. If deemed necessary, you can do some changes such as adding some helper methods or changing the signatures of some methods.
class Song{ private:
string artist; string title; Song* next;
public:
// define a constructor to initialize artist and title but next to null
Song(string artist,string title);
// define a constructor to initialize artist, title, and next to another //song object Song(string artist,string title,Song* next);
// define a deafault constructor
Song();
// compareTo two song objects first by artist and then by title //return 0 if they are equal //return <0 if this object is smaller than other> 0 if this object is greater than other
int compareTo(Song* other);
//print the object in a format Artist: artist Title: title such as //Artist: The Beatles //Title: The Fool on the Hill friend ostream& operator <<(ostream& outs, const Song& song);
// SongList
friend class SongList; };
// Define a songList class
class SongList{ private:
Song* head;
int numSongs;
public:
//to track the number of songs. Increment when you add // decrement when you remove
//list construct and destruct
SongList(); ~SongList();
// This method reads data from a file afile and populates the list // songs.txt has the following format: // Artist: ... // Title: ....
// empty line // Artist: ... // Title: ... // empty line ... and so onvoid readFile (string aFile);
// This method adds a song to the list while maintaining its sorted order in the list // node should be created and added in the right position
3
void addSong (string artist, string title);
// This method deletes all songs by an artist
void deleteByArtist (string artist);
// This method should return a song list that contains all songs by an artist // without deleting them from the main SongList object. SongList * getSongsByArtist (string artist);
// This method deletes a given song
void deleteByTitle (string title);
// This method returns a song object matching the given title without // deleting the song from the main list. It returns NULL if the object does not existSong* getByTitle (string title);
// This method searches for all songs by an artist and displays them
void searchByArtist (string artist);
// This method searches for a given song and displays it
void searchByTitle (string title);
// This method displays all entries in the collection
void displayCatalog ();
// This method over-writes the file
void writeFile ();
};
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