Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me solve this, Write Album's PrintSongsShorterThan() member function to print all the songs from the album whose duration is shorter than the value

Please help me solve this,

"Write Album's PrintSongsShorterThan() member function to print all the songs from the album whose duration is shorter than the value of the parameter songDuration. Use Song's PrintSong() member function to print a song."

#include #include #include using namespace std;

class Song { public: void SetDurationAndName(int songDuration, string songName) { duration = songDuration; name = songName; } void PrintSong() const { cout << duration << " - " << name << endl; } int GetDuration() const { return duration; } string GetName() const { return name; }

private: int duration; string name; };

class Album { public: void SetName(string albumName) { name = albumName; } void InputSongs(); void PrintName() const { cout << name << endl; } void PrintSongsShorterThan(int songDuration) const;

private: string name; vector albumSongs; };

void Album::InputSongs() { Song currSong; int currDuration; string currName;

cin >> currDuration; while (currDuration >= 0) { getline(cin, currName); currSong.SetDurationAndName(currDuration, currName); albumSongs.push_back(currSong); cin >> currDuration; } }

void Album::PrintSongsShorterThan(int songDuration) const { unsigned int i; Song currSong;

cout << "Songs shorter than " << songDuration << " seconds:" << endl;

/* Your code goes here */

}

int main() { Album musicAlbum; string albumName;

getline(cin, albumName); musicAlbum.SetName(albumName); musicAlbum.InputSongs(); musicAlbum.PrintName(); musicAlbum.PrintSongsShorterThan(180);

return 0; }

#include #include #include using namespace std;

class Song { public: void SetDurationAndName(int songDuration, string songName) { duration = songDuration; name = songName; } void PrintSong() const { cout << duration << " - " << name << endl; } int GetDuration() const { return duration; } string GetName() const { return name; }

private: int duration; string name; };

class Album { public: void SetName(string albumName) { name = albumName; } void InputSongs(); void PrintName() const { cout << name << endl; } void PrintSongsShorterThan(int songDuration) const;

private: string name; vector albumSongs; };

void Album::InputSongs() { Song currSong; int currDuration; string currName;

cin >> currDuration; while (currDuration >= 0) { getline(cin, currName); currSong.SetDurationAndName(currDuration, currName); albumSongs.push_back(currSong); cin >> currDuration; } }

void Album::PrintSongsShorterThan(int songDuration) const { unsigned int i; Song currSong;

cout << "Songs shorter than " << songDuration << " seconds:" << endl;

for (i = 0; i < albumSongs.size(); ++i) { if (albumSongs[i].GetDuration() > songDuration) { albumSongs[i].PrintSong(); } }/* Your code goes here */

}

int main() { Album musicAlbum; string albumName;

getline(cin, albumName); musicAlbum.SetName(albumName); musicAlbum.InputSongs(); musicAlbum.PrintName(); musicAlbum.PrintSongsShorterThan(180);

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Fundamentals Concepts, Drivers & Techniques

Authors: Thomas Erl, Wajid Khattak, Paul Buhler

1st Edition

0134291204, 9780134291208

More Books

Students also viewed these Databases questions