当前位置:首页 » 操作系统 » 图书馆源码

图书馆源码

发布时间: 2023-12-13 10:40:17

㈠ C++图书馆管理系统源代码

/*****************************************************************************************/
#include <iostream>
#include <iomanip>
#include <cstring>
#include <fstream>//输入/输出文件流类
using namespace std;
const int Maxr=100;//最多的读者
const int Maxb=100;//最多的图书
const int Maxbor=5;//每位读者最多借五本书
//读者类,实现对读者的信息的描述

class Reader
{
private:
int tag; //删除标记 1:已删 0:未删
int no; //读者编号
char name[10]; //读者姓名
int borbook[Maxbor];//所借图书
public:
Reader() {}
char *getname() {return name;} //获取姓名
int gettag() {return tag;} //获取删除标记
int getno() {return no;} //获取读者编号
void setname(char na[]) //设置姓名
{
strcpy(name,na);

}
void delbook(){ tag=1; }//设置删除标记 1:已删 0:未删
void addreader(int n,char *na)//增加读者
{
tag=0;
no=n;
strcpy(name,na);
for(int i=0;i<Maxbor;i++)
borbook[i]=0;
}
void borrowbook(int bookid)//借书操作
{
for(int i=0;i<Maxbor;i++)
{
if (borbook[i]==0)
{
borbook[i]=bookid;
return;

}
}

}
int retbook(int bookid)//还书操作
{
for(int i=0;i<Maxbor;i++)
{
if(borbook[i]==bookid)
{
borbook[i]=0;
return 1;

}
}
return 0;
}
void disp()//读出读者信息
{
cout << setw(5) << no <<setw(10) << name<<"借书编号:[";
for(int i=0;i<Maxbor;i++)
if(borbook[i]!=0)
cout << borbook[i] << "|";
cout << "]"<<endl;

}
};

//读者类库,实现建立读者的个人资料
class RDatabase
{
private:
int top; //读者记录指针
Reader read[Maxr];//读者记录
public:
RDatabase() //构造函数,将reader.txt读到read[]中
{
Reader s;
top=-1;
fstream file("reader.txt",ios::in);//打开一个输入文件
while (1)
{
file.read((char *)&s,sizeof(s));
if (!file)break;
top++;
read[top]=s;
}
file.close(); //关闭 reader.txt
}
void clear()//删除所有读者信息
{
top=-1;
}
int addreader(int n,char *na)//添加读者时先查找是否存在
{
Reader *p=query(n);
if (p==NULL)
{
top++;
read[top].addreader(n,na);
return 1;
}
return 0;

}
Reader *query(int readerid)//按编号查找
{
for (int i=0;i<=top;i++)
if (read[i].getno()==readerid &&
read[i].gettag()==0)
{
return &read[i];
}
return NULL;
}
void disp() //输出所有读者信息
{
for (int i=0;i<=top;i++)
read[i].disp();
}
void readerdata();//读者库维护
~RDatabase() //析构函数,将read[]写到reader.txt文件中
{
fstream file("reader.txt",ios::out);
for (int i=0;i<=top;i++)
if (read[i].gettag()==0)
file.write((char *)&read[i],sizeof(read[i]));
file.close();

}
};
void RDatabase::readerdata()
{

char choice;
char rname[20];
int readerid;
Reader *r;
while (choice!='0')
{
cout <<"\n\n\t\t\t读 者 维 护\n\n\n\t\t 1 新 增\n\n\t\t 2 更 改\n\n\t\t 3 删 除\n\n\t\t 4 查 找\n\n\t\t 5 显 示\n\n\t\t 6 全 删\n\n\t\t 0 退 出"<<endl;
cin >> choice;
switch (choice)
{
case '1':
cout << "输入读者编号:";
cin >> readerid;
cout << "输入读者姓名:";
cin >> rname;
addreader (readerid,rname);
break;
case '2':
cout << "输入读者编号:";
cin >> readerid;
r=query(readerid);
if (r==NULL)
{
cout << " 该读者不存在 "<<endl;
break;
}
cout << "输入新的姓名:";
cin >> rname;
r->setname(rname);
break;
case '3':
cout << " 输入读者编号:";
cin >> readerid;
r=query(readerid);
if (r==NULL)
{
cout <<" 该读者不存在" << endl;
break;
}
r->delbook();
break;
case '4':
cout << "读入读者编号:";
cin >> readerid;
r=query(readerid);
if (r==NULL)
{
cout <<"该读者不存在"<< endl;
break;
}
r->disp();
break;
case '5':
disp();
break;
case '6':
clear();
break;
default:cout<<"输入错误,请从新输入:";break;
}
}
}

//图书类,实现对图书的描述,图书的编号,书名,借出,还入等
class Book
{
private:
int tag;//删除标记 1:已删 0:未删
int no;//图书编号
char name[20];//书名
int onshelf;//是否再架 1:再架 2:已借
public:
Book(){}
char *getname() { return name; }//获取姓名
int getno(){ return no; }//获取图书编号
int gettag(){ return tag; }//获取删除标记
void setname(char na[])//设置书名
{
strcpy(name,na);
}
void delbook(){ tag=1;}//删除图书
void addbook(int n,char *na)//增加图书
{
tag=0;
no=n;
strcpy(name,na);
onshelf=1;
}
int borrowbook()//借书操作
{
if (onshelf==1)
{
onshelf=0;
return 1;
}
return 0;
}
void retbook()//还书操作
{
onshelf=1;
}
void disp()//输出图书
{
cout << setw(6) << no << setw(18) << name << setw(10)
<<(onshelf==1? "在架":"已借") <<endl;
}
};

