图书管理系统代码。要注释
#include<iostream.h>#include<string.h>
#include<iomanip.h>
class book
{
private:
static int n;
char author[30];
char title[30];
char number[30];
int stock;
int out;
char reader[30];
char id[30];
public:
book();
book(char a[],char b[],char c[],int d[],int e[],char f[],char g[]);
void setbook();
void outcom();
friend class group;
};
class group
{
private:
book *a;
int len;
public:
group(int s)
{
len=s;a=new book[len];book::book();
}
~group(){ delete []a;}
void add();
void del();
void find();
void get();
void back();
void inquire();
int menu();
};
int book::n=0;
book::book()
{
strcpy(author,"-");
strcpy(title,"-");
strcpy(number,"-");
strcpy(reader,"-");
strcpy(id,"-");
}
book::book(char a[],char b[],char c[],int d[],int e[],char f[],char g[])
{
strcpy(author,a);
strcpy(title,b);
strcpy(number,c);
strcpy(reader,f);
strcpy(id,g);
n++;
}
void book::setbook()
{
cout<<"请输入书籍数据"<<endl;
cout<<"作者"<<setw(8)<<"书目"<<setw(15)<<"书目编号"<<setw(12)<<"库存册数"<<setw(12)<<"已借出数"<<setw(12)<<"借走的人"<<setw(12)<<"登录号"<<endl;
cin>>author>>title>>number>>stock>>out>>reader>>id;
cout<<endl;
n++;
}
void book::outcom()
{
if(strlen(number)!=0)
cout<<author<<setw(10)<<title<<setw(12)<<number<<setw(12)<<stock<<setw(12)<<out<<setw(11)<<reader<<setw(12)<<id<<endl;
}
void group::add()
{
if(book::n!=0)
{
for(int i=book::n-1;i<len;i++)
{
a[i+1].book::setbook();
cout<<"还要继续添加吗?确定(y)/取消(n):";
char c;
cin>>c;
if(c=='y') continue;
else if(c=='n')
{
cout<<"退出添加!"<<endl; return;
}
else
{
cout<<"选择错误,默认退出添加!"<<endl;
return;
}
}
}
else
{
for(int i=0;i<len;i++)
{
a[i].book::setbook();
cout<<"还要继续添加吗?确定(y)/取消(n):";
char c;
cin>>c;
if(c=='y') continue;
else if(c=='n')
{
cout<<"退出添加!"<<endl; return;
}
else
{
cout<<"选择错误,默认退出添加!"<<endl;
return;
}
}
}
}
void group::del()
{
int i,j;
char c;
char n[15];
cout<<"请输入登录号"<<endl;
cin>>n;
for( i=0;i<book::n;i++)
if(!strcmp(a[i].id,n))
{
j=i;
cout<<"将要删除该书目:"<<endl;
cout<<"作者"<<setw(8)<<"书目"<<setw(15)<<"书目编号"<<setw(12)<<"库存册数"<<setw(12)<<"已借出数"<<setw(12)<<"借走的人"<<setw(12)<<"登录号"<<endl;
a[j].book::outcom();
cout<<"确定要删除吗?确定(y)/取消(n)";
cin>>c;
if(c=='y')
{
for( i=j;i<book::n-1;i++)
a[i]=a[i+1];
cout<<"已删除该书目信息:"<<endl;
book::n--;return;
}
}
else if(c=='y'||c=='Y')
{
cout<<"取消删除 !"<<endl;
return;
}
cout<<"你要删除的书不存在!"<<endl;
return;
}
void group::find()
{
char n[15];
int i,j;
cout<<"请输入登录号"<<endl;
cin>>n;
for(i=0;i<book::n;i++)
if(!strcmp(a[i].id,n))
{
j=i;
cout<<"你要查找的书d信息:"<<endl;
cout<<"作者"<<setw(8)<<"书目"<<setw(15)<<"书目编号"<<setw(12)<<"库存册数"<<setw(12)<<"已借出数"<<setw(12)<<"借走的人"<<setw(12)<<"登录号"<<endl;
a[j].book::outcom();
return;
}
else
{
cout<<"输入错误!"<<endl;
break;
}
}
void group::get()
{
char s[40];
int i;
cout<<"请输入你要借的书的登录号:"<<endl;
cin>>s;
{
for(i=0;i<book::n;i++)
if(!strcmp(a[i].id,s))
{
cout<<"你要借书的信息:"<<endl;
cout<<"作者"<<setw(8)<<"书目"<<setw(15)<<"书目编号"<<setw(12)<<"库存册数"<<setw(12)<<"已借出数"<<setw(12)<<"借走的人"<<setw(12)<<"登录号"<<endl;
a[i].book::outcom();
cout<<"该书可借阅,是否借阅确定(y)/取消(n),请输入:"<<endl;
char c;
cin>>c;
if(c=='y')
{
strcpy(a[i].id,s);
return;
}
else
{
cout<<"取消借阅!"<<endl;
return;
}
}
}
}
void group::back()
{
char n[15];
int i;
cout<<"请输入你要还书的登录号:";
cin>>n;
{
for(i=0;i<book::n;i++)
if(!strcmp(a[i].id,n))
{
cout<<"你要还d书的信息:"<<endl;
cout<<"作者"<<setw(8)<<"书目"<<setw(15)<<"书目编号"<<setw(12)<<"库存册数"<<setw(12)<<"已借出数"<<setw(12)<<"借走的人"<<setw(12)<<"登录号"<<endl;
a[i].book::outcom();
cout<<"还书成功!"<<endl;
return;
}
}
}
void group::inquire()
{
char n[15];
cout<<"请输入书目登录号"<<endl;
cin>>n;
cout<<"借走的人是:"<<a->reader<<endl;
return;
}
int group::menu()
{
int i;
cout<<" ***图书管理系统***~"<<endl;
cout<<" 1.添加新书"<<endl;
cout<<" 2.删除旧书"<<endl;
cout<<" 3.查找书目"<<endl;
cout<<" 4.借书"<<endl;
cout<<" 5.还书"<<endl;
cout<<" 6.查询借书人"<<endl;
for(;;)
{
cin>>i;
if(i<1||i>10)
cout<<"输入错误,请重试,并选择(1~6)!:"<<endl;
else break;
}
return i;
}
void main()
{
char c='y';
int n;
cout<<"请输入藏书数目---n"<<endl;
cin>>n;
group a(n);
while(c=='y')
{
switch(a.menu())
{
case 1: a.add();break;
case 2: a.del();break;
case 3: a.find();break;
case 4: a.get();break;
case 5: a.back();break;
case 6: a.inquire();break;
}
}
}