#include<iostream.h>
#define N 20
#include<string.h>
class object
{
char name[N];
int no;
public:
object(char na[N],int num);
};
class Book: public object
{
char author[20];
public:
Book(char na[N],int num,char zuozhe[N]);
Book();
void setBook(char na[N],int num,char zuozhe[N]);
};
object::object(char na[N],int num)
{
strcpy(name,na);
no=num;
}
Book::Book(char na[N],int num,char zuozhe[N]):object(na[N],num)
{
strcpy(author,zuozhe);
}
class Reader:public object
{
public:
Reader(char na[N],int num):object(na[N],num)
{
cout<<"读者: "<<name[N]<<"("<<no<<")"<<endl;
cout<<"所借图书:"<<endl;
}
Reader();
void setReader(char na[N],int num)
{
strcpy(object::name,na);object::no=num;
cout<<"读者: "<<object::name<<"("<<object::no<<")"<<endl;
cout<<"所借图书:"<<endl;
}
void rentBook(Book &a)
{
static int n=1;
cout<<" "<<n<<". ";
n++;
cout<<a.name<<"("<<a.no<<")"<<endl;
}
};
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);
}