//图书库类,实现对图书的维护,查找,删除等
class BDatabase
{
private:
int top; //图书记录指针
Book book[Maxb]; //图书记录
public:
BDatabase()//构造函数,将book.txt读到book[]中
{
Book b;
top=-1;
fstream file("book.txt",ios::in);
while (1)
{
file.read((char *)&b,sizeof(b));
if (!file) break;
top++;
book[top]=b;
}
file.close();
}
void clear()//全删
{
top=-1;
}
int addbook(int n,char *na)//增加图书
{
Book *p=query(n);
if (NULL==p)
{
top++;
book[top].addbook(n,na);
return 1;
}
return 0;
}
Book *query(int bookid)//查找图书
{
for (int i=0;i<=top;i++)
if (book[i].getno()==bookid &&book[i].gettag()==0)
{
return &book[i];
}
return NULL;
}
void bookdata();//图书库维护
void disp()
{
for (int i=0;i<=top;i++)
if (book[i].gettag()==0)
book[i].disp();
}
~BDatabase()//析构函数,将book[]写到book.txt文件中
{
fstream file("book.txt",ios::out);
for (int i=0;i<=top;i++)
if (book[i].gettag()==0)
file.write((char *)&book[i],sizeof(book[i]));
file.close();
}
};
void BDatabase::bookdata()
{
char choice;
char bname[40];
int bookid;
Book *b;
while (choice!='0')
{
cout <<"\n\n\n\t\t\t图 书 维 护 "<<endl<<endl;
cout<<"\t\t1 新 增\n \t\t2 更 改\n\t\t3 删 除\n\t\t4 查 找\n\t\t5 显 示\n\t\t6 全 删\n\t\t0 退 出"<<endl;
cin >> choice;
switch (choice)
{
case '1':
cout << "输入图书编号:"<<endl;
cin >> bookid;
cout << "输入图书书名:"<<endl;
cin >> bname;
addbook(bookid,bname);
break;
case '2':
cout << "输入图书编号:"<<endl;
cin >> bookid;
b=query(bookid);
if (b==NULL)
{
cout << " 该图书不存在 "<<endl;
break;
}
cout << "输入新的书名:"<<endl;
cin >> bname;
b->setname(bname);
break;
case '3':
cout <<" 读入图书编号:"<<endl;
cin >> bookid;
b=query(bookid);
if (b==NULL)
{
cout <<" 该图书不存在" << endl;
break;
}
b->delbook();
break;
case '4':
cout << " 读入图书编号:"<<endl;
cin >> bookid;
b=query(bookid);
if (b==NULL)
{
cout <<" 该图书不存在"<< endl;
break;
}
b->disp();
break;
case '5':
disp();
break;
case '6':
clear();
break;
default:cout<<"输入错误,请从新输入:";
}
}
}

//main() 函数的实现,程序的主界面的引导

int main(void)
{
char choice;
int bookid,readerid;
RDatabase ReaderDB;
Reader *r;
BDatabase BookDB;
Book *b;
while(choice!='0')
{
cout <<endl<<endl<<"\t\t\t 图 书 管 理 系 统\n\n\n";

cout <<"\t\t\t1 借 书\n\n\t\t\t2 还 书 \n\n\t\t\t3 图 书 维 护\n\n\t\t\t4 读 者 维 护\n\n\t\t\t0 离 开"<<endl;
cin >> choice;
switch (choice)
{
case '1':
cout <<" 借书 读者编号:";
cin >>readerid;
cout <<" 图书编号: ";
cin >>bookid;
r=ReaderDB.query(readerid);//按编号查找
if (NULL==r)
{
cout <<" 不存在该读者,不能借书"<< endl;
break;
}
b=BookDB.query(bookid);
if (b==NULL)
{
cout <<" 不存在该图书,不能借书"<< endl;
break;
}
if (b->borrowbook()==0)
{
cout << " 该图书已借出,不能借书"<< endl;
break;
}
r->borrowbook(b->getno());
break;
case '2':
cout<<"还书\n 读者编号:";
cin >>readerid;
cout << " 图书编号:";
cin >>bookid;
r=ReaderDB.query(readerid);
if (r==NULL)
{
cout <<" 不存在该读者,不能还书" << endl;
break;
}
b=BookDB.query(bookid);
if (b==NULL)
{
cout <<" 不存在该图书,不能还书" <<endl;
break;
}
b->retbook();
r->retbook(b->getno());
break;
case '3':
BookDB.bookdata();
break;
case '4':
ReaderDB.readerdata();
break;
default:cout<<"输入错误,请从新输入:";

}
}
return 0;
}

㈡ 用C语言编写的"图书馆管理系统"的源代码,删减版

#include <iostream>
#include <iomanip>
#include <string>
//输入/输出文件流类
#include <fstream>
using namespace std;
//最多的读者
const int Maxr=100;
//最多的图书
const int Maxb=100;
//每位读者最多借五本书
const int Maxbor=5;

//读者类,实现对读者的信息的描述
class Reader
{
private:
//删除标记 1:已删 0:未删
int tag;
//读者编号
int no;
//读者姓名
char name[10];
//所借图书
int borbook[Maxbor];
public:
Reader()
{
;
}
//获取姓名
char *getname()
{
return name;
}
//获取删除标记
int gettag()
{
return tag;
}
//获取读者编号
int getno()
{
return no;
}
//设置姓名
void setname(char na[])
{
strcpy(name,na);

}
//设置删除标记 1:已删 0:未删
void delbook()
{
tag=1;
}
//增加读者
void addreader(int n,char *na)
{
tag=0;
no=n;
strcpy(name,na);
for(int i=0;i<Maxbor;i++)
borbook[i]=0;
}
//借书操作
void borrowbook(int bookid)
{
for(int i=0;i<Maxbor;i++)
{
if (borbook[i]==0)
{
borbook[i]=bookid;
return;

}
}

}
//还书操作
int retbook(int bookid)
{
for(int i=0;i<Maxbor;i++)
{
if(borbook[i]==bookid)
{
borbook[i]=0;
return 1;

}
}
return 0;
}
//读出读者信息
void disp()
{
cout << setw(5) << no <<setw(10) << name<<"借书编号:[";
for(int i=0;i<Maxbor;i++)
if(borbook[i]!=0)
cout << borbook[i] << "|";
cout << "]"<<endl;

}
};

