Question: C++ constructor and keyword new add a constructor to the Song class that takes no parameters and sets all fields to appropriate default values. Next

C++ constructor and keyword new

add a constructor to the Song class that takes no parameters and sets all fields to appropriate default values.

Next change the provided code in main so that all Song objects are allocated using the keyword new and the constructor you just created.

Finally, after a song is played in main, delete it.

#include using namespace std;

class Song{ string songname; string singer; int time; int sec; int min; public: string play (Song); Song(string songname, string singer, int time); void play(){ cout << "Played \"" << songname <<"\" by " << singer << " for " << min <<":" << sec <songname=songname; this->singer =singer; this->time =time; min= time/60; sec= time-(min*60); }

int main(int argc, char **argv) { Song s1("Black Hole Sun", "SoundGarden", (3*60)+41); Song s2("Nevermind", "Nirvana", (2*60)+56); Song s3("GrandHotel", "Regina Spektor", (3*60)+50);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!