1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
posledela
3 years ago
9

Write Album's PrintSongsShorterThan() to print all the songs from the album shorter than the value of the parameter songDuration

. Use Song's PrintSong() to print the songs.
#include
#include
#include
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 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 */
}
int main() {
Album musicAlbum;
string albumName;
getline(cin, albumName);
musicAlbum.SetName(albumName);
musicAlbum.InputSongs();
musicAlbum.PrintName();
musicAlbum.PrintSongsShorterThan(210);
return 0;
}

Computers and Technology
1 answer:
Romashka-Z-Leto [24]3 years ago
3 0

Answer:

Here is the function PrintSongsShorterThan() which prints all the songs from the album shorter than the value of the parameter songDuration.

void Album::PrintSongsShorterThan(int songDuration) const {

unsigned int i;

Song currSong;  

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

for(int i=0; i<albumSongs.size(); i++){  

currSong = albumSongs.at(i);  

if(currSong.GetDuration()<songDuration){  

currSong.PrintSong();     } } }

Explanation:

I will explain the working of the for loop in the above function.

The loop has a variable i that is initialized to 0. The loop continues to execute until the value of i exceeds the albumSongs vector size. The albumSongs is a Song type vector and vector works just like a dynamic array to store sequences.

At each iteration the for loop checks if the value of i is less than the size of albumSongs. If it is true then the statement inside the loop body execute. The at() is a vector function that is used to return a reference to the element at i-th position in the albumSongs.  So the album song at the i-th index of albumSongs is assigned to the currSong. This currSong works as an instance. Next the if condition checks if that album song's duration is less than the specified value of songDuration. Here the method GetDuration() is used to return the value of duration of the song. If this condition evaluates to true then the printSong method is called using currSong object. The printSong() method has a statement cout << name << " - " << duration << endl;  which prints/displays the name of the song with its duration.

If you see the main() function statement: musicAlbum.PrintSongsShorterThan(210);

The musicAlbum is the Album object to access the PrintSongsShorterThan(210) The value passed to this method is 210 which means this is the value of the songDuration.

As we know that the parameter of PrintSongsShorterThan method is songDuration. So the duration of each song in albumSongs vector is checked by this function and if the song duration is less than 210 then the name of the song along with its duration is displayed on the output screen.

For example if the album name is Anonymous and the songs name along with their duration are:

ABC 400

XYZ 123

CDE 300

GHI 200

KLM 100

Then the above program displays the following output when the user types "quit" after entering the above information.

Anonymous                                                                              

Songs shorter than 210 seconds:                                                                        

XYZ - 123                                                                                                              

GHI - 200                                                                                                              

KLM - 100

Notice that the song name ABC and CDE are not displayed because they exceed the songDuration i.e. 210.

The output is attached.

You might be interested in
All about wide area network<br>​
andreev551 [17]

Answer:

a wide area network is also known as (WAN) it is a large information that has been tied to more than a single location you can understand by the diagram shown you can think of it as a network sharing information around the world

6 0
3 years ago
Situation 1: Mang Castor wanted to create a simple nutcracker Christmas tree
Papessa [141]

56856546856754578247

6 0
3 years ago
Coordinate with
Lunna [17]

Answer:

First blank: producer

Second blank: Hairdressers

5 0
3 years ago
To provide a good sealing joint between the cylinder head and exhaust manifold, apply a sealant to the machined surfaces.
jeka94

Answer:

It's a true statement.

7 0
3 years ago
Read 2 more answers
In the range E7:E11, apply the Currency number format with zero decimal places and $ as the symbol.
lisabon 2012 [21]

Answer:

bt wheres the data

Explanation:

6 0
3 years ago
Other questions:
  • Nathan wants to make the quotation stand out further. Which order of steps does he need to follow to do this task?
    5·2 answers
  • Which of the following lines of distribution best describes the diagram?
    9·2 answers
  • Roblox published a series of videos to help their audience use their creation engine, what are they called?​
    9·2 answers
  • What is the name for the warmth or coolness of white light?
    10·1 answer
  • What is TLB for? Why TLB? Given the following number, what is theeffective memory access time?
    11·1 answer
  • The ____ area on the status bar includes six commands as well as the result of the associated calculation on the right side of t
    5·1 answer
  • Write a Unix (Linux) find-like command (myFind) in Python3 where the function will return the full paths of all the files contai
    9·1 answer
  • Which of these tax forms reports an employee's yearly social security tax withheld
    11·2 answers
  • Please help i have 15 mins
    5·1 answer
  • Hello guys where's bios chip in this motherboard ​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!