//读者类库,实现建立读者的个人资料
class RDatabase
{
private:
//读者记录指针
int top;
//读者记录
Reader read[Maxr];
public:
//构造函数,将reader.txt读到read[]中
RDatabase()
{
Reader s;
top=-1;
//打开一个输入文件
fstream file("reader.txt",ios::in);
while (1)
{
file.read((char *)&s,sizeof(s));
if (!file)break;
top++;
read[top]=s;
}
//关闭 reader.txt
file.close();
}
//删除所有读者信息
void clear()
{
top=-1;
}
//添加读者时先查找是否存在
int addreader(int n,char *na)
{
Reader *p=query(n);
if (p==NULL)
{
top++;
read[top].addreader(n,na);
return 1;
}
return 0;

}
//按编号查找
Reader *query(int readerid)
{
for (int i=0;i<=top;i++)
if (read[i].getno()==readerid &&
read[i].gettag()==0)
{
return &read[i];
}
return NULL;
}
//输出所有读者信息
void disp()
{
for (int i=0;i<=top;i++)
read[i].disp();
}
//读者库维护
void readerdata();
//析构函数,将read[]写到reader.txt文件中
~RDatabase()
{
fstream file("reader.txt",ios::out);
for (int i=0;i<=top;i++)
if (read[i].gettag()==0)
file.write((char *)&read[i],sizeof(read[i]));
file.close();

}
};
void RDatabase::readerdata()
{

char choice;
char rname[20];
int readerid;
Reader *r;
while (choice!='0')
{
cout <<"\n\n\t\t\t读 者 维 护\n\n\n\t\t 1 新 增\n\n\t\t 2 更 改\n\n\t\t 3 删 除\n\n\t\t 4 查 找\n\n\t\t 5 显 示\n\n\t\t 6 全 删\n\n\t\t 0 退 出"<<endl;
cin >> choice;
switch (choice)
{
case '1':
cout << "输入读者编号:";
cin >> readerid;
cout << "输入读者姓名:";
cin >> rname;
addreader (readerid,rname);
break;
case '2':
cout << "输入读者编号:";
cin >> readerid;
r=query(readerid);
if (r==NULL)
{
cout << " 该读者不存在 "<<endl;
break;
}
cout << "输入新的姓名:";
cin >> rname;
r->setname(rname);
break;
case '3':
cout << " 输入读者编号:";
cin >> readerid;
r=query(readerid);
if (r==NULL)
{
cout <<" 该读者不存在" << endl;
break;
}
r->delbook();
break;
case '4':
cout << "读入读者编号:";
cin >> readerid;
r=query(readerid);
if (r==NULL)
{
cout <<"该读者不存在"<< endl;
break;
}
r->disp();
break;
case '5':
disp();
break;
case '6':
clear();
break;
default:cout<<"输入错误,请从新输入:";break;
}
}
}

//图书类,实现对图书的描述,图书的编号,书名,借
private:
//删除标记 1:已删 0:未删
int tag;
//图书编号
int no;
//书名
char name[20];
//是否再架 1:再架 2:已借
int onshelf;
public:
Book(){}
//获取姓名
char *getname() { return name; }
//获取图书编号
int getno(){ return no; }
//获取删除标记
int gettag(){ return tag; }
//设置书名
void setname(char na[])
{
strcpy(name,na);
}
//删除图书
void delbook(){ tag=1;}
//增加图书
void addbook(int n,char *na)
{
tag=0;
no=n;
strcpy(name,na);
onshelf=1;
}
//借书操作
int borrowbook()
{
if (onshelf==1)
{
onshelf=0;
return 1;
}
return 0;
}
//还书操作
void retbook()
{
onshelf=1;
}
//输出图书
void disp()
{
cout << setw(6) << no << setw(18) << name << setw(10)
<<(onshelf==1? "在架":"已借") <<endl;
}
};

//图书库类,实现对图书的维护,查找,删除等
class BDatabase
{
private:
//图书记录指针
int top;
//图书记录
Book book[Maxb];
public:
//构造函数,将book.txt读到book[]中
BDatabase()
{
Book b;
top=-1;
fstream file("book.txt",ios::in);
while (1)
{
file.read((char *)&b,sizeof(b));
if (!file) break;
top++;
book[top]=b;
}
file.close();
}
//全删
void clear()
{
top=-1;
}
//增加图书
int addbook(int n,char *na)
{
Book *p=query(n);
if (NULL==p)
{
top++;
book[top].addbook(n,na);
return 1;
}
return 0;
}
//查找图书
Book *query(int bookid)
{
for (int i=0;i<=top;i++)
if (book[i].getno()==bookid &&book[i].gettag()==0)
{
return &book[i];
}
return NULL;
}
//图书库维护
void bookdata();
void disp()
{
for (int i=0;i<=top;i++)
if (book[i].gettag()==0)
book[i].disp();
}
//析构函数,将book[]写到book.txt文件中
~BDatabase()
{
fstream file("book.txt",ios::out);
for (int i=0;i<=top;i++)
if (book[i].gettag()==0)
file.write((char *)&book[i],sizeof(book[i]));
file.close();
}
};
void BDatabase::bookdata()
{
char choice;
char bname[40];
int bookid;
Book *b;
while (choice!='0')
{
cout <<"\n\n\n\t\t\t图 书 维 护 "<<endl<<endl;
cout<<"\t\t1 新 增\n \t\t2 更 改\n\t\t3 删 除\n\t\t4 查 找\n\t\t5 显 示\n\t\t6 全 删\n\t\t0 退 出"<<endl;
cin >> choice; {
case '1':
cout << "输入图书编号:"<<endl;
cin >> bookid;
cout << "输入图书书名:"<<endl;
cin >> bname;
addbook(bookid,bname);
break;
case '2':
cout << "输入图书编号:"<<endl;
cin >> bookid;
b=query(bookid);
if (b==NULL)
{
cout << " 该图书不存在 "<<endl;
break;
}
cout << "输入新的书名:"<<endl;
cin >> bname;
b->setname(bname);
break;
case '3':
cout <<" 读入图书编号:"<<endl;
cin >> bookid;
b=query(bookid);
if (b==NULL)
{
cout <<" 该图书不存在" << endl;
break;
}
b->delbook();
break;
case '4':
cout << " 读入图书编号:"<<endl;
cin >> bookid;
b=query(bookid);
if (b==NULL)
{
cout <<" 该图书不存在"<< endl;
break;
}
b->disp();
break;
case '5':
disp();
break;
case '6':
clear();
break;
default:cout<<"输入错误,请从新输入:";
}
}
}

