SHARE
TWEET

Music Library: Part 1

a guest Feb 17th, 2017 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Complete the program by:
  3.  * - Prompting the user to enter an album and an undetermined number of songs
  4.  * - Modify the Song class by adding the following properties: track number and writers
  5.  * - Add the following properties to the Album class: release year, artist, label and genre
  6.  * - At the end of the program, all properties of the album should be printed
  7.  */
  8.  
  9.  
  10. #include <iostream>
  11. #include <vector>
  12.  
  13. using namespace std;
  14.  
  15. class Song {
  16.  
  17. public:
  18.     string title;
  19.     int duration;
  20.  
  21.     string durationFormatted() {
  22.         int mins = this->duration / 60;
  23.         int sec = this->duration % 60;
  24.  
  25.         return "" + to_string(mins) + ":" + to_string(sec) + "0";
  26.     }
  27. };
  28.  
  29. class Album {
  30.  
  31. public:
  32.     string name;
  33.     vector<Song> songs;
  34. };
  35.  
  36. int main() {
  37.  
  38.     Song song1;
  39.     Album album1;
  40.     vector<Song> songs;
  41.  
  42.     song1.title = "Often";
  43.     song1.duration = 242; // in seconds
  44.  
  45.     // add a song to the songs collection (vector)
  46.     songs.push_back(song1);
  47.  
  48.     album1.name = "Beauty Behind the Madness";
  49.     album1.songs = songs;
  50.  
  51.     cout << album1.name << endl;
  52.  
  53.     for (Song s : album1.songs) {
  54.         cout << s.title << " " << s.durationFormatted() << endl;
  55.     }
  56.  
  57.     return 0;
  58. }
RAW Paste Data
Top