⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ts.cpp

📁 小的图书管理
💻 CPP
字号:
#include<iostream.h>
#include<string.h>
class Book
{public:
static void Borrow(Book*head);
static void Store(Book*head);
static void Creat(Book*&head,Book*&p);
static void Display(Book*head);
static int Total_number();
static int total_number;
Book*next;
private:
char name[20];
float price;
int number;
int number1;
};
int Book::total_number=0;
void Book::Borrow(Book*head)
{int i=1;
char s[20];
if(head==NULL)cout<<"图书馆尚未有存书!"<<endl;
else {cout<<"请输入要借的书名:";
	cin>>s;
	while(head)
{if(strcmp(head->name,s)==0)
{if(head->number>0)
{cout<<"借书成功!"<<endl;
head->number--;
Book::total_number--;
cout<<"当前存书数量为:"<<head->number<<"本"<<endl;
i=0;
}
else {cout<<"书已借完!"<<endl;i=0;}
break;
}
head=head->next;
}
if(i)cout<<"图书馆并无此种书!"<<endl;
}
}
void Book::Store(Book*head)
{int i=1;
char s[20];
if(head==NULL)cout<<"图书馆并无书借出!"<<endl;
else {cout<<"请输入要还的书名:";
	cin>>s;
	while(head)
{if(strcmp(head->name,s)==0)
{if(head->number<head->number1)
{cout<<"还书成功!"<<endl;
head->number++;
Book::total_number++;
cout<<"当前存书数量为:"<<head->number<<"本"<<endl;
i=0;
}
else {cout<<"此种书并无借出!"<<endl;i=0;}
break;
}
head=head->next;
}
if(i)cout<<"图书馆并无此种书!"<<endl;
}
}
void Book::Display(Book*head)
{if(head==NULL)cout<<"图书馆尚未有存书!"<<endl;
else {cout<<"图书馆现有存书:"<<endl<<"书名"<<'\t'<<"价格"<<'\t'<<"数量"<<endl;
while(head)
{cout<<head->name<<'\t'<<head->price<<'\t'<<head->number<<endl;
head=head->next;
}
cout<<"总存书数量为:"<<Book::Total_number()<<endl;
}
}
int Book::Total_number()
{return total_number;
}
void Book::Creat(Book*&head,Book*&p)
{Book*s;
s=new Book;
cout<<"请输入书名、价格和数量:"<<endl;
cin>>s->name>>s->price >>s->number;
s->number1 =s->number ;
Book::total_number+=s->number ;
if(head==NULL)head=p=s;
else p->next=s;
p=s;
p->next=NULL;
cout<<"创建成功!"<<endl;
}
void main()
{Book*head,*p;
head=p=NULL;
char c;
char s[20];
do
{cout<<"请输入所要进行的操作:0.退出;1.创建新图书;2.显示图书情况;3.借阅图书;4.归还图书"<<endl;
cin>>c;
switch(c)
{case '0':break;
case '1':Book::Creat(head,p);break;
case '2':Book::Display(head);break;
case '3':Book::Borrow(head);break;
case '4':Book::Store(head);break;
default:cout<<"输入错误!"<<endl;break;
}
cout<<"还要继续吗?Y/N"<<endl;
cin>>c;
}while(c=='Y');
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -