Answer:
kindly check explainations for code
Explanation:
Check below for program code.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Song
{
public:
void SetNameAndDuration(string songName, int songDuration)
{
name = songName;
duration = songDuration;
}
void PrintSong() const
{
cout << name << " - " << duration << endl;
}
string GetName() const { return name; }
int GetDuration() const { return duration; }
private:
string name;
int duration;
};
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<Song> albumSongs;
};
void Album::InputSongs()
{
Song currSong;
string currName;
int currDuration;
cin >> currName;
while (currName != "quit")
{
cin >> currDuration;
currSong.SetNameAndDuration(currName, currDuration);
albumSongs.push_back(currSong);
cin >> currName;
}
}
void Album::PrintSongsShorterThan(int songDuration) const
{
unsigned int i;
Song currSong;
cout << "Songs shorter than " << songDuration << " seconds:" << endl;
/* Your code goes here */
for(int i=0; i<albumSongs.size(); i++){
currSong = albumSongs.at(i);
if(currSong.GetDuration()<songDuration){
currSong.PrintSong();
}
}
}
int main()
{
Album musicAlbum;
string albumName;
getline(cin, albumName);
musicAlbum.SetName(albumName);
musicAlbum.InputSongs();
musicAlbum.PrintName();
musicAlbum.PrintSongsShorterThan(210);
return 0;
}