管理系統(tǒng)程序是一個(gè)偏長(zhǎng)的c語(yǔ)言程序,其中包含的函數(shù)公式涉及面很廣,令人難以捉摸。
公司主營(yíng)業(yè)務(wù):網(wǎng)站制作、成都做網(wǎng)站、移動(dòng)網(wǎng)站開(kāi)發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競(jìng)爭(zhēng)能力。成都創(chuàng)新互聯(lián)公司是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開(kāi)放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對(duì)我們的高要求,感謝他們從不同領(lǐng)域給我們帶來(lái)的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來(lái)驚喜。成都創(chuàng)新互聯(lián)公司推出立山免費(fèi)做網(wǎng)站回饋大家。
1、順應(yīng)時(shí)代發(fā)展要求
2、技術(shù)先進(jìn)
3、功能強(qiáng)大
4、高度靈活性
5、高度安全性
6、讀者自助服務(wù)
7、簡(jiǎn)單易用
#include
#include
#include
#include
#include
#define STACK_INIT_SIZE 10
#define OK 1
#define TRUE 1
#define ERROR 0
/*定義學(xué)生類型,用于存放借出的書(shū)籍*/
struct student {
int carnum;
char lendbook[10];
}student[1000];
/*定義書(shū)的類型*/
struct book
{
int booknum;
char bookname[20];
float bookprice;
char bookcreat[20];
int turefalse; /*用于借書(shū)和還書(shū)模塊判斷一本書(shū)是否借出的條件*/
}book[1000];
/*借書(shū)卡的數(shù)據(jù)類型*/
struct car
{
int carnum;
char sex[5];
char studentname[20];
int studentclass;
}car[1000];
/*查詢圖書(shū)信息模塊*/
/*(1)按書(shū)名查找*/
findbook()
{
FILE *fp;
char bookname[10];
int i;
fp=fopen("book.txt","r");
printf("請(qǐng)輸入你要查找的書(shū)名:\n");
scanf("%s",bookname);
for(i=0;fread(&book[i],sizeof(structbook),1,fp)!=0;i++)
{
if(strcmp(bookname,book[i].bookname)==0)
{
if(book[i].turefalse==1)
{
printf(" 書(shū)號(hào) 書(shū)名 作者 \n %d %s %s \n",book[i].booknum,book[i].bookname,book[i].bookcreat);
printf("此書(shū)現(xiàn)在無(wú)人借閱\n按任意鍵返回\n");}
else {printf("這本書(shū)已經(jīng)有人借出\n");fclose(fp);return 0;}
fclose(fp);
return 0;
}
}
printf("抱歉無(wú)此書(shū)!\n");
fclose(fp);
return 0;
}
/*(2)按作者查找*/
findbook1()
{
FILE *fp;
char bookcreat[10];
int i;
fp=fopen("book.txt","r");
printf("請(qǐng)輸入作者名:\n");
scanf("%s",bookcreat);
for(i=0;fread(&book[i],sizeof(structbook),1,fp)!=0;i++)
{
if(strcmp(bookcreat,book[i].bookcreat)==0)
{
if(book[i].turefalse==1)
{
printf(" 書(shū)號(hào) 書(shū)名 作者\(yùn)n %d %s %s\n",book[i].booknum,book[i].bookname,book[i].bookcreat);
printf("此書(shū)現(xiàn)在無(wú)人借閱\n按任意鍵返回\n");
}
else {printf("此書(shū)已借出!\n");fclose(fp);
return 0;
}
fclose(fp);
return 0;
}
}
printf("沒(méi)有此書(shū)籍\n");
fclose(fp);
return 0;
}
chabook()/*查找圖書(shū)主模塊 */
{
char ch6;
do
{
printf("?。。g迎進(jìn)入圖書(shū)查詢系統(tǒng)?。?!\n");
printf(" 1: 按書(shū)名查找\n");
printf(" 2: 按作者查找\n");
printf(" 0: 返回\n");
printf("請(qǐng)輸入0━2:\n");
ch6=getch();
switch(ch6)
{
case '1':findbook();getch();break;
case '2':findbook1();getch();break;
case '0':break;
default:printf("無(wú)此操作!\n");getch();break;
}
}while(ch6!='0');
return 0;
}
/*借書(shū)與還書(shū)模塊*/
/*(1).借書(shū)模塊*/
lendbook()
{
FILE *fp,*fp2;
int i,n;
int carnum;
system("cls");
printf("\t\t*****歡迎進(jìn)入借書(shū)系統(tǒng)*****\n\n");
printf("請(qǐng)輸入借書(shū)人的:\n卡號(hào):\n");
scanf("%d",&carnum);
fp=fopen("car.txt","r");
for(i=0;fread(&car[i],sizeof(structcar),1,fp)!=0;i++)
{
if(car[i].carnum==carnum)
{
n=i;
fclose(fp);
printf("書(shū)名:\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("對(duì)不起,此書(shū)有人借出,請(qǐng)借其他書(shū)\n");fclose(fp);getch();return0;}
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("借書(shū)完畢,按任意鍵返回...\n");
getch();
return 0;
}
}
printf("不存在這樣的書(shū),任意鍵返回...\n");
fclose(fp);
getch();
return 0;
}
}
printf("你的卡號(hào)不存在,請(qǐng)申請(qǐng)新卡,按任意鍵返回...\n");
fclose(fp);
getch();
return 0;}
/*(2).還書(shū)函數(shù)*/
huanbook()
{
FILE *fp,*fp2; /*定義兩個(gè)文件指針,fp2用于修改數(shù)據(jù)時(shí)設(shè)立臨時(shí)文件用,防止數(shù)據(jù)遭破壞*/
int i,n;
int carnum;
char lendbook[10];
system("cls");
printf("\t\t@@@@歡迎進(jìn)入還書(shū)界面@@@@");
printf("\n請(qǐng)你輸入你的\n卡號(hào):\n");
scanf("%d",&carnum);
fp=fopen("car.txt","r");/*讀取卡號(hào)記錄*/
for(i=0;fread(&car[i],sizeof(structcar),1,fp)!=0;i++) /*for循環(huán)判斷卡號(hào)是否存在*/
{
if(car[i].carnum==carnum) /*卡號(hào)存在,進(jìn)入下一循環(huán)*/
{
n=i;
fclose(fp);
printf("請(qǐng)輸入你要還的書(shū)的名字:\n");
scanf("%s",lendbook);
fp=fopen("record.txt","r");
for(i=0;fread(&student[i],sizeof(struct student),1,fp)!=0;i++) /*判斷是否借閱了輸入的書(shū)*/
{
if(strcmp(student[i].lendbook,lendbook)==0) /*借閱了該書(shū),進(jìn)入下一循環(huán),否則出錯(cuò)顯示*/
{
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; /*刪除還掉的書(shū)的借書(shū)記錄*/
}
fwrite(&student[i],sizeof(struct student),1,fp2); /*寫(xiě)入原來(lái)沒(méi)還的書(shū)的記錄*/
}
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); /*將借書(shū)記錄信息寫(xiě)回*/
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w"); /*清臨時(shí)文件的記錄*/
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++) /*將書(shū)的記錄寫(xiě)入臨時(shí)文件,防止因?yàn)樾薷男畔⑵茐囊郧暗挠涗?/
{
if(i==n)
{
book[i].turefalse=1;
fwrite(&book[i],sizeof(struct book),1,fp2); /*將還的書(shū)的原來(lái)狀態(tài)設(shè)為無(wú)人借閱的*/
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); /*將臨時(shí)文件寫(xiě)回*/
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w"); /*清臨時(shí)文件*/
fclose(fp2);
printf("還書(shū)完畢,按任意鍵返回...\n");
getch();
return 1;
}
}
printf("你沒(méi)有借這樣的書(shū),任意鍵返回...\n"); /*出錯(cuò)提示*/
fclose(fp);
getch();
return 0;
}
}
printf("沒(méi)這樣的卡,和管理員聯(lián)系,按任意鍵返回...\n"); /*出錯(cuò)提示*/
fclose(fp);
getch();
return 0;}
/*(3).借書(shū)統(tǒng)計(jì)*/
lendcount()
{
FILE *fp;
int i,n=0;
fp=fopen("record.txt","r");
for(i=0;fread(&student[i],sizeof(structstudent),1,fp)!=0;i++)
{
printf("卡號(hào) 借出的書(shū)籍 \n");
printf("%d %s\n",student[i].carnum,student[i].lendbook);
n=n+1;
}
fclose(fp);
printf("目前共有%d本書(shū)借出\n",n);
printf("按任意鍵...\n");
getch();
return n;
}
/*會(huì)員卡管理模塊*/
/*(1).增加會(huì)員卡*/
addcar()
{
FILE *fp;
int i=0;
fp=fopen("car.txt","a+");
printf("卡號(hào):\n");
scanf("%d",&car[i].carnum);
printf("性別:\n");
scanf("%s",car[i].sex);
printf("姓名:\n");
scanf("%s",car[i].studentname);
printf("班級(jí):\n");
scanf("%d",&car[i].studentclass);
fwrite(&car[i],sizeof(structcar),1,fp);
fclose(fp);
printf("輸入完畢,任意鍵返回...\n");
getch();
}
/*(2).刪除會(huì)員卡*/
delcar()
{
FILE *fp,*fp2;
int i;
int carnum;
char choice;
fp=fopen("car.txt","r");
fp2=fopen("bookl.txt","w");
printf("要?jiǎng)h除的卡號(hào)(不存在則不作改動(dòng)):\n");
scanf("%d",&carnum);
for(i=0;fread(&car[i],sizeof(structcar),1,fp)!=0;i++)
{
if(car[i].carnum!=carnum)
{
fwrite(&car[i],sizeof(struct car),1,fp2);
}
}
fclose(fp);
fclose(fp2);
printf("確認(rèn)刪除?(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按任意鍵返回...\n");
getch();
return 0;
}
else
{
printf("操作已取消!\n按任意鍵返回...\n");
getch();
return 0;
}
}
/*(3).會(huì)員卡統(tǒng)計(jì)*/
carcount()
{
FILE *fp;
int i,n=0;
fp=fopen("car.txt","r");
for(i=0;fread(&car[i],sizeof(structcar),1,fp)!=0;i++)
{
printf("第%d張卡 \n",i+1);
printf("卡號(hào) 性別 姓名 班級(jí) \n");
printf(" %d %5s %10s %3d\n\n",car[i].carnum,car[i].sex,car[i].studentname,car[i].studentclass);
n=n+1;
}
fclose(fp);
printf("目前共有%d個(gè)會(huì)員。\n",n);
printf("按任意鍵返回...\n");
getch();
}
/*圖書(shū)管理模塊*/
/*(1).增加圖書(shū)信息*/
addbook()
{
FILE *fp;
int i=0;
char choice='y';
fp=fopen("book.txt","a+");
while(choice=='y'||choice=='Y')
{
printf("書(shū)號(hào):\n");
scanf("%d",&book[i].booknum);
printf("書(shū)名:\n");
scanf("%s",book[i].bookname);
printf("作者:\n");
scanf("%s",book[i].bookcreat);
printf("單價(jià):\n");
scanf("%f",&book[i].bookprice);
printf("請(qǐng)你設(shè)定書(shū)的狀態(tài)(1在架/0不在):\n");
scanf("%d",&book[i].turefalse);
fwrite(&book[i],sizeof(struct book),1,fp);
printf("是否要輸入下本書(shū)(y/n)\n");
scanf("%s",&choice);
}
fclose(fp);
}
/*(2).刪除圖書(shū)信息*/
delbook()
{
FILE *fp,*fp2;
int i;
char bookname[10],choice;
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
printf("書(shū)名:\n");
scanf("%s",bookname);
for(i=0;fread(&book[i],sizeof(structbook),1,fp)!=0;i++)
{
if(strcmp(bookname,book[i].bookname)!=0)
{
fwrite(&book[i],sizeof(struct book),1,fp2);
}
}
fclose(fp);
fclose(fp2);
printf("確認(rèn)刪除(y/n)?\n");
scanf("%s",&choice);
if(choice=='y'||choice=='Y')
{
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);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意鍵返回...\n");
getch();
return 0;
}
else
{
printf("按任意鍵返回...\n");
getch();
return 0;
}
}
/*(3)修改圖書(shū)*/
changebook()
{
FILE *fp,*fp2;
char bookname[10],choice;
int i;
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
printf("書(shū)名:\n");
scanf("%s",bookname);
for(i=0;fread(&book[i],sizeof(structbook),1,fp)!=0;i++)
{
if(strcmp(book[i].bookname,bookname)==0)
{
printf("你所要修改的書(shū)的資料如下,請(qǐng)選擇你要修改的內(nèi)容:\n");
printf("序號(hào) 書(shū)名 作者 \n");
printf("%d %s %s\n",book[i].booknum,book[i].bookname,book[i].bookcreat); printf("1:修改書(shū)號(hào):\n");
printf("2: 修改書(shū)名:\n");
printf("3: 修改作者:\n");
printf("4: 修改單價(jià):");
printf("請(qǐng)輸入1━3:");
choice=getch();
switch(choice)
{
case '1':
{
printf("新書(shū)號(hào):\n");
scanf("%d",&book[i].booknum);
fwrite(&book[i],sizeof(struct book),1,fp2);
}break;
case '2':
{
printf("新書(shū)名:\n");
scanf("%s",book[i].bookname);
fwrite(&book[i],sizeof(struct book),1,fp2);
}break;
case '3':
{
printf("新的作者:\n");
scanf("%s",book[i].bookcreat);
fwrite(&book[i],sizeof(struct book),1,fp2);
}break;
case '4':
{
printf("新的單價(jià):");
scanf("%f",book[i].bookprice);
fwrite(&book[i],sizeof(struct book),1,fp2); }
default:printf("沒(méi)有這樣的操作!");break;
}
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(structbook),1,fp2)!=0;i++)
{
fwrite(&book[i],sizeof(struct book),1,fp);
}
fclose(fp);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意鍵返回...\n");
getchar();
return 0;
}
/*(4).圖書(shū)統(tǒng)計(jì)*/
bookcount()
{
FILE *fp;
int i,n=0;
fp=fopen("book.txt","r");
for(i=0;fread(&book[i],sizeof(structbook),1,fp)!=0;i++)
{
if(book[i].booknum!=0&&strlen(book[i].bookname)!=0&&strlen(book[i].bookcreat)!=0)
{
printf("第%d本書(shū)\n序號(hào) 書(shū)名 作者 單價(jià) 狀態(tài) \n",i+1);
printf(" %d %10s ",book[i].booknum,book[i].bookname);
printf("%15s %4.2f %d(1在/0不在)\n",book[i].bookcreat,book[i].bookprice,book[i].turefalse);n=n+1;
}
}
fclose(fp);
printf("目前共有%d本書(shū).\n",n);
printf("按任意鍵返回...\n");
}
/*結(jié)束界面函數(shù)*/
end()
{ system("cls");
printf("\t\t********************************\n");
printf("\t\t********************************\n");
printf("\t\t**** 謝謝使用本系統(tǒng) , 再見(jiàn)! ****\n");
printf("\t\t********************************\n");
printf("\t\t********************************\n");
}
/*主函數(shù)*/
main()
{
char ch2,ch3,ch5;
do
{ system("cls");
printf("\t\t********************************\n");
printf("\t\t********************************\n");
printf("\t\t***** 歡迎進(jìn)入圖書(shū)管理系統(tǒng) *****\n");
printf("\t\t********************************\n");
printf("\t\t********************************\n");
printf(" 請(qǐng)選擇:\n");
printf(" 1:查閱圖書(shū) \n");
printf(" 2:借閱圖書(shū) \n");
printf(" 3:管理系統(tǒng) \n");
printf(" 4:還書(shū) \n");
printf(" 0:退出 \n");
printf("請(qǐng)輸入0━4:\n");
ch2=getch();
switch(ch2)
{
case '1':chabook();break;
case '2':lendbook();;break;
case '3':{
do
{
system("cls");
printf("\t\t*******歡迎進(jìn)入管理系統(tǒng)*******\n");
printf(" 1:增加圖書(shū) \n");
printf(" 2:刪除圖書(shū) \n");
printf(" 3:修改圖書(shū) \n");
printf(" 4:圖書(shū)統(tǒng)計(jì) \n");
printf(" 5:會(huì)員管理系統(tǒng) \n");
printf(" 0:返回 \n");
printf("請(qǐng)輸入0━5:\n");
ch3=getch();
switch(ch3)
{
case '1':addbook();
break;
case '2':delbook();break;
case '3':changebook();break;
case '4':bookcount();getch();break;
case '5':{
do
{
system("cls");
printf("\t\t····歡迎進(jìn)入學(xué)生管理系統(tǒng)····\n");
printf(" 1: 申請(qǐng)新卡\n");
printf(" 2: 刪除卡號(hào)\n");
printf(" 3: 借書(shū)統(tǒng)計(jì)\n");
printf(" 4: 卡號(hào)統(tǒng)計(jì)\n");
printf(" 0: 返回\n");
printf("請(qǐng)輸入0━4:\n");
ch5=getch();
switch(ch5)
{
case '1':addcar();break;
case '2':delcar();break;
case '3':lendcount();break;
case '4':carcount();break;
case '0':break;
default:printf("無(wú)此操作!\n");getch();break;
}
}while(ch5!='0');}break;
case '0':break;
default:printf("無(wú)此操作!\n");getch();break;
}
} while(ch3!='0');}break;
case '4':huanbook();break;
case '0':break;
default:printf("無(wú)此操作!\n");getch();break;
}
}while(ch2!='0');
}