#include<iostream.h>
#define N 20
#include<string.h>
class object
{
public:
object(char na[N],int num);
object();
char name[N];
int no;
};
class Book: public object
{
char author[20];
public:
Book(char na[],int num,char zuozhe[]);
Book();
void setBook(char na[N],int num,char zuozhe[N])
{
strcpy(name,na);no=num;strcpy(author,zuozhe);
}
};
object::object() {}
object::object(char na[N],int num)
{
strcpy(name,na);
no=num;
}
Book::Book (): object(){}
Book::Book(char na[N],int num,char zuozhe[N]):object(na,num)
{
strcpy(author,zuozhe);
}
class Reader:public object
{
public:
char *a;
int *b;
void rentBook(Book &c)
{
static int i=1;
strcpy(&a[i],c.name);
b[i]=c.no;
i++;
}
void showBook()
{
int i;
cout<<"读者: "<<object::name<<"("<<no<<")"<<endl;
cout<<"所借图书:"<<endl;
for(i=1;b[i]!=0;i++)
cout<<" "<<i<<"."<<a[i]<<"("<<b[i]<<")"<<endl;
}
Reader(char na[N],int num):object(na,num){}
Reader(){};
void setReader(char na[N],int num)
{
strcpy(object::name,na);object::no=num;
}
};
void main()
{
Book b1("C语言", 1,"潭浩强"),b2("数据结构", 2,"严蔚敏"),b3,b4,b5;
Reader r1("王华",1),r2;
b3.setBook("VB程序设计",3, "成功");
b4.setBook("数据库原理",4, "王瑟");
b5.setBook("计算机导学",5, "张仁");
r2.setReader("李明",2);
r1.rentBook(b1);
r1.rentBook(b3);
r2.rentBook(b2);
r2.rentBook(b4);
r2.rentBook(b5);
r1.showBook();
r2.showBook();
}