c图书馆管理系统源码_图书馆管理系统c#

hacker|
106

文章目录:

用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;iMaxbor;i++)

borbook[i]=0;

}

//借书操作

void borrowbook(int bookid)

{

for(int i=0;iMaxbor;i++)

{

if (borbook[i]==0)

{

borbook[i]=bookid;

return;

}

}

}

//还书操作

int retbook(int bookid)

{

for(int i=0;iMaxbor;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;iMaxbor;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图 书 维 护 "endlendl;

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 endlendl"\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语言编写的图书管理系统源代码

#includestdio.h

#includestring.h

#includeconio.h

#includestdlib.h

#includectype.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();

}

c语言 图书管理系统 源代码

#include

#include

#include

#include

#include

struct book{

char number[100];

char tittle[100];

char writer[100];

char publisher[100];

char date[100];

char price[100];

char status[100];

char reader[100];

};

void search_book();

void borrow_book();

void return_book();

void add_book();

void delete_book();

void modify_book();

void scan_book();

int main()

{

int c1=0,c2,c3;

int l,x,z;

while(1)

{

system("color 2C");

printf("\t\t\t ^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");

printf("\t\t\t| * - * - * -图书管理系统 * - * - * |\n");

printf("\t\t\t* [1] 用户登录 *\n");

printf("\t\t\t* [2] 管理员登录 *\n");

printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");

printf("\n");

printf("请选择操作 :");

scanf("%d",c1);

system("cls");

break;

}

if(c1==1)

{

while(1){

system("color 2C");

printf("\t\t\t ^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");

printf("\t\t\t| * - * - * -图书管理系统 * - * - * |\n");

printf("\t\t\t* [1] 查询图书 *\n");

printf("\t\t\t| [2] 借阅图书 |\n");

printf("\t\t\t* [3] 借图书 *\n");

printf("\t\t\t* [4] 浏览图书信息 *\n");

printf("\t\t\t| [5] 退图书管理系统 |\n");

printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");

printf("\n");

printf("请选择操作 :");

scanf("%d",c2);

getchar();

switch(c2)

{

case 1:search_book(); break;

case 2:borrow_book(); break;

case 3:return_book(); break;

case 4:scan_book(); break;

case 5:system("cls"); return 0;

}

}

}

if(c1==2)

{

while(1){

system("color 2C");

printf("\t\t\t ^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");

printf("\t\t\t| * - * - * -图书管理系统 * - * - * |\n");

printf("\t\t\t| [1] 添加图书 |\n");

printf("\t\t\t* [2] 删减图书 *\n");

printf("\t\t\t| [3] 修改图书信息 |\n");

printf("\t\t\t* [4] 浏览图书信息 *\n");

printf("\t\t\t| [5] 退图书管理系统 |\n");

printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");

printf("\n");

printf("请选择操作 :");

scanf("%d",c3);

getchar();

switch(c3)

{

case 1:add_book(); break;

case 2:delete_book(); break;

case 3:modify_book(); break;

case 4:scan_book(); break;

case 5:system("cls"); return 0;

}

}

}

}

/*查询图书*/

void search_book()

{

FILE*fp;

struct book n;

struct book nn;

int l,r;

char x,z;

fp=fopen("F:\\课程设计\\图书管理系统.txt","rb");

while(1)

{

l=0;

system("cls");

printf("请输入图书名称:");

scanf("%s",n.tittle);

fflush(stdin);

rewind(fp);

while(1)

{

fread(nn,sizeof(nn),1,fp);

if(feof(fp))

break;

r=strcmp(n.tittle,nn.tittle );

if(r==0)

{

l=1;

break;

}

}

if(l==0)

{

printf("没要查询图书\n\n ");

}

else

{

printf("查询图书:");

printf("\n");

printf("****************************************\n");

printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n");

printf("\n");

printf("%s %s %s %s %s %s %s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);

printf("\n\n\n");

}

printf("否继续查询图书 ? [(y)/否(n)] ? \n\n");

do

{

x=getche();

}while(x!='n'x!='y');

if(x=='n')

break;

}

fclose(fp);

system("cls");

}

//添加

void add_book()

{

FILE *fp;

struct book n;

struct book nn;

char x,z;

int l,r;

fp=fopen("F:\\课程设计\\图书管理系统.txt","ab+");

do

{

system("cls");

do

{

l=0;

printf("\n");

printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n");

fflush(stdin);

scanf("%s %s %s %s %s %s %s %s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);

system("cls");

rewind(fp);

while(!feof(fp))

{

fread(nn,sizeof(nn),1,fp);

r=strcmp(n.tittle,nn.tittle);

if(r==0)

{

l=1;

printf(" 该图书已存请输入新图书信息: \n\n");

break;

}

}

}while(l);

fwrite(n,sizeof(n),1,fp);

printf("\n");

printf("否继续输入新图书信息[y/n] \n\n");

do

{

x=getche();

}while(x!='n'x!='y');

}while(x=='y');

fclose(fp);

system("cls");

}

//删除图书

void delete_book()

{

FILE *fp,*fp1;

char x,z;

struct book n;

struct book nn;

int l,r;

fp=fopen("F:\\课程设计\\图书管理系统.txt","ab+");

while(1)

{

l=0;

system("cls");

printf("\n");

printf("请输入需要删除图书名: \n\n");

fflush(stdin);

scanf("%s",n.tittle);

rewind(fp);

while(1)

{

fread(nn,sizeof(nn),1,fp);

if(feof(fp))

break;

r=strcmp(n.tittle,nn.tittle);

if(r==0)

{

l=1;

break;

}

}

if(l==0)

{

printf("\n");

printf("起未找该图书 \n");

}

else

{

printf("\n");

printf("****************************************\n");

printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n");

printf("\n");

printf("%s %s %s %s %s %s %s %s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);

printf("\n");

printf("确认删除图书信息 [(y)/否(n)]\n\n");

do

{

z=getche();

}while(z!='n'z!='y');

if(z=='n')

break;

else

{

fp1=fopen("F:\\课程设计\\图书管理系统new.txt","wb");

rewind(fp);

while(1)

{

fread(nn,sizeof(nn),1,fp);

if(feof(fp))

break;

r=strcmp(n.tittle,nn.tittle);

if(r!=0)

fwrite(nn,sizeof(nn),1,fp1);

}

fclose(fp);

fclose(fp1);

fp=fopen("F:\\课程设计\\图书管理系统.txt","wb");

fp1=fopen("F:\\课程设计\\图书管理系统new.txt","rb");

while(1)

{

fread(nn,sizeof(nn),1,fp1);

if(feof(fp1))

break;

fwrite(nn,sizeof(nn),1,fp);

}

fclose(fp);

fclose(fp1);

}

}

printf("\n");

printf("否继续删除图书信息 [(y)/否(n)] \n");

do

{

x=getche();

}while(x!='n'x!='y');

if(x=='n')

break;

}

fclose(fp);

system("cls");

}

//修改图书信息

void modify_book()

{

FILE *fp;

struct book n;

struct book nn;

int l,r;

char x,z;

fp=fopen("F:\\课程设计\\图书管理系统.txt","rb+");

while(1)

{

l=0;

printf("\n");

system("cls");

printf("请输入需要修改图书名: \n\n");

fflush(stdin);

scanf("%s",n.tittle);

system("cls");

rewind(fp);

while(1)

{

fread(nn,sizeof(nn),1,fp);

if(feof(fp))

break;

r=strcmp(n.tittle,nn.tittle);

if(r==0)

{

l=1;

break;

}

}

if(l==0)

{

printf("\n");

printf("起未找该图书信息 \n\n");

}

else

{

printf("\n");

printf("****************************************\n");

printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n");

printf("\n");

printf("%s %s %s %s %s %s %s %s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);

printf("请依修改图书信息\n\n\n");

fflush(stdin);

scanf("%s %s %s %s %s %s %s %s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);

fseek(fp,sizeof(nn),1);

fwrite(n,sizeof(nn),1,fp);

}

printf("\n");

printf(" 否继续修改用户信息[y/n]? \n\n");

do

{

x=getch();

}while(x!='n'x!='y');

if(x=='n')

break;

}

fclose(fp);

system("cls");

}

//借书

void borrow_book()

{

FILE*fp;

struct book n;

struct book nn;

char x,z;

int l,r;

fp=fopen("F:\\课程设计\\图书管理系统.txt","rb+");

while(1)

{

l=0;

system("cls");

printf("\n");

printf("请输入需要借阅图书名: \n");

fflush(stdin);

scanf("%s",n.tittle);

rewind(fp);

while(1)

{

fread(nn,sizeof(nn),1,fp);

if(feof(fp))

break;

r=strcmp(n.tittle,nn.tittle);

if(r==0)

{

l=1;

break;

}

}

if(l==0)

{

printf("\n");

printf("起未找该图书 \n");

}

else

{ printf("\n");

printf("****************************************\n");

printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n");

printf("\n");

printf("%s %s %s %s %s %s %s %s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);

printf("\n");

fflush(stdin);

printf("请输入图书信息并修改库状态及借阅者信息");

printf("****************************************\n");

printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n");

printf("\n");

scanf("%s %s %s %s %s %s %s %s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);

fseek(fp,sizeof(nn),1);

fwrite(n,sizeof(nn),1,fp);

}

printf("\n");

printf(" 否继续借书 [(y)/否(n)] \n\n");

do

{

x=getch();

}while(x!='n'x!='y');

if(x=='n')

break;

}

fclose(fp);

system("cls");

}

//书

void return_book()

{

FILE*fp;

struct book n;

struct book nn;

char x,z;

int l,r;

fp=fopen("F:\\课程设计\\图书管理系统.txt","rb+");

while(1)

{

l=0;

system("cls");

printf("\n");

printf("请输入需要借图书名: \n");

fflush(stdin);

scanf("%s",n.tittle);

rewind(fp);

while(1)

{

fread(nn,sizeof(nn),1,fp);

if(feof(fp))

break;

r=strcmp(n.tittle,nn.tittle);

if(r==0)

{

l=1;

break;

}

}

if(l==0)

{

printf("\n");

printf("起未找该图书 \n");

}

else

{

printf("\n");

printf("****************************************\n");

printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n");

printf("\n");

printf("%s %s %s %s %s %s %s %s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);

printf("\n");

fflush(stdin);

printf("请输入图书信息并修改库状态 \n\n");

printf("****************************************\n");

printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n");

printf("\n");

scanf("%s %s %s %s %s %s %s %s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);

fseek(fp,-(int)sizeof(nn),1);

fwrite(n,sizeof(nn),1,fp);

}

printf("\n");

printf("否继续书 [(y)/否(n)] \n");

do

{

x=getche();

}while(x!='n'x!='y');

if(x=='n')

break;

}

fclose(fp);

system("cls");

}

//浏览

void scan_book()

{

FILE*fp;

char x,z;

struct book n;

fp=fopen("F:\\课程设计\\图书管理系统.txt","rb");

rewind(fp);

system("cls");

while(1)

{

fread(n,sizeof(n),1,fp);

if(feof(fp))

break;

else

{

printf("********************************************\n");

printf("编号 书名 作者 版社 版间 价格 状态 借阅者\n");

printf("\n");

printf("%s %s %s %s %s %s %s %s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);

printf("\n");

}

}

printf("\n");

printf("主菜单请按车");

do

{

x=getche();

}while(x!='\r');

if(x=='\r')

{

fclose(fp);

system("cls");

}

}

5条大神的评论

  • avatar
    访客 2022-07-09 上午 03:54:56

    "借书编号:["; for(int i=0;iMaxbor;i++) if(borbook[i]!=0) cout borbook[i] "|"; co

  • avatar
    访客 2022-07-09 上午 05:10:00

    read(nn,sizeof(nn),1,fp); if(feof(fp))break;r=strcmp(n.tittle,nn.tittle);if(r==0){l=1;break;}}if(l==0){printf("\n");printf("起未

  • avatar
    访客 2022-07-09 上午 07:09:27

    int borbook[Maxbor]; public: Reader() { ; } //获取姓名 char *getname() { return name; } //获取删除标记 int gettag() { return tag; }

  • avatar
    访客 2022-07-09 上午 05:02:47

    rn NULL; } //输出所有读者信息 void disp() { for (int i=0;i=top;i++) read[i].disp(); } //读者库维护 void readerdata(); //析构函数,将read[]写到reader.txt文件中 ~RD

  • avatar
    访客 2022-07-09 上午 07:43:28

    n,sizeof(n),1,fp); printf("\n");printf("否继续输入新图书信息[y/n] \n\n");do{x=getche();}while(x!='n'x!='y');}while(x=='y');fclose(fp); system("cls");}

发表评论