Write a C++ program that will allow the user to manage the storage portion of a
ID: 669487 • Letter: W
Question
Write a C++ program that will allow the user to manage the storage portion of a digital music player. The music player will store the following information about each song:
• Song title (e.g., “Hey Jude”: may contain spaces, must be unique)
• Artist name (e.g., “The Beatles”: may contain spaces, not unique)
• Size (the song’s size in MB; a float with value greater than 0)
• Play count (the number of times the song has been played; an integer)
• Lyrics (e.g., “Take a sad song and make it better”: one line of the song’s lyrics, may contain spaces; used in this assignment to simulate ‘playing’ the song)
Your music player should be able to store up to 25 songs and has a maximum storage capacity of 50.0 MB.
When run, the music player program should offer the user a menu with the following options: (Do not change the numbers associated with the operations!) 1. Add a new song to the player (prompt the user for input values) 2. Remove a song from the player (by title) 3. Play a song (by title) 4. Display a song’s metadata (given its title) 5. Display the full playlist ordered alphabetically by title 6. Display the player’s remaining storage capacity (in MB) 7. Quit the program The program should perform the selected operation (or display a message stating that an invalid menu choice was entered) and then re-display the menu.
For the Add Song operation, the program should prompt the user to enter a song title, an artist name, the song’s size in MB (with input validation), and a line of lyrics. A complete solution will ensure that the music player is not full (25 songs, or no storage capacity remaining for the song’s size). If the song cannot be added, the program should output a message stating why.
For the Remove Song operation, the program should prompt the user to enter a song title to remove. The program should indicate whether the operation was successful or not.
For the Play Song operation, the program should prompt the user to enter a song title to play. The program should increment the play count of the song, then output the song’s name and artist followed by its lyrics. If the song is not found, the program should indicate an error. (You don’t need to validate that the play count doesn’t overflow the max value of an integer).
For the Display Metadata operation, the program should prompt the user to enter a song title to display. It should then output the title, the artist name, the file size, and the play count of the song. If the song is not found, the program should display an appropriate error message.
For the Display Playlist operation, the program should display the title, artist, size, and play count for each song, with each song printed on its own line. If the music player is empty, the program should display a message stating so. For the Display Remaining Capacity operation, the program should display the number of MB of remaining storage space available on the music player. All output is to standard (console) out.
Additional requirements:
• Do not use global variables! Global named constants are encouraged.
• Use an array of Song structures to represent the music player contents. The structure definition should be global, but the array of structures may NOT be global.
• When the music player contains fewer than 25 songs, all empty slots should be at the back of the array. Keep a count of how many songs are stored in the music player. The songs should always be stored in elements 0 through count-1 of the array.
• You MUST use binary search for all searches! Your code may not have a linear search anywhere!
• Your program must be modular, with significant work done by functions. Each function should perform a single, well-defined task. (Hints: The actions represented by each menu choice would make good functions, though it’s likely you’ll want a handful of others, too). Pay attention to which function parameters need to be references.
Explanation / Answer
the main shows some tings, possibll not all
#include <iostream>
#include <string.h>
using namespace std;
class itunes
{private:
string name;
string artist;
int bitrate;
int total_time;
public:
itunes();
itunes(string,string,int,int);
static const int MIN_BITRATE=64;
static const int MAX_BITRATE = 705;
static const int MIN_STR_LENGTH = 1;
static const int MAX_STR_LENGTH = 80;
static const int MIN_PLAY_TIME = 1000;
static const int MAX_PLAY_TIME = 1000*60*60;
static const int DEFAULT_BITRATE = 64;
static const int DEFAULT_PLAY_TIME = 1000;
static const string DEFAULT_STRING;
void Display();
string getname();
string getartist();
int getbitrate();
int gettotal_time();
void setbitrate(int);
void settotal_time(int);
void setname(string );
void setartist(string );
};
const string itunes::DEFAULT_STRING = " (undefined) ";
itunes::itunes()
{name=DEFAULT_STRING;
artist=DEFAULT_STRING;
bitrate=DEFAULT_BITRATE;
total_time=DEFAULT_PLAY_TIME;
}
itunes::itunes(string n, string a, int b, int p)
{setname(n);
setartist(a);
setbitrate(b);
settotal_time(p);
}
void itunes::Display()
{cout<<"Title: "<<name<<endl;
cout<<"Artist: "<<artist<<endl;
cout<<"Bit Rate: "<<bitrate<<" kilobits per second ";
cout<<"Playing Time: "<<total_time/100<<" seconds ";
}
string itunes::getname()
{return name;
}
string itunes::getartist()
{return artist;
}
int itunes::getbitrate()
{return bitrate;
}
int itunes::gettotal_time()
{return total_time;
}
void itunes::setbitrate(int b)
{if(b<MIN_BITRATE||b>MAX_BITRATE)
{cout<<"bitrate out of bounds, default used ";
bitrate=DEFAULT_BITRATE;
}
else
bitrate=b;
}
void itunes::settotal_time(int t)
{if(t<MIN_PLAY_TIME||t>MAX_PLAY_TIME)
{cout<<"play time out of bounds, default used ";
bitrate=DEFAULT_PLAY_TIME;
}
else
total_time=t;
}
void itunes::setname(string n)
{if(n.length()<MIN_STR_LENGTH ||n.length()>MAX_STR_LENGTH)
{cout<<"name length out of bounds, default used ";
name=DEFAULT_STRING;
}
else
name=n;
}
void itunes::setartist(string a)
{if(a.length()<MIN_STR_LENGTH ||a.length()>MAX_STR_LENGTH)
{cout<<"artist name length out of bounds, default used ";
artist=DEFAULT_STRING;
}
else
artist=a;
}
int main()
{string s;
int i;
itunes a;
a.Display();
itunes b("Janiva Magness", "You Were Never Mine",128, 276 );
b.Display();
s=b.getname();
a.setname(s);
a.Display();
itunes c("", "Hello",1000, 276 );
c.Display();
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.