//main() 函数的实现,程序的主界面的引导

void main()
{
char choice;
int bookid,readerid;
RDatabase ReaderDB;
Reader *r;
BDatabase BookDB;
Book *b;
while(choice!='0')
{
cout <<endl<<endl<<"\t\t\t 图 书 管 理 系 统\n\n\n";

cout <<"\t\t\t1 借 书\n\n\t\t\t2 还 书 \n\n\t\t\t3 图 书 维 护\n\n\t\t\t4 读 者 维 护\n\n\t\t\t0 离 开"<<endl;
cin >> choice;
switch (choice)
{
case '1':
cout <<" 借书 读者编号:";
cin >>readerid;
cout <<" 图书编号: ";
cin >>bookid;
//按编号查找
r=ReaderDB.query(readerid);
if (NULL==r)
{
cout <<" 不存在该读者,不能借书"<< endl;
break;
}
b=BookDB.query(bookid);
if (b==NULL)
{
cout <<" 不存在该图书,不能借书"<< endl;
break;
}
if (b->borrowbook()==0)
{
cout << " 该图书已借出,不能借书"<< endl;
break;
}
r->borrowbook(b->getno());
break;
case '2':
cout<<"还书\n 读者编号:";
cin >>readerid;
cout << " 图书编号:";
cin >>bookid;
r=ReaderDB.query(readerid);
if (r==NULL)
{
cout <<" 不存在该读者,不能还书" << endl;
break;
}
b=BookDB.query(bookid);
if (b==NULL)
{
cout <<" 不存在该图书,不能还书" <<endl;
break;
}
b->retbook();
r->retbook(b->getno());
break;
case '3':
BookDB.bookdata();
break;
case '4':
ReaderDB.readerdata();
break;
default:cout<<"输入错误,请从新输入:";

}
}
}

㈢ c++图书馆藏书管理系统源代码

#include"stdio.h"
#include"string.h"

struct book /*定义结构体*/
{ char number[20];
char name[20];
char press[20];
char writer[20];
int n; /*现有量*/
int m; /*总量*/
}a[10];
int b; /*输入书的数量*/

void input() /*输入图书信息函数*/
{
FILE *fp;
char str2[10]={" "};
int i;
if((fp=fopen("d:\\wen","w"))==NULL)
{ printf("Open failed\n");
return; }
printf("\nHow many books do you want to input?\n");
scanf("%d",&b);
for(i=0;i<b;i++)
{
printf("Enter the %d book's number name press writer now all\n",i+1);
scanf("%s%s%s%s%d%d",&a[i].number,&a[i].name,&a[i].press,&a[i].writer,&a[i].n,&a[i].m);
fwrite(&a[i],sizeof(struct book),1,fp);
}
fclose(fp);
}

void Search() /*查询书籍*/
{
FILE *fp;
int w,i; /*w查询方式使用的数据*/
char str[20]; /*查询书籍的编码书名出版社作者*/
if((fp=fopen("d:\\wen","r"))==NULL)
{ printf("Open failed\n");
return; }
for(i=0;i<b;i++)
if(fread(&a[i],sizeof(struct book),1,fp)!=1)
printf("file read error\n");
printf("search by number--6\n");
printf("search by name--7\n");
printf("search by writer--8\n");
printf("search by press--9\n");
scanf("%d",&w);
printf("Enter the word you want to search:\n");
scanf("%s",str);
switch(w)
{
case 6:
{for(i=0;i<b;i++)
if(strcmp(a[i].number,str)==0)
{printf("number: %s name: %s press: %s writer: %s now: %d all:%d\n",a[i].number,a[i].name,a[i].press,a[i].writer,a[i].n,a[i].m);
break;
}
}
break;
case 7:
{for(i=0;i<b;i++)
if(strcmp(a[i].name,str)==0)
{printf("number: %s name: %s press: %s writer: %s now: %d all:%d\n",a[i].number,a[i].name,a[i].press,a[i].writer,a[i].n,a[i].m);
break;}
}
break;
case 8:
{for(i=0;i<b;i++)
if(strcmp(a[i].press,str)==0)
{printf("number: %s name: %s press: %s writer: %s now: %d all:%d\n",a[i].number,a[i].name,a[i].press,a[i].writer,a[i].n,a[i].m);
break;}
}
break;
case 9:
{for(i=0;i<b;i++)
if(strcmp(a[i].writer,str)==0)
{ printf("number: %s name: %s press: %s writer: %s now: %d all:%d\n",a[i].number,a[i].name,a[i].press,a[i].writer,a[i].n,a[i].m);
break; }
}
}
fclose(fp);
}
void borrow() /*借阅图书函数*/
{ FILE *fp;
int i;
char xuehao[20],number2[20];
char jieyue[20]={"borrow:"};
if((fp=fopen("d:\\wen00.txt","w"))==NULL)
{ printf("Open failed\n");
return; }
printf("Enter your number:\n");
scanf("%s",xuehao);
printf("Enter the book's number which you want to borrow\n");
scanf("%s",number2);
for(i=0;i<10;i++)
if(strcmp(a[i].number,number2)==0)
if(a[i].n>0)
{a[i].n--;
printf("borrow sucess!\n");
if(fwrite(&xuehao[20],sizeof(xuehao[20]),1,fp)!=1)
printf("file write error\n");
if(fwrite(&jieyue[20],sizeof(jieyue),1,fp)!=1)
printf("file write error\n");
if(fwrite(&a[i],sizeof(struct book),1,fp)!=1)
printf("file write error\n");
break;
}
else
printf("borrow failed!");
fclose(fp);

}
void giveback() /*归还图书函数*/
{FILE *fp;
int i;
char xuehao[20],number2[20];
char guihuan2[20]={"give back"};
if((fp=fopen("d:\\wen00.txt","w"))==NULL)
{printf("cannot open file\n");
return;
}
printf("Enter your number:\n");
scanf("%s",xuehao);
printf("Enter the book's number which you want to give back\n");
scanf("%s",number2);
for(i=0;i<1000;i++)
if(strcmp(a[i].number,number2)==0)
{ if(fwrite(&xuehao[20],sizeof(xuehao),1,fp)!=1)
printf("file write error\n");
if(fwrite(&guihuan2[20],sizeof(guihuan2),1,fp)!=1)
printf("file write error\n");
if(fwrite(&a[i],sizeof(a[i]),1,fp)!=1)
printf("file write error\n");
break;
}
printf("give back sucess!\n");
fclose(fp);
}

