Question: Problem You Need to Solve for This Project (Same as Project 2) You are asked to write an app to keep track of a relatively
Problem You Need to Solve for This Project (Same as Project 2) You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should save the data back to the same data file when the program exits. What Your Program Should Do (Same as Project 2)
Write an interactive text based menu interface (using a loop) that will allow the user to Enter information for a new song Display information for all the songs in the database with index for each song Remove a song by index Search for songs by a certain artist Search for songs by a certain album Quit
For each song, you need to keep track of:
title artist duration album
Allow the program to keep looping until user wants to quit. When the program starts, it should load the tasks from external file ("songs.txt") into memory. When user enters information about the new song, the program needs to read them in, save them in memory and eventually write them to the external data file ("songs.txt"). The file format could look like:
Stereo Hearts;Gym Class Heroes;3;34;The Papercut Chronicles II Counting Stars;OneRepulic;4;17;Native The ';' is used as a delimiter or field separator. Each record ends with a new line character. Also the above sample data came from my teen son, not a reflection of your instructors music taste
Some Implementation Requirements: (Different from Project 2!!!)
1. Use structs or class named Song to model song. You are encouraged in every way to use class to model song in this project. If you do the work here, you will benefit from this in Project 4 and 5. 2. Use class named SongList to model the collection of songs. 3. Use array of Song to implement class SongList 4. Use int data type to model the duration (minutes and seconds) for each song. You must do data validation for this to prevent letters or characters from crashing your code. 5. When using class, please make sure you encapsulate the data which means make all the instance data member private and provide accessor methods and mutator methods to access and manipulate the data. 7. You are required to have a makefile inside the project directory. The tar file should have the makefile in it. When I grade your project, after extracting from the tar file, all I will do is to type make to build your app and make clean to remove the
This is my code
//Main.cpp
#include #include #include #include #include #include
Using namespace std;
int option; int menu int counter = 0; Song collection[200]; Struct Song { String title, artist, album; double duration; }
int main() { cout<<"1)Enter information of New Song"< cout<<"2)display information of all songs with index"< cout<<"3)Remove a song by index"< cout<<"4)Search a Song by certain artist"< cout<<"5)Search a Song by certain album "< cout<<"6)Exit Program"< cin >> option; switch (option) { case 1: cout << " Add a new songs information" << endl; void AddNewsong (); counter++; break; case 2: cout << " Remove a song by particular index" << endl; void Remove(int counter); break; case 3: cout << " Display a all songs" << endl; void Display(); break; case 4: search a song by certain Artist< void SearchbyArt(string artist); break; case 5: search a song by certain Album< void SearchbyAlb(string album); break; case 6: cout<< " Quit" << endl; void Exit(); break; default: cout << " Input a value between 1-6" << endl; return menu(); }
//song.cpp #include #include #include "song.h"
void addNewsong() { cout << " Enter song title:" << endl; getline(cin, title); collection[counter].setTitle(title);
cout << " Enter song artist:" << endl; getline(cin, artist); collection[counter].setArtist(artist);
cout << " Enter song album:" << endl; getline(cin, album); collection[counter].setAlbum(album); cout<< enter duration of song:< getLine(cin,duration); collection[counter].setDuration(duration); return menu(); }
void Remove(int counter); { cout << " Enter index of song you want to delete" << endl; getline(cin, counter); collection[counter].remove();
return menu(); }
void DisplayallSongs(int counter); { int i; Song list;
cout << " Here are the songs in your collection: "<< endl;
for(i = 0; i { list = collection[i];
cout << "Title:" << list.getTitle() << endl; cout << "Artist:" << list.getArtist()<< endl; cout << "Album:" << cout << list.getAlbum()<< endl; cout< void SearchbyAlb(string album) { cout<< please enter the album name:< getLine(cin,album); for(i = 0; i { if(collection[i].getAlbum() == album) cout< } void Exit() { } Song:: Song() { title= " "; artist = " "; album = " "; } Song::Song(string aTitle, string anArtist, string anAlbum,double aDuration) { title = aTitle; //Assing parameters artist = anArtist; album = anAlbum; } string Song::getTitle() const { return title; } void Song:: setTitle(string newTitle) { title= newTitle; } string Song::getArtist() const { return artist; } void Song:: setArtist(string newArtist) { artist=newArtist; } string Song::getAlbum() const { return album; } void Song::setAlbum(string newAlbum) { album= newAlbum; } double Song::getDuration() const { Return duration; } Void Song::setDuration(double newduration) { Duration =newDuration; } string Song::toDisplayString() const { string view = " Title: " + title; view += " Author: " + artist; view += " Album: " + album; View+= Duration: +duration+ " "; return view; } Note: to output it to Songs.txt file we can use: Ofstream fout(songs.txt); for(int i=0;i { fout< } //song.h #ifndef SONG_H #define SONG_H Struct Song { String title, artist, album; double duration; public: Song(); //default constructor Song(string aTitle, string anArtist, string anAlbum, double aDuration); string getTitle()const; string getArtist()const; string getAlbum()const; string getDuration()const; void setTitle(string newTitle); void setArtist(string newArtist); void setAlbum(string newAlbum); void setDuration(double newDuration); string toDisplayString() const; void AddNewsong(); void Remove(int counter); void Display(); void SearchbyArt(string anArtist); void SearchbyAlb(string anAlbum); void Exit(); private: string title; string artist; string album; double duration; }; #endif
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
