📄 class.cpp
字号:
#include "class.h"
#include <string.h>
#include <iostream.h>
Book::Book()
{
strcpy(Title,"");
Code = 0;
Next = NULL;
}
Book::Book(char *title,long code)
{
strcpy(Title,title);
Code = code;
Next = NULL;
}
void Book::Show()
{
cout<<"书籍:\t"<<Title<<'\t'<<Code<<endl;
}
Item::Item():Book()
{
strcpy(Author,"");
strcpy(IndexCode,"");
Type = 0;
}
Item::Item(char *author,char *title,char *index,int code):Book(title,code)
{
strcpy(Author,author);
strcpy(IndexCode,index);
Type = 0;
}
Item::Item(Item & it)
{
strcpy(Author,it.Author);
strcpy(Title,it.Title);
strcpy(IndexCode,it.IndexCode);
Code = it.Code;
Type = it.Type;
}
void Item::SetAuthor(char *t1)
{
strcpy(Author, t1);
}
void Item::SetIndexCode(char *t1)
{
strcpy(IndexCode, t1);
}
void Item::Show()
{
cout<<"书:\t"<<Title<<'\t'<<Author<<'\t'<<IndexCode<<'\t'<<Code<<'\n';
}
Magazine::Magazine(char *title,int vol,LANG lang,int code):Book(title,code)
{
Volume = vol;
Lang = lang;
Type = 1;
}
Magazine::Magazine(Magazine & mz){
strcpy(Title,mz.Title);
Volume = mz.Volume;
Lang = mz.Lang;
Code = mz.Code;
Type = 1;
}
void Magazine::Show()
{
cout<<"杂志:\t"<<Title<<'\t'<<"卷号"<<Volume<<'\t'<<((Lang==1)?"Chinese":"English")<<'\t'<<Code<<'\n';
}
Reader::Reader()
{
strcpy(Name,"");
strcpy(Position,"");
Counter = 0;
Age = 0;
Code = 0;
items = NULL;
}
Reader::Reader(char *name,char *posi,int age,int code)
{
strcpy(Name,name);
strcpy(Position,posi);
Counter = 0;
Age = age;
Code = code;
items = NULL;
}
/*
Reader::Reader(Reader & rd)
{
/* strcpy(Name,rd.Name);
strcpy(Position,rd.Position);
Counter = 0;
Age = rd.Age;
Code = rd.Code;
Item *p = rd.items,*q;
while(p)
{
q = new Item;
*q = *p;
if(Counter==0)items = q;
p = p->Next;
Counter++;
}
}*/
Reader::~Reader()
{
}
void Reader::SetName(char *t)
{
strcpy(Name,t);
}
void Reader::SetPosition(char *t)
{
strcpy(Position,t);
}
void Reader::SetAge(int t)
{
Age = t;
}
void Reader::SetCode(long t)
{
Code = t;
}
void Reader::ShowBooks()
{
Book* p = items;
if(p==NULL) { cout<<"您未借书!";return;}
while(p){
p->Show();
p = p->Next;
}
}
void Reader::Show(){
cout<<"读者:\t"<<Name<<'\t'<<Position<<'\t'<<Age<<'\t'<<Code<<endl;
}
/*
void Reader::AddBook(Book *p)
{
/* if(bk.GetType()){
p = new Magazine; // 创建一个新结点
if(p){
*p = bk;
p->Next = items;//插入表头
items = p;
Counter++;
}
else cout<<"申请存储空间失败!";
}
else {
p = new Item;
if(p){
*p = bk;
p->Next = items;//插入表头
items = p;
Counter++;
}
else cout<<"申请存储空间失败!";
}
p->Next = items;//插入表头
items = p;
return;
}*/
void Reader::AddBook(Magazine it)
{
Magazine *p;
p = new Magazine; // 创建一个新结点
if(p){
*p = it;
p->Next = items;//插入表头
items = p;
Counter++;
}
}
void Reader::AddBook(Item it)
{
Item *p;
p = new Item; // 创建一个新结点
if(p){
*p = it;
p->Next = items;//插入表头
items = p;
Counter++;
}
}
void Reader::DelBook(Book it)
{
Book * p = items,*q;
while(p->GetCode()!=it.GetCode()&&p!=NULL){
q = p;
p = p->Next;
}
if(p->GetCode()==it.GetCode())
{
if(p == items) items = p->Next;
else q->Next = p->Next;
delete p;
}
return;
}
Loan::Loan(Loan & l){
Code = l.Code;
if(Code) mag = l.mag;
else item = l.item;
reader = l.reader;
manager = l.manager;
}
void Loan::Show(){
if(Type)mag.Show();
else item.Show();
reader.Show();
manager.Show();
}
Manager::Manager(char* name,int age,int code)
{
strcpy(Name,name);
Age = age;
Code = code;
}
void Manager::Show()
{
cout<<"管理员:\t"<<Name<<'\t'<<Age<<'\t'<<Code<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -