Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.                            
  5. class iTunes
  6. {
  7. private:
  8.    string name;
  9.    string artist;
  10.    int bitrate;
  11.    int total_time;
  12. public:
  13.    static const int MIN_BITRATE = 64;
  14.    static const int MAX_BITRATE = 705;
  15.    static const unsigned int MIN_STR_LENGTH = 1;
  16.    static const unsigned int MAX_STR_LENGTH = 80;
  17.    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
  18.    static const int MIN_PLAY_TIME = 1000;
  19.    static const int MAX_PLAY_TIME = 1000*60*60;
  20.    static const int DEFAULT_PLAY_TIME = 1000;
  21.    static const string DEFAULT_STRING;
  22.  
  23.    // CONSTRUCTORS
  24.    iTunes();
  25.    iTunes(string newName, string newArtist, int newBitrate, int newTotalTime);
  26.  
  27.    // MUTATORS & ACCESSORS & METHODS
  28.    string GetName();
  29.    string GetArtist();
  30.    int GetBitrate();
  31.    int GetTotalTime();
  32.    bool SetName(string theName);
  33.    bool SetArtist(string theArtist);
  34.    bool SetBitrate(int theBitrate);
  35.    bool SetTotalTime(int theTotalTime);
  36.    string ToString();
  37.    void Display();
  38. };
  39.  
  40. const string iTunes::DEFAULT_STRING = "(undefined)";
  41.  
  42.  
  43. int main()
  44. {
  45.    iTunes song1("Prelude", "Bonobo", 3200, 780000000),
  46.           song2("Dolphin", "Lone", 256, 62000),
  47.           song3("I Thought It Was You","Onur Engin",128, 92200),
  48.           song4("Leftside Drive", "Boards of Canada", 320, 176200);
  49.  
  50.  
  51. // Mutator tests
  52. if ( !song2.SetBitrate(999))
  53.    cout << "Unable to set Bitrate to 999." << endl;
  54. else
  55.    cout << "Bitrate set to 999." << endl;
  56. if ( !song4.SetTotalTime(0))
  57.    cout << "Unable to set Total Time to 0." << endl;
  58. else
  59.    cout << "Total Time set to 0." << endl;
  60. if ( !song1.SetArtist(""))
  61.    cout << "Unable to set Artist. Invalid string length." << endl;
  62. else
  63.    cout << "Artist name is set." << endl;
  64.  
  65.  
  66.  
  67. // 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?
  68. int x;
  69. cin >> x;
  70.  
  71.  
  72. }
  73.  
  74. iTunes::iTunes()
  75. {
  76.    name = SetName("(undefined)");
  77.    artist = SetArtist("(undefined)");
  78.    bitrate = SetBitrate(62);
  79.    total_time = SetTotalTime(1000);
  80. }
  81.  
  82. iTunes::iTunes(string newName, string newArtist, int newBitrate, int newTotalTime)
  83. {
  84.    if (!SetName(newName))
  85.       name = DEFAULT_STRING;
  86.    if (!SetArtist(newArtist))
  87.       artist = DEFAULT_STRING;
  88.    if (!SetBitrate(newBitrate))
  89.       bitrate = DEFAULT_BITRATE;
  90.    if (!SetTotalTime(newTotalTime))
  91.       total_time = DEFAULT_PLAY_TIME;
  92. }
  93.  
  94. bool iTunes::SetName(string theName)                                  
  95. {
  96.    if (theName.length() < MIN_STR_LENGTH || theName.length() > MAX_STR_LENGTH)
  97.       return false;
  98.    name = theName;
  99.    return true;
  100. }
  101.  
  102. bool iTunes::SetArtist(string theArtist)
  103. {
  104.    if (theArtist.length() < MIN_STR_LENGTH || theArtist.length() > MAX_STR_LENGTH)
  105.       return false;
  106.    artist = theArtist;
  107.    return true;
  108. }
  109.  
  110. bool iTunes::SetBitrate(int theBitrate)
  111. {
  112.    if (theBitrate < MIN_BITRATE || theBitrate > MAX_BITRATE)
  113.       return false;
  114.    bitrate = theBitrate;
  115.    return true;
  116. }
  117.  
  118. bool iTunes::SetTotalTime(int theTotalTime)
  119. {
  120.    if (theTotalTime < MIN_PLAY_TIME || theTotalTime > MAX_PLAY_TIME)
  121.       return false;
  122.    theTotalTime = theTotalTime/MIN_PLAY_TIME;
  123.    total_time = theTotalTime;
  124.    return true;
  125. }
  126. string iTunes::GetName()
  127. {
  128.    return name;
  129. }
  130.  
  131. string iTunes::GetArtist()
  132. {
  133.    return artist;
  134. }
  135.  
  136. int iTunes::GetBitrate()
  137. {
  138.    return bitrate;
  139. }
  140.  
  141. int iTunes::GetTotalTime()
  142. {
  143.    return total_time;
  144. }
  145.  
  146. string iTunes::ToString()
  147. {
  148.  
  149. }
  150.  
  151. void iTunes::Display()
  152. {
  153.    cout << "Song Name = " << name << "\nArtist = " << artist << "\nBitrate = "
  154.         << bitrate << "\nTotal Time = " << total_time << " seconds" << endl;
  155.  
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement