13.2类的定义 class Item public Book t ∥书籍类 char Author[20] ∥作者 char Index Code[10] ∥1分类号 public Temo 缺省构造函数 Item(char *author, char *title, char *index int code): Book(title, code)t 众 strcpy( Author, autho); ndexcode≡ index;∥构造函数 m tem it)t ∥拷贝构造函数 strcpy (Title, it Title); Code it Code; strcpy(Author, it. Author); IndexCode= it Index Code; void SetAuthor(char *) void Setlndex Code(char * void Show(t ∥1重定义显示函数 cout<“书名:”<Ttle≤“,作者:”<< Author<< endla
13.2 类的定义 class Item :public Book { // 书籍类 char Author[20]; // 作者 char IndexCode[10]; // 分类号 public: Item(); // 缺省构造函数 Item(char *author, char *title, char *index, int code):Book(title, code) { strcpy(Author, author); IndexCode = index; // 构造函数 Item(Item & it) { // 拷贝构造函数 strcpy(Title, it.Title); Code = it.Code; strcpy(Author, it.Author); IndexCode = it.IndexCode; } void SetAuthor(char *); void SetIndexCode(char *); void Show() { // 重定义显示函数 cout << “书名:” << Title << “, 作者:” << Author << endl; } };
13.2类的定义 class Magazine: public Book{∥杂志类 int volume enum lanG{cH|NESE=1, ENGLISH}Lang;∥语言种类 public: Magazine ( Book i Volume =0; Lang CHINESE; Type =1; 1 Magazine(char title, int vol, LANG lang, int code): Book(titlem code i Volume=vol;Lang=lang;}∥构造函数 MagazineMagazine ma) ∥拷贝构造函数 void SetVolume (int voli Volume vol; y void SetLangint lang)i Lang =(LANG)lang; void show( ∥重定义显示函数 {cout<“杂志名:”< Title<“卷号:”< Volume ≤≤endl;} 读者类要存储所借书。现在图书类一个派生类体系,它们的公共基 类Book提供了统一接口。可定义一个单链表来同时存储读者所借书籍 Item和杂志 Magazine。Book类有一个指向Book类的指针Next, 用来构成箱表
13.2 类的定义 class Magazine: public Book { // 杂志类 int Volume; enum LANG {CHINESE=1, ENGLISH} Lang; // 语言种类 public: Magazine ():Book() { Volume = 0; Lang = CHINESE; Type = 1; } Magazine (char * title, int vol, LANG lang, int code):Book(titlem code) { Volume = vol; Lang = lang; } // 构造函数 Magazine (Magazine & ma); // 拷贝构造函数 void SetVolume (int vol) { Volume = vol; } void SetLang (int lang ) { Lang = (LANG)lang; } void Show ( ) // 重定义显示函数 {cout << “杂志名:”<< Title<< “, 卷号:”<<Volume <<endl;} }; 读者类要存储所借书。现在图书类一个派生类体系,它们的公共基 类Book提供了统一接口。 可定义一个单链表来同时存储读者所借书籍 Item和杂志Magazine 。Book类有一个指向Book类的指针Next, 用来构成链表