void adddelet() /*增加删除功能*/
{ FILE *fp;
char number3[20];
int s,i,j,t; /*t为增加或删除 s增加书的数量*/
if((fp=fopen("d:\\wen00.txt","w"))==NULL)
{printf("cannot open file\n");
return ;
}
printf("Chose what you want to do:");
printf("add books--11\n");
printf("delet books--12\n");
scanf("%d",&t);
switch(t)
{
case 11:
{printf("Enter the book'number which you want to add:");
scanf("%s",number3);
printf("How many books do you want to add?:");
scanf("%d",&s);
for(i=0;i<10;i++)
if(strcmp(a[i].number,number3)==0)
a[i].m=a[i].m+s;
} break;
default :
{printf("Enter the book'number which you want to delet:");
scanf("%s",number3);
for(i=0;i<10;i++)
if(strcmp(a[i].number,number3)==0)
for(;i<10;i++)
{ for(j=0;j<20;j++)
a[i].number[j]=a[i+1].number[j];
for(j=0;j<20;j++)
a[i].name[j]=a[i+1].name[j];
for(j=0;j<20;j++)
a[i].press[j]=a[i+1].press[j];
for(j=0;j<20;j++)
a[i].writer[j]=a[i+1].writer[j];
a[i].n=a[i+1].n;
a[i].m=a[i+1].m;
}
}

}
fclose(fp);
}

void main() /*主函数*/
{
printf("Welcome to labrary!\nChose what you want to do:\n");
printf("Input book's information--1;\n");
printf("serach books--2;\n");
printf("borrow books--3;\n");
printf("add or delet books--4;\n");
printf("give back books--5;\n");
printf("quit--6;\n");
printf("Please chose zhe number:");
while(1)
{
switch(getchar())
{
case '1': input();break;
case '2': Search();break;
case '3': borrow() ;break;
case '4': adddelet();break;
case '5': giveback();break;

}
}
}

㈣ 求图书馆管理系统C++源代码

