📄 class.cpp
字号:
#include "class.h"
#include <string.h>
#include <iostream.h>
Item::Item()
{
strcpy(Title,"");
strcpy(Author,"");
strcpy(IndexCode,"");
Code = 0;
Next = NULL;
}
Item::Item(Item & it)
{
strcpy(Author,it.Author);
strcpy(Title,it.Title);
strcpy(IndexCode,it.IndexCode);
Code = it.Code;
}
void Item::SetTitle(char *t1)
{
strcpy(Title, t1);
}
void Item::SetAuthor(char *t1)
{
strcpy(Author, t1);
}
void Item::SetIndexCode(char *t1)
{
strcpy(IndexCode, t1);
}
void Item::SetCode(long t)
{
Code = t;
}
void Item::Show()
{
cout<<Title<<'\t'<<Author<<'\t'<<IndexCode<<'\t'<<Code<<'\n';
}
Reader::Reader()
{
strcpy(Name,"");
strcpy(Position,"");
Counter = 0;
Age = 0;
Code = 0;
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()
{
Item * p = items;
if(p==NULL) { cout<<"您未借书!";return;}
while(p){
p->Show();
p = p->Next;
}
}
void Reader::Show(){
cout<<Name<<'\t'<<Position<<'\t'<<Age<<'\t'<<Code<<endl;
}
void Reader::AddBook(Item it)
{
Item * p = NULL;
p = new Item; // 创建一个新结点
if(p){
*p = it;
p->Next = items;//插入表头
items = p;
Counter++;
}
else cout<<"申请存储空间失败!";
return;
}
void Reader::DelBook(Item it)
{
Item * 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;
}
void Manager::Show()
{
cout<<Name<<'\t'<<Age<<'\t'<<Code<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -