Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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
//return > 0 if this object is greater than other

int compareTo(Song* other);

//print the object in a format Artist: artist \nTitle: 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

3.41 Rating (157 Votes )

There are 3 Steps involved in it

Step: 1

Songh ifndef MYSONGCLASS define MYSONGCLASS include class Song private public member variables stdstring songTitle stdstring artistName stdstring song... 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

Statistics Alive

Authors: Wendy J. Steinberg

2nd Edition

1412979501, 978-1483343341, 1483343340, 978-1412979504

More Books

Students also viewed these Programming questions

Question

Explain the relationship between thoughts, feelings, and actions.

Answered: 1 week ago

Question

Define deferred revenue. Why is it a liability?

Answered: 1 week ago