Need Help ASAP C++ Assignment! Thank you!!! Music Library Dynamic Memory OK, we
ID: 3676601 • Letter: N
Question
Need Help ASAP C++ Assignment! Thank you!!!
Music Library
Dynamic Memory
OK, we have come to realize how useful going forward our Music Library will prove to be. Now that we are thinking long range in terms of building our Music Library we realize that our solution needs might better be served with dynamic memory. This change will allow us to handily grow and shrink our library as our storage needs ebb and flow.
For this bonus assignment pointers and dynamic memory will be used to implement your Assignment # 7 lab. This will call for revising your lab 7 solution to now use classes and dynamic memory allocation. Expand your solution to include capability to delete a descriptor in the library. Done correctly, this change will only require revision in the client.
When your new and improved dynamic library is up and functional do demonstrate that all is in working order by providing the exact same run as shown in your assignment 7 lab. In order to showcase the expanded deletion capability of this new music library version, delete an iTune entry in your library.
If you read on you will see that the rest of this assignment specification is the same as Lab 7. Let this serve as a telltale sign of the reusability of your Assignment # 7 class solution.
Understand the Application
An iTune entry in music library is a descriptor that summarizes information about the tune that it describes. (It is not the actual tune, which is contained in a large music data file.)
This application will start you on your way to building your very own music library. Using descriptors to identify each iTune entry, you will be able to build your repository of music favorites. Not only that, as your library grows you be able to find your iTune entry thanks to the organized filing system that you are about to explore.
For each iTune entry in your own music library file there are between 20 and 50 fields – i.e. members. If you were to look at the file on your system, you would find that the fields have names like Genre, Track ID, Name, Artist, Bit Rate, Sample Rate, Track Type, and so on.
To get things started in this music business we will develop our own iTune class.
The Program Spec
We will consider a simplified iTune class, that stores these iTune entry objects, with only the following four members for each object:
Name (the title of the song)
Artist (the performing musician or group)
Bit Rate (the number of kilobits per second that the iTune streams at or plays at –- higher for better quality, lower for smaller data file size)
Total Time (the playing time of the iTune, represented in milliseconds, i.e., 36500 would stand for 36.5 seconds)
Create a class called iTune that represents these four items, and provides solid protection for the fields. Then, provide a sample client that instantiates between three and sixiTune objects and mutates and displays these objects. The details follow.
Private class instance members:
string name – the title of the song. All legal strings should be between 1 and 80 characters.
string artist –the performing musician or group. All legal strings should be between 1 and 80 characters.
int bitrate – the number of kilobits per second. A legal value should be between 64 and 705.
int total_time – the playing time in milliseconds. A legal value should be between 1 second and 1 hour (expressed in milliseconds)
As stated in our class lectures, we never want to see a literal in our methods. So the class should have static members to hold values for the limits described above, as well as default values for any field that is constructed using illegal arguments from the client. These are put in the public static section.
Public class static constants:
MIN_BITRATE = 64
MAX_BITRATE = 705
MIN_STR_LENGTH = 1
MAX_STR_LENGTH = 80
MIN_PLAY_TIME = 0
MAX_PLAY_TIME = 1000 * 60 * 60
DEFAULT_BITRATE = 64
DEFAULT_PLAY_TIME = 1
DEFAULT_STRING = “ (undefined) “
You should supply all of the following public instance methods:
Constructors – one that takes no parameters (sets values to default) and one that takes all four parameters.
Accessors (get()s) and Mutators (set()s) for each instance member.
string toString() – a method that returns a string which contains all the information of the iTune. This string can be in any format as long as it is understandable and clearly formatted. Two of the many possible formats for such a string for one iTune might be:
“Janiva Magness, You Were Never Mine, 276 seconds, 128 bits per second”
Title: You Were Never Mind / Artist: Janiva Magness / Playing Time: 4 minutes 36 seconds / Bit Rate: 128k”
void display() – an output method that sends the string returned by the toString() to the screen. display() can, alternatively, send the data directly to the screen on several lines in a different manner than toString(). It can also call upon toString() but prepend and append extra formatting for the console.
Happy listening!
Input Error Checking: Always check for invalid client input in set() methods.
Test Run Requirements: Only submit one run that shows a sample client that instantiates between three to six iTunes objects and mutates and displays these objects. Verify set() methods honor limits defined in the spec.
Here are some tips and requirements:
The client has been described specifically in the program spec, but to summarize, it should instantiate, mutate, display objects and thoroughly test your class. It does not have to take any input from the user. It must certainly confirm, for instance, that your mutators correctly filter out and report bad arguments to the client through its return value.
Inline methods are allowed for get() Methods only.
Sample Partial Output Run:
iTunes Song -------:
"Hobo Blues", by John Lee Hooker
Duration: 182 seconds, Bit Rate: 128
.
.
.
etc.
Explanation / Answer
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <fstream>
#include "songs.h"
using namespace std;
void Welcome();
int main()
{
vector <Songs*> library;
vector <Songs*> playlist;
Welcome(); // Welcome screen.
// Main Menu: (S) enter song, (L) review library, (P)review playlist, or (X) print and end program.
//Check SLPX in while loop.
// S - Enter Song: Name, length (s), artist name, album name, genre, star rating, year.
// Check length (s, ><), check genre(1 of 5), check rating(1-5), check year(>1900<2010).
// Add to playlist? Y or N (Check);
Y copy to playlist vector
// -> Main Menu
// L - Print library (function)
// Ask to delete song from libray (and playligst; search and delete), add song to playlist not on it yet, or go back to Main Menu.
// P - Print playlist (function)
// Ask to delete song from playlist, or back to Main Menu
// X - Print Both (function; no questions; end)
return 0;
}
void Welcome()
{
cout << endl;
cout << "-----------------------------------------" << endl;
cout << "Welcome to myTunes." << endl << endl;
}
#ifndef SONGS_H_
#define SONGS_H_
#include <string>
#include <vector>
using namespace std;
class Songs
{
private:
string songName;
string artistName;
string albumName;
string genre;
int playTime;
int year;
int starRating;
char yesOrNo;
public:
Songs();
Songs(string SN, string ArN, string AlN, int PT, int YR, int SR, string GR);
string getSongName();
void setSongName(string newSong);
string getArtistName();
void setArtistName(string newArtist);
string getAlbumName();
void setAlbumName(string newAlbum);
int getPlayTime();
void setPlayTime(int newTime);
int getYear();
void setYear(int newYear);
int getStarRating();
void setStarRating(int newStarRating);
string getSongGenre();
void setSongGenre(string newGenre);
void addSongLibrary(vector<Songs> *library, vector<Songs> *playlist);
};
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include "songs.h"
using namespace std;
Songs::Songs()
{
this->songName = " ";
this->artistName = " ";
this->albumName = " ";
this->playTime = 1;
this->year = 1901;
this->starRating = 1;
this->genre = "Other";
}
Songs::Songs(string SN, string ArN, string AlN, int PT, int YR, int SR, string GR)
{
this->songName = SN;
this->artistName = ArN;
this->albumName = AlN;
this->playTime = PT;
this->year = YR;
this->starRating = SR;
this->genre = GR;
}
string Songs::getSongName()
{
return songName;
}
void Songs::setSongName(string newSong)
{
this->songName = newSong;
}
string Songs::getArtistName()
{
return artistName;
}
void Songs::setArtistName(string newArtist)
{
this->artistName = newArtist;
}
string Songs::getAlbumName()
{
return albumName;
}
void Songs::setAlbumName(string newAlbum)
{
this->albumName = newAlbum;
}
int Songs::getPlayTime()
{
return playTime;
}
void Songs::setPlayTime(int newTime)
{
this->playTime = newTime;
}
int Songs::getYear()
{
return year;
}
void Songs::setYear(int newYear)
{
this->year = newYear;
}
int Songs::getStarRating()
{
return starRating;
}
void Songs::setStarRating(int newStarRating)
{
this->starRating = newStarRating;
}
string Songs::getSongGenre()
{
return genre;
}
void Songs::setSongGenre(string newGenre)
{
this->genre = newGenre;
}
void Songs::addSongLibrary(vector<Songs> *library, vector<Songs> *playlist)
{
cout << "Please enter song name: ";
getline(cin, songName);
cout << "Please enter artist name: ";
getline(cin, artistName);
cout << "Please enter album name: ";
getline(cin, albumName);
while(true)
{
cout << "Please enter length of song in seconds: ";
cin >> playTime;
if(!cin.fail() && playTime > 0)
break;
else if(cin.fail())
cout << "Time must be in seconds. Please enter the song's length again: ";
else if(playTime <= 0)
cout << "Time must be greater than 0 seconds. Please enter the song's length again: ";
cin >> playTime;
}
while(true)
{
cout << "Please enter the year the song was made: ";
cin >> year;
if(!cin.fail() && year < 1900)
break;
else if(cin.fail())
cout << "Year must be in numbers. Please enter the song's year again: ";
else if(year < 1900)
cout << "Year must be 1900 or greater. Please enter the song's year again: ";
cin >> year;
}
while(true)
{
cout << "Please enter a star rating for the song (1 to 5 stars): ";
cin >> starRating;
if(!cin.fail() && starRating >= 1 && starRating <= 5)
break;
else if(cin.fail())
cout << "Rating can only be the digits 1, 2, 3, 4, or 5. Please enter a new rating for the song: ";
else if(starRating < 1 || starRating > 5)
cout << "Rating must be between 1 and 5. Please enter the song's year again: ";
cin >> year;
}
while(true)
{
cout << "Please enter a genre (Rock, Rap, Country, Gospel, or Other) for the song: ";
cin >> genre;
if(genre == "Rock" || genre == "Rap" || genre == "Country" || genre == "Gospel" || genre == "Other")
break;
else
cout << "Genre not recognized. Please enter one of the five given genres (Rock, Rap, Country, Gospel, or Other)";
cin >> genre;
}
Songs* newSongInfo = new Songs();
newSongInfo->setSongName(songName);
newSongInfo->setArtistName(artistName);
newSongInfo->setAlbumName(albumName);
newSongInfo->setPlayTime(playTime);
newSongInfo->setYear(year);
newSongInfo->setStarRating(starRating);
newSongInfo->setSongGenre(genre);
library->push_back(*newSongInfo);;
while(true)
{
cout << "Enter y to add the song to you playlist, or n to do nothing: ";
cin >> yesOrNo;
if(yesOrNo = 'y')
{
playlist->push_back(*newSongInfo);
break;
}
else if(yesOrNo == 'n')
break;
else
cout << "Invalid operation. Please enter y to add the song to you playlist, or n to do nothing: ";
cin >> yesOrNo;
}
}
#endif
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.