c++ 初学者写的图书馆管理系统 多多指教
2016-04-03 13:31
399 查看
#include<iostream>
#include<assert.h>
#include<cstring>
using namespace std;
const int Namelen = 20;
const int Codelen = 7;
const int booknamelen=20;
const int bookpublishlen =20;
const int bookauthorlen=20;
//用户类
class user
{
private:
char Mname[Namelen];
char Mcode[Codelen];
user *next;
public:
user()
{
strcpy_s(Mname, "ab");
strcpy_s(Mcode, "ab");
next = NULL;
};
user(char *name, char *code)
{
strcpy_s(Mname, name);
strcpy_s(Mcode, code);
next = NULL;
}
char*Getname() {return Mname;}
char *Getcode() {return Mcode;}
user*Getnext(){return next;};
class Booklink;
void Borrow();
void Returnback();
void Mysearch();
void Delegte();
void Login();
void Deleteuser();
public:
class usermationnode
{
public:
char bkname[booknamelen];
char bkaut[bookauthorlen];
char bkpub[bookpublishlen];
int amount;
usermationnode *bkmationnext;
usermationnode()
{
amount = 0;
bkmationnext=NULL;
}
};
usermationnode *bkmationnext;
//嵌套类,用户链表结点
public:
class userlink
{
private:
user *Mhead;
public:
userlink()
{
Mhead =new(nothrow) user;
assert( Mhead != NULL);
Mhead ->next =NULL;
}
int Add_user(user us)
{
user*newuser =new(nothrow)user;
assert(newuser != NULL);
strcpy_s(newuser->Mname, us.Mname);
strcpy_s(newuser->Mcode,us.Mcode);
newuser->next =Mhead->next;
Mhead->next = newuser;
return 1;
}
user *Getfirstnode(){return Mhead->next;};
};
void insert(usermationnode &p)
{
(&p)->bkmationnext = bkmationnext;
bkmationnext =(&p);
}
};
/*************************************************************/
//图书类
class Booklink
{
public:
Booklink()
{
mhead = new(nothrow)Node;
assert(mhead != NULL);
mhead->next = NULL;
};
~Booklink()
{
Node *pcur =new(nothrow)Node;
assert(pcur != NULL);
pcur = mhead;
while(pcur != NULL)
{
mhead = mhead->next;
delete pcur;
pcur = mhead;
}
}
void Searchbook();
void Adminsert();
public:
class Node
{
public:
Node()
{
strcpy_s(bkname, "ab");
strcpy_s(bkaut,"ab");
strcpy_s(bkpub,"ab");
amount=0;
next =NULL;
};
Node(char *a, char *b, char *c)
{
strcpy_s(bkname,a);
strcpy_s(bkpub,b);
strcpy_s(bkaut,c);
amount=0;
next =NULL;
}
char bkname[booknamelen];
char bkaut[bookauthorlen];
char bkpub[bookpublishlen];
int amount;
class user b;
Node *next;
};
Node *mhead;
};
Booklink b;
user a;
Booklink::Node *pcurt = new(nothrow)Booklink::Node;
/********删除用户***********/
void user::Deleteuser()
{
void menu();
char str1[Namelen]="ab";
char str2[Codelen]="ab";
cout<<"姓名:";
cin>>str1;
cout<<"密码:";
cin>>str2;
cout<<endl;
user *tep1=new(nothrow)user;
assert(tep1 != NULL);
user *tep2=new(nothrow)user;
assert(tep2 != NULL);
tep1=&a;
for(; tep1->next != NULL; tep1 = tep1->next)
{
if(strcmp(tep1->next->Mname, str1)==0 && strcmp(tep1->next->Mcode, str2)==0)
{
tep2 = tep1->next;
tep1->next =tep1->next->next;
delete tep2;
cout<<endl;
cout<<"删除成功!"<<endl<<endl;
menu();
break;
}
}
}
/*********登录****/
void user::Login()
{
void menu_second();
char str1[Namelen]="ab";
char str2[Codelen]="ab";
cout<<"姓名:";
cin>>str1;
cout<<"密码:";
cin>>str2;
cout<<endl;
user *tep1=new(nothrow)user;
tep1=a.next;
for(; tep1 != NULL; tep1 = tep1->next)
{
if(strcmp(tep1->Mname, str1)==0 && strcmp(tep1->Mcode, str2)==0)
{
cout<<endl;
cout<<"登录成功!"<<endl<<endl;
menu_second();
}
}
if(tep1 == NULL)
{
cout<<"用户名或密码错误!"<<endl;
}
}
/********注册**************/
void user::Delegte()
{
char str1[Namelen]="ab";
char str2[Codelen]="ab";
user *tep=new(nothrow)user;
assert(tep != NULL);
cout<<"姓名:";
cin>>str1;
cout<<"密码:";
cin>>str2;
strcpy_s(tep->Mname,str1);
strcpy_s(tep->Mcode,str2);
tep->next = a.next ;
a.next = tep;
cout<<"注册成功!"<<endl;
}
/********查询我的存书*********/
void user::Mysearch()
{
int tep=0;
usermationnode *p=new(nothrow)usermationnode;
assert(p != NULL);
p = this->bkmationnext;
while(p != NULL)
{
cout<<"书名:"<<p->bkname<<endl;
cout<<"出版社:"<<p->bkpub<<endl;
cout<<"作者:"<<p->bkaut<<endl;
cout<<"数量:"<<p->amount<<endl;
cout<<endl;
tep = 1;
p=p->bkmationnext;
}
if(tep == 0)
{
cout<<"暂时没有借书"<<endl;
}
}
/************查询图书馆存书***************/
void Booklink::Searchbook()
{
char s1bookname[booknamelen]="abc";
cout<<"请输入书名:";
cin>>s1bookname;
cout<<endl;
Node *p=new(nothrow)Node;
assert(p != NULL);
p=mhead->next;
while(p != NULL)
{
if(strcmp(s1bookname, p->bkname)==0)
{
cout<<"书名:"<<p->bkname<<endl;
cout<<"出版社:"<<p->bkpub<<endl;
cout<<"作者:"<<p->bkaut<<endl;
cout<<"数量:"<<p->amount<<endl;
break;
}
p=p->next;
}
if(p == NULL)
{
cout<<endl;
cout<<endl;
cout<<"对不起,暂无此书,请检查输入是否有误!"<<endl;
cout<<endl;
}
}
/*****还书*****/
void user::Returnback()
{
char str1[booknamelen] = "qmj";
cout<<"请输入书名:";
cin>>str1;
pcurt = b.mhead->next;
usermationnode *p =new(nothrow)usermationnode;
assert(p != NULL);
p=this->bkmationnext;
for(;p != NULL; p=p->bkmationnext )
{
if(strcmp(str1,p->bkname) == 0 && p->amount >0)
{
p->amount--;
break;
}
}
if(p == NULL)
{
cout<<"输入有误!"<<endl;
return;
}
pcurt = b.mhead->next;
for(; pcurt != NULL; pcurt =pcurt->next)
{
if(strcmp(pcurt->bkname , str1) == 0)
{
pcurt->amount +=1;
pcurt =b.mhead->next;
cout<<"还书成功!"<<endl;
break;
}
}
}
/***管理员存书*****/
void Booklink::Adminsert()
{
int tepamount;
char s1bookname[booknamelen]="abc";
char s2bookpub[bookpublishlen]="abd";
char s3bookaut[bookauthorlen]="abd";
cout<<"请输入书名:";
cin>>s1bookname;
cout<<"请输入出版社:";
cin>>s2bookpub;
cout<<"请输入作者:";
cin>>s3bookaut;
cout<<"请输入数量:";
cin>>tepamount;
Node *p=new(nothrow)Node;
assert(p != NULL);
p=mhead->next;
while(p != NULL)
{
if(strcmp(s1bookname, p->bkname)==0)
{
p->amount+= tepamount;
break;
}
p=p->next;
}
if(p == NULL)
{
Node *q=new(nothrow)Node;
assert(q != NULL);
q->next = mhead->next;
mhead->next = q;
mhead->next->amount += tepamount;
strcpy_s(mhead->next->bkname, s1bookname);
strcpy_s(mhead->next->bkpub, s2bookpub);
strcpy_s(mhead->next->bkaut,s3bookaut);
}
}
/*******借书****************/
void user :: Borrow()
{
pcurt = b.mhead->next;
cout<<"请输入书名:";
char str[booknamelen]="ab";
cin>>str;
for(; pcurt != NULL; pcurt =pcurt ->next)
{
if(strcmp(str, pcurt ->bkname) == 0)
{
if(pcurt ->amount > 1)
{
pcurt ->amount--;
break;
}
}
}
if(pcurt == NULL)
{
cout<<"无此书!请检查输入是否有误!"<<endl;
return;
}
usermationnode *p = new(nothrow)usermationnode;
assert(p != NULL);
p = this->bkmationnext;
usermationnode *q = new(nothrow)usermationnode;
assert(q != NULL);
strcpy_s(q->bkname, str);
strcpy_s(q->bkpub, pcurt->bkpub);
strcpy_s(q->bkaut, pcurt->bkaut);
q->amount =1;
for(; p !=NULL; p =p->bkmationnext)
{
if(strcmp(str,p->bkname)==0)
{
p->amount++;
pcurt =b.mhead->next;
cout<<"借书成功 !"<<endl;
return ;
}
}
if(p == NULL)
{
insert(*q);
pcurt =b.mhead->next;
cout<<"借书成功 !"<<endl;
return ;
}
}
/*************************************************************************************/
void menu()
{
user :: userlink plist;
int flag=1;
void menu_second();
cout<<"欢迎登录图书馆管理系统"<<endl;
while(flag)
{
cout<<endl;
cout<<"0------退出"<<endl;
cout<<"1------注册"<<endl;
cout<<"2------登录"<<endl;
cout<<"3------返回"<<endl;
cout<<"4------管理员登录"<<endl;
cout<<endl;
cout<<"请选择:"<<endl;
int choice;
cin>>choice;
switch(choice)
{
case 0:
{
return;
}
break;
case 1:
{
a.Delegte();
}
break;
case 2:
{
a.Login();
}
break;
case 3:
{
cout<<"欢迎您下次登录!"<<endl;
}
break;
case 4:
{
cout<<"姓名:";
cin>>(a.Getname());
cout<<"密码:";
cin>>(a.Getcode());
if(strcmp("liwei", a.Getname())==0 &&
strcmp("12345", a.Getcode())==0)
{
cout<<endl;
cout<<"登录成功 !"<<endl<<endl;
menu_second();
}
else
{
cout<<"用户名或密码错误,请重新输入"<<endl;
}
}
break;
default:
cout<<"输入有误,请重新输入"<<endl;
}
}
}
/**************************************************************/
void menu_second()
{
int chice = 0;
while(1)
{
cout<<"0------退出系统"<<endl;
cout<<"1------还书"<<endl;
cout<<"2------借书"<<endl;
cout<<"3------查询图书馆存书"<<endl;
cout<<"4------注销用户"<<endl;
cout<<"5------返回上一层"<<endl;
cout<<"6------管理员存书"<<endl;
cout<<"7------查询我的图书"<<endl;
cout<<endl;
cout<<"请您选择"<<endl;
cin>>chice;
switch(chice)
{
case 0:
{
cout<<"欢迎下次登录 !"<<endl;
return;
}
case 1:
{
a.Returnback();
}
break;
case 2:
{
a.Borrow();
}
break;
case 3:
{
b.Searchbook();
}
break;
case 4:
{
a.Deleteuser();
}
break;
case 5:
{
menu();
}
break;
case 6:
{
b.Adminsert();
}
break;
case 7:
{
a.Mysearch();
}
break;
default:cout<<"输入有误,请重新输入:"<<endl;
}
}
}
/****************************************************/
int main()
{
menu();
return 0;
}
#include<assert.h>
#include<cstring>
using namespace std;
const int Namelen = 20;
const int Codelen = 7;
const int booknamelen=20;
const int bookpublishlen =20;
const int bookauthorlen=20;
//用户类
class user
{
private:
char Mname[Namelen];
char Mcode[Codelen];
user *next;
public:
user()
{
strcpy_s(Mname, "ab");
strcpy_s(Mcode, "ab");
next = NULL;
};
user(char *name, char *code)
{
strcpy_s(Mname, name);
strcpy_s(Mcode, code);
next = NULL;
}
char*Getname() {return Mname;}
char *Getcode() {return Mcode;}
user*Getnext(){return next;};
class Booklink;
void Borrow();
void Returnback();
void Mysearch();
void Delegte();
void Login();
void Deleteuser();
public:
class usermationnode
{
public:
char bkname[booknamelen];
char bkaut[bookauthorlen];
char bkpub[bookpublishlen];
int amount;
usermationnode *bkmationnext;
usermationnode()
{
amount = 0;
bkmationnext=NULL;
}
};
usermationnode *bkmationnext;
//嵌套类,用户链表结点
public:
class userlink
{
private:
user *Mhead;
public:
userlink()
{
Mhead =new(nothrow) user;
assert( Mhead != NULL);
Mhead ->next =NULL;
}
int Add_user(user us)
{
user*newuser =new(nothrow)user;
assert(newuser != NULL);
strcpy_s(newuser->Mname, us.Mname);
strcpy_s(newuser->Mcode,us.Mcode);
newuser->next =Mhead->next;
Mhead->next = newuser;
return 1;
}
user *Getfirstnode(){return Mhead->next;};
};
void insert(usermationnode &p)
{
(&p)->bkmationnext = bkmationnext;
bkmationnext =(&p);
}
};
/*************************************************************/
//图书类
class Booklink
{
public:
Booklink()
{
mhead = new(nothrow)Node;
assert(mhead != NULL);
mhead->next = NULL;
};
~Booklink()
{
Node *pcur =new(nothrow)Node;
assert(pcur != NULL);
pcur = mhead;
while(pcur != NULL)
{
mhead = mhead->next;
delete pcur;
pcur = mhead;
}
}
void Searchbook();
void Adminsert();
public:
class Node
{
public:
Node()
{
strcpy_s(bkname, "ab");
strcpy_s(bkaut,"ab");
strcpy_s(bkpub,"ab");
amount=0;
next =NULL;
};
Node(char *a, char *b, char *c)
{
strcpy_s(bkname,a);
strcpy_s(bkpub,b);
strcpy_s(bkaut,c);
amount=0;
next =NULL;
}
char bkname[booknamelen];
char bkaut[bookauthorlen];
char bkpub[bookpublishlen];
int amount;
class user b;
Node *next;
};
Node *mhead;
};
Booklink b;
user a;
Booklink::Node *pcurt = new(nothrow)Booklink::Node;
/********删除用户***********/
void user::Deleteuser()
{
void menu();
char str1[Namelen]="ab";
char str2[Codelen]="ab";
cout<<"姓名:";
cin>>str1;
cout<<"密码:";
cin>>str2;
cout<<endl;
user *tep1=new(nothrow)user;
assert(tep1 != NULL);
user *tep2=new(nothrow)user;
assert(tep2 != NULL);
tep1=&a;
for(; tep1->next != NULL; tep1 = tep1->next)
{
if(strcmp(tep1->next->Mname, str1)==0 && strcmp(tep1->next->Mcode, str2)==0)
{
tep2 = tep1->next;
tep1->next =tep1->next->next;
delete tep2;
cout<<endl;
cout<<"删除成功!"<<endl<<endl;
menu();
break;
}
}
}
/*********登录****/
void user::Login()
{
void menu_second();
char str1[Namelen]="ab";
char str2[Codelen]="ab";
cout<<"姓名:";
cin>>str1;
cout<<"密码:";
cin>>str2;
cout<<endl;
user *tep1=new(nothrow)user;
tep1=a.next;
for(; tep1 != NULL; tep1 = tep1->next)
{
if(strcmp(tep1->Mname, str1)==0 && strcmp(tep1->Mcode, str2)==0)
{
cout<<endl;
cout<<"登录成功!"<<endl<<endl;
menu_second();
}
}
if(tep1 == NULL)
{
cout<<"用户名或密码错误!"<<endl;
}
}
/********注册**************/
void user::Delegte()
{
char str1[Namelen]="ab";
char str2[Codelen]="ab";
user *tep=new(nothrow)user;
assert(tep != NULL);
cout<<"姓名:";
cin>>str1;
cout<<"密码:";
cin>>str2;
strcpy_s(tep->Mname,str1);
strcpy_s(tep->Mcode,str2);
tep->next = a.next ;
a.next = tep;
cout<<"注册成功!"<<endl;
}
/********查询我的存书*********/
void user::Mysearch()
{
int tep=0;
usermationnode *p=new(nothrow)usermationnode;
assert(p != NULL);
p = this->bkmationnext;
while(p != NULL)
{
cout<<"书名:"<<p->bkname<<endl;
cout<<"出版社:"<<p->bkpub<<endl;
cout<<"作者:"<<p->bkaut<<endl;
cout<<"数量:"<<p->amount<<endl;
cout<<endl;
tep = 1;
p=p->bkmationnext;
}
if(tep == 0)
{
cout<<"暂时没有借书"<<endl;
}
}
/************查询图书馆存书***************/
void Booklink::Searchbook()
{
char s1bookname[booknamelen]="abc";
cout<<"请输入书名:";
cin>>s1bookname;
cout<<endl;
Node *p=new(nothrow)Node;
assert(p != NULL);
p=mhead->next;
while(p != NULL)
{
if(strcmp(s1bookname, p->bkname)==0)
{
cout<<"书名:"<<p->bkname<<endl;
cout<<"出版社:"<<p->bkpub<<endl;
cout<<"作者:"<<p->bkaut<<endl;
cout<<"数量:"<<p->amount<<endl;
break;
}
p=p->next;
}
if(p == NULL)
{
cout<<endl;
cout<<endl;
cout<<"对不起,暂无此书,请检查输入是否有误!"<<endl;
cout<<endl;
}
}
/*****还书*****/
void user::Returnback()
{
char str1[booknamelen] = "qmj";
cout<<"请输入书名:";
cin>>str1;
pcurt = b.mhead->next;
usermationnode *p =new(nothrow)usermationnode;
assert(p != NULL);
p=this->bkmationnext;
for(;p != NULL; p=p->bkmationnext )
{
if(strcmp(str1,p->bkname) == 0 && p->amount >0)
{
p->amount--;
break;
}
}
if(p == NULL)
{
cout<<"输入有误!"<<endl;
return;
}
pcurt = b.mhead->next;
for(; pcurt != NULL; pcurt =pcurt->next)
{
if(strcmp(pcurt->bkname , str1) == 0)
{
pcurt->amount +=1;
pcurt =b.mhead->next;
cout<<"还书成功!"<<endl;
break;
}
}
}
/***管理员存书*****/
void Booklink::Adminsert()
{
int tepamount;
char s1bookname[booknamelen]="abc";
char s2bookpub[bookpublishlen]="abd";
char s3bookaut[bookauthorlen]="abd";
cout<<"请输入书名:";
cin>>s1bookname;
cout<<"请输入出版社:";
cin>>s2bookpub;
cout<<"请输入作者:";
cin>>s3bookaut;
cout<<"请输入数量:";
cin>>tepamount;
Node *p=new(nothrow)Node;
assert(p != NULL);
p=mhead->next;
while(p != NULL)
{
if(strcmp(s1bookname, p->bkname)==0)
{
p->amount+= tepamount;
break;
}
p=p->next;
}
if(p == NULL)
{
Node *q=new(nothrow)Node;
assert(q != NULL);
q->next = mhead->next;
mhead->next = q;
mhead->next->amount += tepamount;
strcpy_s(mhead->next->bkname, s1bookname);
strcpy_s(mhead->next->bkpub, s2bookpub);
strcpy_s(mhead->next->bkaut,s3bookaut);
}
}
/*******借书****************/
void user :: Borrow()
{
pcurt = b.mhead->next;
cout<<"请输入书名:";
char str[booknamelen]="ab";
cin>>str;
for(; pcurt != NULL; pcurt =pcurt ->next)
{
if(strcmp(str, pcurt ->bkname) == 0)
{
if(pcurt ->amount > 1)
{
pcurt ->amount--;
break;
}
}
}
if(pcurt == NULL)
{
cout<<"无此书!请检查输入是否有误!"<<endl;
return;
}
usermationnode *p = new(nothrow)usermationnode;
assert(p != NULL);
p = this->bkmationnext;
usermationnode *q = new(nothrow)usermationnode;
assert(q != NULL);
strcpy_s(q->bkname, str);
strcpy_s(q->bkpub, pcurt->bkpub);
strcpy_s(q->bkaut, pcurt->bkaut);
q->amount =1;
for(; p !=NULL; p =p->bkmationnext)
{
if(strcmp(str,p->bkname)==0)
{
p->amount++;
pcurt =b.mhead->next;
cout<<"借书成功 !"<<endl;
return ;
}
}
if(p == NULL)
{
insert(*q);
pcurt =b.mhead->next;
cout<<"借书成功 !"<<endl;
return ;
}
}
/*************************************************************************************/
void menu()
{
user :: userlink plist;
int flag=1;
void menu_second();
cout<<"欢迎登录图书馆管理系统"<<endl;
while(flag)
{
cout<<endl;
cout<<"0------退出"<<endl;
cout<<"1------注册"<<endl;
cout<<"2------登录"<<endl;
cout<<"3------返回"<<endl;
cout<<"4------管理员登录"<<endl;
cout<<endl;
cout<<"请选择:"<<endl;
int choice;
cin>>choice;
switch(choice)
{
case 0:
{
return;
}
break;
case 1:
{
a.Delegte();
}
break;
case 2:
{
a.Login();
}
break;
case 3:
{
cout<<"欢迎您下次登录!"<<endl;
}
break;
case 4:
{
cout<<"姓名:";
cin>>(a.Getname());
cout<<"密码:";
cin>>(a.Getcode());
if(strcmp("liwei", a.Getname())==0 &&
strcmp("12345", a.Getcode())==0)
{
cout<<endl;
cout<<"登录成功 !"<<endl<<endl;
menu_second();
}
else
{
cout<<"用户名或密码错误,请重新输入"<<endl;
}
}
break;
default:
cout<<"输入有误,请重新输入"<<endl;
}
}
}
/**************************************************************/
void menu_second()
{
int chice = 0;
while(1)
{
cout<<"0------退出系统"<<endl;
cout<<"1------还书"<<endl;
cout<<"2------借书"<<endl;
cout<<"3------查询图书馆存书"<<endl;
cout<<"4------注销用户"<<endl;
cout<<"5------返回上一层"<<endl;
cout<<"6------管理员存书"<<endl;
cout<<"7------查询我的图书"<<endl;
cout<<endl;
cout<<"请您选择"<<endl;
cin>>chice;
switch(chice)
{
case 0:
{
cout<<"欢迎下次登录 !"<<endl;
return;
}
case 1:
{
a.Returnback();
}
break;
case 2:
{
a.Borrow();
}
break;
case 3:
{
b.Searchbook();
}
break;
case 4:
{
a.Deleteuser();
}
break;
case 5:
{
menu();
}
break;
case 6:
{
b.Adminsert();
}
break;
case 7:
{
a.Mysearch();
}
break;
default:cout<<"输入有误,请重新输入:"<<endl;
}
}
}
/****************************************************/
int main()
{
menu();
return 0;
}
相关文章推荐
- 1142: 【C语言训练】立方和不等式
- 简析四大函数
- C++中的复制构造函数
- 1133: 【C语言训练】求1+2!+3!+...+N!的和
- c++primer第二章读书笔记---变量和基本类型
- c++中动态尾随内存的技巧和定位new
- 1147: 【C语言训练】角谷猜想(其实是3n+1)
- C/C++ 读入一行字符串
- win7 64下VC++6.0(Unable to register this add-in because its DLLRegisterServer return an error)
- C++笔记
- [leetcode]36. Valid Sudoku c语言
- 1123: 【C语言训练】列出最简真分数序列*
- c语言下的通用数据库接口(之sqlite消化,模拟c#,java的反射)
- 折半查找
- 顺序方法查找
- 图的遍历和二维矩阵动态分配内存
- 图的矩阵与邻接矩阵转换和遍历
- 图的邻接表存储
- 二叉树
- 队列