Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ assignment Need Help Revising code below using classes & DYNAMIC memory allo

ID: 3678270 • Letter: C

Question

c++ assignment

Need Help Revising code below using classes & DYNAMIC memory allocation Please! Thank you.

Below is my assignment 7. Need help with the following:

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.

Assignment 7:


#include
#include
#include

using namespace std;

class Itunes
{
private:
string name;
string artist;
int bit_rate;
int total_time;

public:
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;

Itunes();

Itunes(string, string, int, int);

string to_string();

void set_defaults();
void display();

bool set_name(string);
bool set_artist(string);
bool set_bit_rate(int);
bool set_total_time(int);

string get_name();
string get_artist();
int get_bit_rate();
int get_total_time();
};

const string Itunes::DEFAULT_STRING = "(undefined)";

void display_songs(Itunes song_1, Itunes song_2,
Itunes song_3, Itunes song_4, Itunes song_5)
{
song_1.display();
song_2.display();
song_3.display();
song_4.display();
song_5.display();
}

Itunes::Itunes()
{
name = DEFAULT_STRING;
artist = DEFAULT_STRING;
bit_rate = DEFAULT_BITRATE;
total_time = DEFAULT_PLAY_TIME;
}

Itunes::Itunes(string song, string singer,
int rate, int time)
{
if (!set_name(song))
name = DEFAULT_STRING;
if (!set_artist(singer))
artist = DEFAULT_STRING;
if (!set_bit_rate(rate))
bit_rate = DEFAULT_BITRATE;
if (!set_total_time(time))
total_time = DEFAULT_PLAY_TIME;
}

string Itunes::to_string()
{
string info_in_string, rate_str, time_str;

ostringstream convert_rate_to_str,
convert_time_to_str;

convert_rate_to_str << bit_rate;
convert_time_to_str << total_time;

rate_str = convert_rate_to_str.str();
time_str = convert_time_to_str.str();

info_in_string = name + ", " + artist + ", "
+ rate_str +
"k bits per second, " + time_str +
" milliseconds.";

return info_in_string;
}

void Itunes::set_defaults()
{
name = DEFAULT_STRING;
artist = DEFAULT_STRING;
bit_rate = DEFAULT_BITRATE;
total_time = DEFAULT_PLAY_TIME;
}

void Itunes::display()
{
cout << to_string() << endl;
}

bool Itunes::set_name(string song)
{
if (song.length() >= MIN_STR_LENGTH &&
song.length() <= MAX_STR_LENGTH)
{
name = song;
return true;
}
else
{
name = DEFAULT_STRING;
return false;
}
}
bool Itunes::set_artist(string singer)
{
if (singer.length() >= MIN_STR_LENGTH &&
singer.length() <= MAX_STR_LENGTH)
{
artist = singer;
return true;
}
else
{
artist = DEFAULT_STRING;
return false;
}
}
bool Itunes::set_bit_rate(int rate)
{
if (rate >= MIN_BITRATE && rate <= MAX_BITRATE)
{
bit_rate = rate;
return true;
}
else
{
bit_rate = DEFAULT_BITRATE;
return false;
}
}
bool Itunes::set_total_time(int time)
{
if (time >= MIN_PLAY_TIME && time <= MAX_PLAY_TIME)
{
total_time = time;
return true;
}
else
{
total_time = DEFAULT_PLAY_TIME;
return false;
}
}

Explanation / Answer

#include <iostream>

#include <string>

using namespace std;

class iTunes

{

private:

string name;

string artist;

int bitrate;

int total_time;

public:

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 DEFAULT_BITRATE = 64;

static const int MIN_PLAY_TIME = 1000;

static const int MAX_PLAY_TIME = 1000*60*60;

static const int DEFAULT_PLAY_TIME = 1000;

static const int DEFAULT_STRING = "(undefined)";

// METHODS

string ToString();

void Display();

// CONSTRUCTORS

iTunes();

iTunes(name, artist, bit_rate, total_time);

// MUTATORS & ACCESSORS

string GetName() { return name; }

string GetArtist() { return artist; }

int GetBitrate() { return bitrate; }

int GetTotalTime() { return total_time; }

bool SetName(string theName);

bool SetArtist(string theArtist);

bool SetBitrate(int theBitrate);

bool SetTotalTime(int theTotalTime);

};

int main()

{

iTunes song1, song2, song3, song4;

song1.SetName("Prelude");

song1.SetArtist("Bonobo");

song1.SetBitrate(320);

song1.SetTotalTime(78000);

song2.SetName("Dolphin");

song2.SetArtist("Lone");

song2.SetBitrate(256);

song2.SetTotalTime(62000);

song3.SetName("I Thought It Was You");

song3.SetArtist("Onur Engin");

song3.SetBitrate(128);

song3.SetTotalTime(99000);

song4.SetName("Leftside Drive");

song4.SetArtist("Boards of Canada");

song4.SetBitrate(320);

song4.SetTotalTime(176200);

}

// class method defs

iTunes::iTunes()

{

name = SetName("(undefined)");

artist = SetArtist("(undefined)");

bitrate = SetBitrate(62);

total_time = SetTotalTime(1000);

}

// method def for iTunes() with parameters

iTunes::ToString()

{

}

iTunes::Display()

{

// Remember to format text by prepending or appending

cout << ToString();

}

bool iTunes::SetName(string name)

{

if (theName.length() < MIN_STR_LENGTH || theName.length() > MAX_STR_LENGTH)

return false;

name = theName;

return true;

}

bool iTunes::SetArtist(string artist)

{

if (theArtist.length() < MIN_STR_LENGTH || theArtist.length() > MAX_STR_LENGTH)

return false;

artist = theArtist;

return true;

}

bool iTunes::SetBitrate(int theBitrate)

{

if (theBitrate < MIN_BITRATE || theBitrate > MAX_BITRATE)

return false;

bitrate = theBitrate;

return true;

}

bool iTunes::SetTotalTime(int theTotalTime)

{

if (theTotalTime < MIN_PLAY_TIME || theTotalTime > MAX_PLAY_TIME)

return false;

total_time = theTotalTime;

return true;

}

string iTunes::GetName()

{

return name;

}

string iTunes::GetArtist()

{

return artist;

}

int iTunes::GetBitrate()

{

return bitrate;

}

int iTunes::GetTotalTime()

{

return total_time;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote