两个类 想在catalogue类里面包含BOOKRECORD 数组 怎么弄?跪求好人解答
class BookRecord
{
public:
BookRecord(char *id,char *title,char *first,char *last,char *y,int copy)
{
if(id[0]<65||id[0]>90)
{
cout<<"id is illegal"<<endl;
abort();
}
if(y[0]!=1||y[0]!=2)
{
cout<<"year is illegal"<<endl;
abort();
}
copy_number=copy;
book_id=new char[strlen(id)+1];
strcpy_s(book_id,strlen(id)+1,id);
book_title=new char[strlen(title)+1];
strcpy_s(book_title,strlen(title)+1,title);
first_name=new char[strlen(first)+1];
strcpy_s(first_name,strlen(first)+1,first);
last_name=new char[strlen(last)+1];
strcpy_s(last_name,strlen(last)+1,last);
}
char* ReturnId()
{
return book_id;
}
void show_data()
{
cout<<"Book ID: "<<book_id<<endl;
cout<<"Title: "<<book_title<<endl;
cout<<"Author:"<<first_name<<" "<<last_name<<endl;
cout<<"Year published: "<<year<<endl;
cout<<"Total number of copies: "<<copy_number<<endl;
}
~BookRecord()
{
delete []book_id;book_id=NULL;
delete []book_title;book_title=NULL;
delete []first_name;first_name=NULL;
delete []last_name;last_name=NULL;
delete []year;year=NULL;
}
private:
char *book_id;
char *book_title;
char *first_name;
char *last_name;
char *year;
int copy_number;
}
class Catalogue
{
public:
Catalogue(int total)
{
total_record=total;
};
int calculate();
void show_cata()
{
cout<<"the numer of the individual book records is "<<total_record<<endl;
}
private:
int total_record;
BookRecord book[3]=
{
BookRecord(N123,Object-Oriented Programming,Dave,Smith,2009,3),
BookRecord(A251,UML Modelling and Design,Barry,Arthurs,2005,1),
BookRecord(Z001,Practical Guide to STL,John,Johnson,2000,5)
};
}
class BookRecord
{
public:
BookRecord(char *id,char *title,char *first,char *last,char *y,int copy)
{
if(id[0]<65||id[0]>90)
{
cout<<"id is illegal"<<endl;
abort();
}
if(y[0]!=1||y[0]!=2)
{
cout<<"year is illegal"<<endl;
abort();
}
copy_number=copy;
book_id=new char[strlen(id)+1];
strcpy_s(book_id,strlen(id)+1,id);
book_title=new char[strlen(title)+1];
strcpy_s(book_title,strlen(title)+1,title);
first_name=new char[strlen(first)+1];
strcpy_s(first_name,strlen(first)+1,first);
last_name=new char[strlen(last)+1];
strcpy_s(last_name,strlen(last)+1,last);
}
char* ReturnId()
{
return book_id;
}
void show_data()
{
cout<<"Book ID: "<<book_id<<endl;
cout<<"Title: "<<book_title<<endl;
cout<<"Author:"<<first_name<<" "<<last_name<<endl;
cout<<"Year published: "<<year<<endl;
cout<<"Total number of copies: "<<copy_number<<endl;
}
~BookRecord()
{
delete []book_id;book_id=NULL;
delete []book_title;book_title=NULL;
delete []first_name;first_name=NULL;
delete []last_name;last_name=NULL;
delete []year;year=NULL;
}
private:
char *book_id;
char *book_title;
char *first_name;
char *last_name;
char *year;
int copy_number;
}
class Catalogue
{
public:
Catalogue(int total)
{
total_record=total;
};
int calculate();
void show_cata()
{
cout<<"the numer of the individual book records is "<<total_record<<endl;
}
private:
int total_record;
BookRecord book[3]=
{
BookRecord(N123,Object-Oriented Programming,Dave,Smith,2009,3),
BookRecord(A251,UML Modelling and Design,Barry,Arthurs,2005,1),
BookRecord(Z001,Practical Guide to STL,John,Johnson,2000,5)
};
}