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

图书源码

发布时间: 2022-01-20 23:13:46

① 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;
}

② 求高手 图书管理系统的数据库源代码

自己多做分析,最好先去做个调查,然后自己动手做个,很简单的

③ 图书管理系统源代码

想找人代做?
不免费

④ 图书馆借阅系统源代码

#include<stdio.h> #include<string.h> #include<conio.h> #include<stdlib.h> #include<ctype.h> #define STACK_INIT_SIZE 10 #define OK 1 #define TRUE 1 #define FALSE 0 #define ERROR 0 struct student /*定义学生类型,用于存放借出的书籍*/ { int carnum; char lendbook[10]; }student[1000]; struct employ /*定义职工类型*/ { int employnum; char employname[15]; int employage; char employsex[2]; char employleve[10]; long int employtage; }employ[50]; struct book /*定义书的类型*/ { int booknum; char bookname[10]; char bookcreat[10]; int turefalse; /*用于借书和还书模块判断一本书是否借出的条件*/ }book[1000]; struct car /*借书卡的数据类型*/ { int carnum; char studentname[10]; int studentclass; }car[100]; huanbook() /*还书函数*/ { FILE *fp,*fp2; /*定义两个文件指针,fp2用于修改数据时设立临时文件用,防止数据遭破坏*/ int i,n; int carnum; char lendbook[10]; printf("请你输入你的卡号\n"); scanf("%d",&carnum); fp=fopen("car.txt","r"); /*读取卡号记录*/ for(i=0;fread(&car[i],sizeof(struct car),1,fp)!=0;i++) /*for循环判断卡号是否存在*/ { if(car[i].carnum==carnum) /*卡号存在,进入下一循环*/ { n=i; fclose(fp); printf("请输入你要还的书的名字\n"); scanf("%s",lendbook); fp=fopen("record.txt","r"); for(i=0;fread(&student[i],sizeof(struct student),1,fp)!=0;i++) /*判断是否借阅了输入的书*/ { if(strcmp(student[i].lendbook,lendbook)==0) /*借阅了该书,进入下一循环,否则出错显示*/ { fclose(fp); fp=fopen("record.txt","r"); fp2=fopen("bookl.txt","w"); for(i=0;fread(&student[i],sizeof(struct student),1,fp)!=0;i++) { if(strcmp(student[i].lendbook,lendbook)==0) { continue; /*删除还掉的书的借书记录*/ } fwrite(&student[i],sizeof(struct student),1,fp2); /*写入原来没还的书的记录*/ } fclose(fp); fclose(fp2); fp=fopen("record.txt","w"); fp2=fopen("bookl.txt","r"); for(i=0;fread(&student[i],sizeof(struct student),1,fp2)!=0;i++) { fwrite(&student[i],sizeof(struct student),1,fp); /*将借书记录信息写回*/ } fclose(fp); fclose(fp2); fopen("bookl.txt","w"); /*清临时文件的记录*/ fclose(fp2); fp=fopen("book.txt","r"); fp2=fopen("bookl.txt","w"); for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++) /*将书的记录写入临时文件,防止因为修改信息破坏以前的记录*/ { if(i==n) { book[i].turefalse=1; fwrite(&book[i],sizeof(struct book),1,fp2); /*将还的书的原来状态设为无人借阅的*/ continue; } fwrite(&book[i],sizeof(struct book),1,fp2); } fclose(fp); fclose(fp2); fp=fopen("book.txt","w"); fp2=fopen("bookl.txt","r"); for(i=0;fread(&book[i],sizeof(struct book),1,fp2)!=0;i++) { fwrite(&book[i],sizeof(struct book),1,fp); /*将临时文件写回*/ } fclose(fp); fclose(fp2); fopen("bookl.txt","w"); /*清临时文件*/ fclose(fp2); printf("还书完毕,按任意键返回\n"); getch(); return 1; } } printf("你没有借这样的书,任意键返回\n"); /*出错提示*/ fclose(fp); getch(); return 0; } } printf("系统没这样的卡,和管理员联系,按任意键返回\n"); /*出错提示*/ fclose(fp); getch(); } findbook() { FILE *fp; char bookname[10]; int ture,i; fp=fopen("book.txt","r"); printf("请输入你要查找的书名\n"); scanf("%s",bookname); for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++) { if(strcmp(bookname,book[i].bookname)==0) { if(book[i].turefalse==1) { printf("这本书的详细资料是:%d %s %s 此书现在无人借阅\n按任意键返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat); } else {printf("这本书已经有人借出\n");fclose(fp);return 0;} fclose(fp); return FALSE; } } printf("没有你要查询的书籍\n"); fclose(fp); return FALSE; } findbook1() { FILE *fp; char bookcreat[10]; int ture,i; fp=fopen("book.txt","r"); printf("请输入你要查找的作者名\n"); scanf("%s",bookcreat); for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++) { if(strcmp(bookcreat,book[i].bookcreat)==0) { if(book[i].turefalse==1) { printf("这本书的详细资料是:%d %s %s 此书现在无人借阅\n按任意键返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat); } else {printf("这本书已经有人借出\n");fclose(fp);return 0;} fclose(fp); return FALSE; } } printf("没有你要查询的书籍\n"); fclose(fp); return FALSE; } lendcount() { FILE *fp; int i,n=0; fp=fopen("record.txt","r"); for(i=0;fread(&student[i],sizeof(struct student),1,fp)!=0;i++) { printf("卡号:%d 借出的书籍:%s \n",student[i].carnum,student[i].lendbook); n=n+1; } fclose(fp); printf("目前共有%d本书借出\n",n); printf("按任意键\n"); getch(); return n; } chabook() { char ch5; do { printf("---------------欢迎进入图书查询系统!--------------\n"); printf(" 1:<按书名查找>\n"); printf(" 2:<按作者查找>\n"); printf(" 0:<返回>\n"); printf("请输入0--2,其他输入非法!\n"); scanf("%s",&ch5); switch(ch5) { case '1':findbook();getch();break; case '2':findbook1();getch();break; case '0':break; default:printf("无此操作\n");getch();break; } }while(ch5!='0'); return FALSE; } lendbook() { FILE *fp,*fp2; int i,n; int carnum; printf("请你输入你的卡号\n"); scanf("%d",&carnum); fp=fopen("car.txt","r"); for(i=0;fread(&car[i],sizeof(struct car),1,fp)!=0;i++) { if(car[i].carnum==carnum) { n=i; fclose(fp); printf("请输入你要借阅的书的名字\n"); scanf("%s",student[n].lendbook); fp=fopen("book.txt","r"); for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++) { if(strcmp(book[i].bookname,student[n].lendbook)==0) { if(book[i].turefalse==0) {printf("对不起,此书有人借出,请借其他书\n");fclose(fp);getch();return;} else fclose(fp); fp=fopen("record.txt","a+"); student[n].carnum=carnum; fwrite(&student[n],sizeof(struct student),1,fp); fclose(fp); fp=fopen("book.txt","r"); fp2=fopen("bookl.txt","w"); for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++) { if(strcmp(book[i].bookname,student[n].lendbook)==0) { book[i].turefalse=0; fwrite(&book[i],sizeof(struct book),1,fp2); continue; } fwrite(&book[i],sizeof(struct book),1,fp2); } fclose(fp); fclose(fp2); fp=fopen("book.txt","w"); fp2=fopen("bookl.txt","r"); for(i=0;fread(&book[i],sizeof(struct book),1,fp2)!=0;i++) { fwrite(&book[i],sizeof(struct book),1,fp); } fclose(fp); fclose(fp2); fopen("bookl.txt","w"); fclose(fp2); printf("借书完毕,按任意键返回\n"); getch(); return; } } printf("不存在这样的书,任意键返回\n"); fclose(fp); getch(); return; } } printf("你的卡号不存在,请申请新卡,按任意键返回\n"); fclose(fp); getch(); } carcount() { FILE *fp; int i,n=0; fp=fopen("car.txt","r"); for(i=0;fread(&car[i],sizeof(struct car),1,fp)!=0;i++) { printf("第%d张卡<卡号:%d 姓名:%s 班级:%d>\n",i+1,car[i].carnum,car[i].studentname,car[i].studentclass); n=n+1; } fclose(fp); printf("目前共有%d本书\n",n); printf("按任意键\n"); getch(); } delcar() { FILE *fp,*fp2; int i; int carnum; char choice; fp=fopen("car.txt","r"); fp2=fopen("bookl.txt","w"); printf("请输入你要删除的卡号\n"); printf("如果你输入的卡号存在,系统自动删除该信息!如果不存在,系统不做任何改动\n"); scanf("%d",&carnum); for(i=0;fread(&car[i],sizeof(struct car),1,fp)!=0;i++) { if(car[i].carnum!=carnum) { fwrite(&car[i],sizeof(struct car),1,fp2); } } fclose(fp); fclose(fp2); printf("是否真的要删除该卡?删除后该书籍的所有信息将无法恢复《Y/N》\n"); scanf("%s",&choice); if(choice=='y'||choice=='Y') { fp=fopen("car.txt","w"); fp2=fopen("bookl.txt","r"); for(i=0;fread(&car[i],sizeof(struct car),1,fp2)!=0;i++) { fwrite(&car[i],sizeof(struct car),1,fp); } fclose(fp); fclose(fp2); fp2=fopen("bookl.txt","w"); fclose(fp2); printf("按任意键返回\n"); getch(); return; } else { printf("按任意键返回\n"); getch(); return; } } addcar() { FILE *fp; int i=0; fp=fopen("car.txt","a+"); printf("请你输入卡号\n"); scanf("%d",&car[i].carnum); printf("请你输入学生姓名\n"); scanf("%s",car[i].studentname); printf("请你输入班级\n"); scanf("%d",&car[i].studentclass); fwrite(&car[i],sizeof(struct car),1,fp); fclose(fp); printf("输入完毕,任意键返回\n"); getch(); }

