Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions

Question

please dont use chat gpt or other AI 9 0 5 .

Answered: 1 week ago