Question: FIX THIS CODE PLEASE URGENT SEGMENTATION ERROR #include #include using namespace std; class Cd { private: const char* performers; const char* label; int selections; double

FIX THIS CODE PLEASE

URGENT

SEGMENTATION ERROR

#include  #include using namespace std; class Cd { private: const char* performers; const char* label; int selections; double playtime; public: Cd() { performers = new char[8]; label = new char[8]; performers="Unknown"; label="Unknown"; selections=0; playtime=0.0; } Cd(const char* performers,const char* label,int selections,double playtime) { this->performers = new char[strlen(performers)+1]; this->performers = performers; this->label = new char[strlen(label)+1]; this->label = label; this->selections = selections; this->playtime = playtime; } virtual void Report() { cout << "Performer(s):" << performers << endl; cout << "Label:" << label << endl; cout << "Number of selections:" << selections << endl; cout << "Play time:" << playtime << endl; } ~Cd() { delete[] performers; delete[] label; } }; class Classic:public Cd { private: const char* primaryWork; public: Classic() { primaryWork = new char[8]; primaryWork="Unknown"; } Classic(const char* primaryWork,const char* performers,const char* label,int selections,double playtime):Cd(performers,label,selections,playtime) { this->primaryWork = new char[strlen(primaryWork)+1]; this->primaryWork = primaryWork; } virtual void Report() { cout << "Primary Work:" << primaryWork << endl; Cd::Report(); } ~Classic() { delete[] primaryWork; } }; int main() { Cd c1("Beatles","Capitol",14,35.5); Classic c2= Classic("Piano sonata in B flat,Fantasia in C","Alfred Brendel","Philips",2,57.17); Cd* obj1 = &c1; cout << " Using object directly: "; cout << "*********************************" << endl; c1.Report(); c2.Report(); cout << " Using type cd* pointer to objects: "; cout << "*********************************" << endl; obj1->Report(); obj1 = &c2; obj1->Report(); return 0; }

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 Programming Questions!