#include<iostream>
#include<fstream>
#include<windows.h>
#include<stdlib.h>
using namespace std;
void mainmenu();
void Manage_Book();
void input_Book();
void input_Reader();
void New_Book();
void Seek_Book();
void Borrow_Manage();
void Borrow_Book();
void Return_Book();
void Output_Message();
void Exit_System();
int u,v=3,k=0;
struct Book
{
char name[20];
int booknumber;
int num_present;
int num_all;
}book[1000];
struct Reader
{
char name[20];
int readernumber;
int card;
}reader[3];
void mainmenu()
{
int Num_Choice1,flag=1;
system("color E");
for(;k<=0;k++)
{
input_Book();
input_Reader();
}
while(flag==1)
{
system("cls");
cout<<"\t\t\t◆◆◆◆◆主菜单◆◆◆◆◆"<<endl
<<"\t\t\t☆ 1.图书管理 ☆"<<endl
<<"\t\t\t☆ 2.借阅管理 ☆"<<endl
<<"\t\t\t☆ 3.输出信息 ☆"<<endl
<<"\t\t\t☆ 4.退出系统 ☆"<<endl
<<"\t\t\t◆◆◆◆◆◆◆◆◆◆◆◆◆"<<endl;
cout<<"请输入所需要的服务编码"<<endl;
cin>>Num_Choice1;
switch(Num_Choice1)
{
case 1:
Manage_Book();
break;
case 2:
Borrow_Manage();
break;
case 3:
Output_Message();
break;
case 4:
Exit_System();
flag=0;
break;
default:
flag=0;
cout<<"输入有误!!"<<endl;
}
}
}
void Manage_Book()
{
int flag1=1,Num_Choice2;
system("cls"); while(flag1==1)
{
cout<<"\t\t\t◆◆◆◆◆◆◆◆◆◆◆◆◆"<<endl
<<"\t\t\t☆ 1.新书入库 ☆"<<endl
<<"\t\t\t☆ 2.图书查询 ☆"<<endl
<<"\t\t\t☆ 3.返回主菜单 ☆"<<endl
<<"\t\t\t◆◆◆◆◆◆◆◆◆◆◆◆◆"<<endl;
cin>>Num_Choice2;
switch(Num_Choice2)
{
case 1:
flag1=2;
New_Book();
break;
case 2:
flag1=2;
Seek_Book();
break;
case 3:
mainmenu();
default:
flag1=1;
cout<<"输入有误!"<<endl;
system("pause");
system("cls");
}
}}
void input_Book()
{
cout<<"请依照提示输入现有的三本图书的信息:"<<endl;
for(int i=0;i<3;i++)
{
cout<<"书名:"<<endl;
cin>>book[i].name;
cout<<"书号:"<<endl;
cin>>book[i].booknumber;
cout<<"库存量:"<<endl;
cin>>book[i].num_all;
cout<<"现存量:"<<endl;
cin>>book[i].num_present;
}
}
void New_Book()
{
system("cls");
int j;
char newbook_name[20];
cout<<"请输入新书书名:"<<endl;
cin>>newbook_name;
for(j=0;j<1000;j++)
{
if(strcmp(newbook_name,book[j].name)==0)
{
book[j].num_all++;
book[j].num_present++;
break;
}
}
if(j==1000)
{
cout<<"请为此新书编号:"<<endl;
v++;
cin>>book[v].booknumber;
strcpy(book[v].name,newbook_name);
book[v].num_all=1;
book[v].num_present=1;
}
else cout<<"已有此书,库存量加一"<<endl;
system("pause");
}
void Seek_Book()
{
system("cls");
int k,booknumber;
cout<<"请输入所要查询的书号:"<<endl;
cin>>booknumber;
for(k=0;k<1000;k++)
{
if(book[k].booknumber==booknumber)
{
cout<<"书号:"<<booknumber<<endl;
cout<<"书名:"<<book[k].name<<endl;
cout<<"库存量:"<<book[k].num_all<<endl;
cout<<"现存量:"<<book[k].num_present<<endl;
system("pause");
break;
}
}
if(k==1000)
{
cout<<"未找到此书!!"<<endl;
system("pause");
}
}
void Borrow_Manage()
{
int flag=1;
system("cls");
int Num_Choice3;
while(flag==1)
{
cout<<"\t\t\t◆◆◆◆◆◆◆◆◆◆◆◆◆"<<endl
<<"\t\t\t☆ 1.借书登记 ☆"<<endl
<<"\t\t\t☆ 2.还书管理 ☆"<<endl
<<"\t\t\t☆ 3.返回主菜单 ☆"<<endl
<<"\t\t\t◆◆◆◆◆◆◆◆◆◆◆◆◆"<<endl;
cin>>Num_Choice3;
switch(Num_Choice3)
{
case 1:
flag=2;
Borrow_Book();
break;
case 2:
flag=2;
Return_Book();
break;
case 3:
mainmenu();
default:
flag=1;
cout<<"输入有误!!"<<endl;
system("pause");
}
system("cls");
}
}
void input_Reader()
{
system("cls");
cout<<"请依照提示输入现有的三位读者的信息:"<<endl;
for(int m=0;m<3;m++)
{
cout<<"姓名:"<<endl;
cin>>reader[m].name;
cout<<"编号:"<<endl;
cin>>reader[m].readernumber;
reader[m].card=0;
}
}
void Borrow_Book()
{
system("cls");
char reader_name[20];
int n,book_number;
cout<<"请输入读者姓名:"<<endl;
cin>>reader_name;
for(n=0;n<3;n++)
{
if(strcmp(reader_name,reader[n].name)==0)
{
if(reader[n].card!=0)
{
cout<<"已借书,不能再借,请按任意键返回"<<endl;
system("pause");
mainmenu();
}
else
break;
}
}
if(n==3)
{
cout<<"无此读者!输入有误!!按任意键返回主菜单"<<endl;
system("pause");
mainmenu();
}
cout<<"请输入所借图书书号:"<<endl;
cin>>book_number;
for(n=0;n<v;n++)
{
if(strcmp(reader_name,reader[n].name)==0)
reader[n].card=book_number;
}
for(n=0;n<v;n++)
{
if(book[n].booknumber==book_number)
{
if(book[n].num_present==0)
{
cout<<"该书已经被借完,请按任意键返回"<<endl;
system("pause");
for(n=0;n<v;n++)
{
if(strcmp(reader_name,reader[n].name)==0)
reader[n].card=0;
}
mainmenu();
}
else
{
book[n].num_present--;
cout<<"借书成功,请按任意键返回"<<endl;
system("pause");
break;
}
}
}
if(n==v)
{
for(n=0;n<v;n++)
{
if(strcmp(reader_name,reader[n].name)==0)
reader[n].card=0;
}
cout<<"所输入的书号不存在,请按任意键返回主菜单"<<endl;
system("pause");
mainmenu();
}
}void Return_Book()
{
system("cls");
int j;
char reader_name[20];
int book_number;
cout<<"请输入读者姓名:"<<endl;
cin>>reader_name;
for(j=0;j<3;j++)
{
if(strcmp(reader_name,reader[j].name)==0)
break;
}
if(j==3)
{
cout<<"无此读者!输入有误!!按任意键返回主菜单"<<endl;
system("pause");
mainmenu();
}
cout<<"请输入所还图书书号:"<<endl;
cin>>book_number;

for(j=0;j<3;j++)
{
if(strcmp(reader_name,reader[j].name)==0)
{
if(book_number==reader[j].card)
{
reader[j].card=0;
for(j=0;j<v;j++)
{
if(book[j].booknumber==book_number)
{
book[j].num_present++;
cout<<"还书成功,请按任意键返回"<<endl;
system("pause");
break;
}
}
}
else
{
cout<<"该读者未借此书"<<endl;
system("pause");
}
}
if(j==v)
cout<<"所输入的书号不存在:"<<endl;
}
}
void Output_Message()
{
system("cls");
int q;
cout<<"以下是图书信息"<<endl<<endl;
for(q=0;q<v;q++)
{
cout<<"书号:"<<book[q].booknumber<<'\t';
cout<<"书名:"<<book[q].name<<'\t';
cout<<"库存量:"<<book[q].num_all<<'\t';
cout<<"现存量:"<<book[q].num_present<<endl;
}
cout<<"以下是读者信息"<<endl<<endl;
for(q=0;q<3;q++)
{
cout<<"姓名:"<<reader[q].name<<'\t'
<<"编号:"<<reader[q].readernumber<<'\t'
<<"所借书号:"<<reader[q].card<<endl;
}
system("pause");
}
void Exit_System()
{
system("cls");
cout<<"欢迎下次使用,谢谢"<<endl;
system("pause");
}
void main()
{
mainmenu();
}

