这是一个简单的继承的程序,能帮我调试一下程序吗,谢谢拉.(本人分数不多了,所以只能给10分)
#include<iostream>
#include<cstring>
using namespace std;
class cd
{
private:
char performers[50];
char label[20];
int selections;
double playtime;//10
public:
cd(char *sl,char *s2,int n,double x);
cd(const cd&d);
cd();
virtual ~cd(){};
virtual void report()const;
virtual cd&operator=(const cd&d);
};//18
class classic:public cd
{
private:
char zuopin[50];
public:
classic(char *s1,char *s2,char *s3,int n,double x);
classic(const classic&d);
classic();
virtual ~classic();
virtual void peport()const;
virtual classic&operator=(const classic&d);
};
cd::cd(char *s1,char *s2,int n,double x)
{
strncpy(performers,s1,49);//33
strncpy(label,s2,19);
selections=n;
playtime=x;
}
void cd::report()const//38
{ cout<<"performers="<<performers<<"\n";
cout<<"label="<<label<<"\n";
cout<<"selections="<<selections<<"\n";
cout<<"playtime"<<playtime<<"\n";}
cd&cd::operator=(const cd&d)
{
if(this==&d)
return *this;
delete []performers;//47
performers=new char[51];
strcpy(performers,d.performers);
delete []label;
label[]=new char[51];
strcpy(label,d.label);
selections=d.selections;
playtime=d.playtime;
return *this;
}
classic::classic(char *s1,char *s2,char *s3,int n,double x):cd(s1,s2,n,x)
{ strncpy(zuopin,s3,49);//58
} //59
void classic::report()const
{ cout<<"performers="<<s1<<"\n";
cout<<"label="<<s2<<"\n";
cout<<"zuopin="<<s3<<"\n"
cout<<"selections="<<n<<"\n";
cout<<"playtime"<<x<<"\n";}
classic&classic::operator=(const classic&d)
{if (this==&d)
return *this;
delete []performers;
performers=new char[51];
strcpy(performers,d.performers);
delete []label;
label=new char[51];//73
strcpy(label,d.label);
delete []zuopin;
zuopin=new char[51];
strcpy(zuopin,d.zuopin);
selections=d.selections;
playtime=d.playtime;
return *this;
}
void bravo(const cd&disk);//82
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 *pcd=&c1;
cout<<"using obhect directly:\n";
c1.report();
c2.report();
cout<<"using type cd * pointer to objects:\n";
pcd->report();
pcd=&c2;
pcd->report();
cout<<"calling a function with a cd reference argument:\n";
bravo(c1);
bravo(c2);
cout<<"testing assignment:";
classic copy;//98
copy=c2;
copy.report();
return 0;
}
void bravo (const cd&disk)
{disk.report();}