Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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 unsigned int MIN_STR_LENGTH = 1;
- static const unsigned int MAX_STR_LENGTH = 80;
- static const int DEFAULT_BITRATE = 64; // REMEMBER TO CONVERT FROM MILISECONDS TO SECONDS -- cant use literals so would MIN_PLAY_TIME work? i.e. theTotalTime/MIN_PLAY_TIME
- 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 string DEFAULT_STRING;
- // CONSTRUCTORS
- iTunes();
- iTunes(string newName, string newArtist, int newBitrate, int newTotalTime);
- // MUTATORS & ACCESSORS & METHODS
- string GetName();
- string GetArtist();
- int GetBitrate();
- int GetTotalTime();
- bool SetName(string theName);
- bool SetArtist(string theArtist);
- bool SetBitrate(int theBitrate);
- bool SetTotalTime(int theTotalTime);
- string ToString();
- void Display();
- };
- const string iTunes::DEFAULT_STRING = "(undefined)";
- int main()
- {
- iTunes song1("Prelude", "Bonobo", 3200, 780000000),
- song2("Dolphin", "Lone", 256, 62000),
- song3("I Thought It Was You","Onur Engin",128, 92200),
- song4("Leftside Drive", "Boards of Canada", 320, 176200);
- // Mutator tests
- if ( !song2.SetBitrate(999))
- cout << "Unable to set Bitrate to 999." << endl;
- else
- cout << "Bitrate set to 999." << endl;
- if ( !song4.SetTotalTime(0))
- cout << "Unable to set Total Time to 0." << endl;
- else
- cout << "Total Time set to 0." << endl;
- if ( !song1.SetArtist(""))
- cout << "Unable to set Artist. Invalid string length." << endl;
- else
- cout << "Artist name is set." << endl;
- // int x and CIN are only to pause the output so I can see the run in crappy Visual Basic 2008 -- isnt there a Pause function?
- int x;
- cin >> x;
- }
- iTunes::iTunes()
- {
- name = SetName("(undefined)");
- artist = SetArtist("(undefined)");
- bitrate = SetBitrate(62);
- total_time = SetTotalTime(1000);
- }
- iTunes::iTunes(string newName, string newArtist, int newBitrate, int newTotalTime)
- {
- if (!SetName(newName))
- name = DEFAULT_STRING;
- if (!SetArtist(newArtist))
- artist = DEFAULT_STRING;
- if (!SetBitrate(newBitrate))
- bitrate = DEFAULT_BITRATE;
- if (!SetTotalTime(newTotalTime))
- total_time = DEFAULT_PLAY_TIME;
- }
- bool iTunes::SetName(string theName)
- {
- if (theName.length() < MIN_STR_LENGTH || theName.length() > MAX_STR_LENGTH)
- return false;
- name = theName;
- return true;
- }
- bool iTunes::SetArtist(string theArtist)
- {
- 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;
- theTotalTime = theTotalTime/MIN_PLAY_TIME;
- 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;
- }
- string iTunes::ToString()
- {
- }
- void iTunes::Display()
- {
- cout << "Song Name = " << name << "\nArtist = " << artist << "\nBitrate = "
- << bitrate << "\nTotal Time = " << total_time << " seconds" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement