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
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 <
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started