㈤ 图书馆管理系统代码

/*****************************************************************************************/
#include <iostream>
#include <iomanip>
#include <cstring>
#include <fstream>//输入/输出文件流类
using namespace std;
const int Maxr=100;//最多的读者
const int Maxb=100;//最多的图书
const int Maxbor=5;//每位读者最多借五本书
//读者类,实现对读者的信息的描述

class Reader
{
private:
int tag; //删除标记 1:已删 0:未删
int no; //读者编号
char name[10]; //读者姓名
int borbook[Maxbor];//所借图书
public:
Reader() {}
char *getname() {return name;} //获取姓名
int gettag() {return tag;} //获取删除标记
int getno() {return no;} //获取读者编号
void setname(char na[]) //设置姓名
{
strcpy(name,na);

}
void delbook(){ tag=1; }//设置删除标记 1:已删 0:未删
void addreader(int n,char *na)//增加读者
{
tag=0;
no=n;
strcpy(name,na);
for(int i=0;i<Maxbor;i++)
borbook[i]=0;
}
void borrowbook(int bookid)//借书操作
{
for(int i=0;i<Maxbor;i++)
{
if (borbook[i]==0)
{
borbook[i]=bookid;
return;

}
}

}
int retbook(int bookid)//还书操作
{
for(int i=0;i<Maxbor;i++)
{
if(borbook[i]==bookid)
{
borbook[i]=0;
return 1;

}
}
return 0;
}
void disp()//读出读者信息
{
cout << setw(5) << no <<setw(10) << name<<"借书编号:[";
for(int i=0;i<Maxbor;i++)
if(borbook[i]!=0)
cout << borbook[i] << "|";
cout << "]"<<endl;

}
};

//读者类库,实现建立读者的个人资料
class RDatabase
{
private:
int top; //读者记录指针
Reader read[Maxr];//读者记录
public:
RDatabase() //构造函数,将reader.txt读到read[]中
{
Reader s;
top=-1;
fstream file("reader.txt",ios::in);//打开一个输入文件
while (1)
{
file.read((char *)&s,sizeof(s));
if (!file)break;
top++;
read[top]=s;
}
file.close(); //关闭 reader.txt
}
void clear()//删除所有读者信息
{
top=-1;
}
int addreader(int n,char *na)//添加读者时先查找是否存在
{
Reader *p=query(n);
if (p==NULL)
{
top++;
read[top].addreader(n,na);
return 1;
}
return 0;

}
Reader *query(int readerid)//按编号查找
{
for (int i=0;i<=top;i++)
if (read[i].getno()==readerid &&
read[i].gettag()==0)
{
return &read[i];
}
return NULL;
}
void disp() //输出所有读者信息
{
for (int i=0;i<=top;i++)
read[i].disp();
}
void readerdata();//读者库维护
~RDatabase() //析构函数,将read[]写到reader.txt文件中
{
fstream file("reader.txt",ios::out);
for (int i=0;i<=top;i++)
if (read[i].gettag()==0)
file.write((char *)&read[i],sizeof(read[i]));
file.close();

}
};
void RDatabase::readerdata()
{

char choice;
char rname[20];
int readerid;
Reader *r;
while (choice!='0')
{
cout <<"\n\n\t\t\t读 者 维 护\n\n\n\t\t 1 新 增\n\n\t\t 2 更 改\n\n\t\t 3 删 除\n\n\t\t 4 查 找\n\n\t\t 5 显 示\n\n\t\t 6 全 删\n\n\t\t 0 退 出"<<endl;
cin >> choice;
switch (choice)
{
case '1':
cout << "输入读者编号:";
cin >> readerid;
cout << "输入读者姓名:";
cin >> rname;
addreader (readerid,rname);
break;
case '2':
cout << "输入读者编号:";
cin >> readerid;
r=query(readerid);
if (r==NULL)
{
cout << " 该读者不存在 "<<endl;
break;
}
cout << "输入新的姓名:";
cin >> rname;
r->setname(rname);
break;
case '3':
cout << " 输入读者编号:";
cin >> readerid;
r=query(readerid);
if (r==NULL)
{
cout <<" 该读者不存在" << endl;
break;
}
r->delbook();
break;
case '4':
cout << "读入读者编号:";
cin >> readerid;
r=query(readerid);
if (r==NULL)
{
cout <<"该读者不存在"<< endl;
break;
}
r->disp();
break;
case '5':
disp();
break;
case '6':
clear();
break;
default:cout<<"输入错误,请从新输入:";break;
}
}
}

//图书类,实现对图书的描述,图书的编号,书名,借出,还入等
class Book
{
private:
int tag;//删除标记 1:已删 0:未删
int no;//图书编号
char name[20];//书名
int onshelf;//是否再架 1:再架 2:已借
public:
Book(){}
char *getname() { return name; }//获取姓名
int getno(){ return no; }//获取图书编号
int gettag(){ return tag; }//获取删除标记
void setname(char na[])//设置书名
{
strcpy(name,na);
}
void delbook(){ tag=1;}//删除图书
void addbook(int n,char *na)//增加图书
{
tag=0;
no=n;
strcpy(name,na);
onshelf=1;
}
int borrowbook()//借书操作
{
if (onshelf==1)
{
onshelf=0;
return 1;
}
return 0;
}
void retbook()//还书操作
{
onshelf=1;
}
void disp()//输出图书
{
cout << setw(6) << no << setw(18) << name << setw(10)
<<(onshelf==1? "在架":"已借") <<endl;
}
};