⑤ 谁有图书管理系统的源代码

如果你需要这样的毕业设计,你可以到大学生计算机论坛cccbbs的毕业设计范例版找找

⑥ 图书管理系统图书分类源代码

我有管理系统图书分类源代码

⑦ 用C++编写图书管理系统(源代码)

这个由于你给的分太少,估计每人会给你做的。
我给你一个做参照吧,基本功能都已经实现了,并且在VC6上已经编译运行确认:

#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:
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() 函数的实现,程序的主界面的引导

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<<"输入错误,请从新输入:";

}
}
}

java图书管理系统的源代码

是要B/S模式的 还是swing界面开发的?你要说清楚。

热点内容
服务器的空岛如何刷钱 发布:2024-11-15 09:40:52 浏览:262
安卓系统录像设置在哪里 发布:2024-11-15 09:36:33 浏览:917
电信级服务器电脑 发布:2024-11-15 09:26:27 浏览:246
压缩某个文件夹 发布:2024-11-15 09:03:11 浏览:891
网址能解压吗 发布:2024-11-15 08:54:09 浏览:933
python更改目录 发布:2024-11-15 08:41:08 浏览:265
服务器闪存可以装在一般电脑上吗 发布:2024-11-15 08:36:46 浏览:8
安卓手机怎么查询自己的路线轨迹 发布:2024-11-15 08:32:19 浏览:969
phpdatet 发布:2024-11-15 08:32:17 浏览:507
HDB3编译码实验 发布:2024-11-15 08:17:31 浏览:212