//图书库类,实现对图书的维护,查找,删除等
class BDatabase
{
private:
int top; //图书记录指针
Book book[Maxb]; //图书记录
public:
BDatabase()//构造函数,将book.txt读到book[]中
{
Book b;
top=-1;
fstream file("book.txt",ios::in);
while (1)
{
file.read((char *)&b,sizeof(b));
if (!file) break;
top++;
book[top]=b;
}
file.close();
}
void clear()//全删
{
top=-1;
}
int addbook(int n,char *na)//增加图书
{
Book *p=query(n);
if (NULL==p)
{
top++;
book[top].addbook(n,na);
return 1;
}
return 0;
}
Book *query(int bookid)//查找图书
{
for (int i=0;i<=top;i++)
if (book[i].getno()==bookid &&book[i].gettag()==0)
{
return &book[i];
}
return NULL;
}
void bookdata();//图书库维护
void disp()
{
for (int i=0;i<=top;i++)
if (book[i].gettag()==0)
book[i].disp();
}
~BDatabase()//析构函数,将book[]写到book.txt文件中
{
fstream file("book.txt",ios::out);
for (int i=0;i<=top;i++)
if (book[i].gettag()==0)
file.write((char *)&book[i],sizeof(book[i]));
file.close();
}
};
void BDatabase::bookdata()
{
char choice;
char bname[40];
int bookid;
Book *b;
while (choice!='0')
{
cout <<"\n\n\n\t\t\t图 书 维 护 "<<endl<<endl;
cout<<"\t\t1 新 增\n \t\t2 更 改\n\t\t3 删 除\n\t\t4 查 找\n\t\t5 显 示\n\t\t6 全 删\n\t\t0 退 出"<<endl;
cin >> choice;
switch (choice)
{
case '1':
cout << "输入图书编号:"<<endl;
cin >> bookid;
cout << "输入图书书名:"<<endl;
cin >> bname;
addbook(bookid,bname);
break;
case '2':
cout << "输入图书编号:"<<endl;
cin >> bookid;
b=query(bookid);
if (b==NULL)
{
cout << " 该图书不存在 "<<endl;
break;
}
cout << "输入新的书名:"<<endl;
cin >> bname;
b->setname(bname);
break;
case '3':
cout <<" 读入图书编号:"<<endl;
cin >> bookid;
b=query(bookid);
if (b==NULL)
{
cout <<" 该图书不存在" << endl;
break;
}
b->delbook();
break;
case '4':
cout << " 读入图书编号:"<<endl;
cin >> bookid;
b=query(bookid);
if (b==NULL)
{
cout <<" 该图书不存在"<< endl;
break;
}
b->disp();
break;
case '5':
disp();
break;
case '6':
clear();
break;
default:cout<<"输入错误,请从新输入:";
}
}
}

//main() 函数的实现,程序的主界面的引导

int main(void)
{
char choice;
int bookid,readerid;
RDatabase ReaderDB;
Reader *r;
BDatabase BookDB;
Book *b;
while(choice!='0')
{
cout <<endl<<endl<<"\t\t\t 图 书 管 理 系 统\n\n\n";

cout <<"\t\t\t1 借 书\n\n\t\t\t2 还 书 \n\n\t\t\t3 图 书 维 护\n\n\t\t\t4 读 者 维 护\n\n\t\t\t0 离 开"<<endl;
cin >> choice;
switch (choice)
{
case '1':
cout <<" 借书 读者编号:";
cin >>readerid;
cout <<" 图书编号: ";
cin >>bookid;
r=ReaderDB.query(readerid);//按编号查找
if (NULL==r)
{
cout <<" 不存在该读者,不能借书"<< endl;
break;
}
b=BookDB.query(bookid);
if (b==NULL)
{
cout <<" 不存在该图书,不能借书"<< endl;
break;
}
if (b->borrowbook()==0)
{
cout << " 该图书已借出,不能借书"<< endl;
break;
}
r->borrowbook(b->getno());
break;
case '2':
cout<<"还书\n 读者编号:";
cin >>readerid;
cout << " 图书编号:";
cin >>bookid;
r=ReaderDB.query(readerid);
if (r==NULL)
{
cout <<" 不存在该读者,不能还书" << endl;
break;
}
b=BookDB.query(bookid);
if (b==NULL)
{
cout <<" 不存在该图书,不能还书" <<endl;
break;
}
b->retbook();
r->retbook(b->getno());
break;
case '3':
BookDB.bookdata();
break;
case '4':
ReaderDB.readerdata();
break;
default:cout<<"输入错误,请从新输入:";

}
}
return 0;
}
希望能解决您的问题。

热点内容
龙村m脚本 发布:2024-11-29 17:38:10 浏览:784
linuxc配置文件 发布:2024-11-29 17:08:31 浏览:828
wow刷碎片脚本 发布:2024-11-29 15:58:24 浏览:592
明小子源码 发布:2024-11-29 15:15:30 浏览:145
苹果8plus什么配置 发布:2024-11-29 14:16:36 浏览:677
androidmvp结构 发布:2024-11-29 14:16:34 浏览:536
androidsqlite命令 发布:2024-11-29 14:04:38 浏览:156
信用卡分期算法 发布:2024-11-29 13:50:56 浏览:808
安卓手机dll文件为什么打不开 发布:2024-11-29 13:40:49 浏览:1003
百分之五十石碳酸怎么配置 发布:2024-11-29 13:38:56 浏览:974