真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

C語言圖書統(tǒng)計(jì)函數(shù) c語言 圖書館

急~c語言圖書管理

#includestdio.h

網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、成都微信小程序、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了始興免費(fèi)建站歡迎大家使用!

#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 /*定義學(xué)生類型,用于存放借出的書籍*/

{

int studentnum,phonenum;

char lendbook[10];

}student[1000];

struct book /*定義書的類型*/

{

char bookname[11];

char publisher[20];

char page;

char year[6];

char status[4];

char name[11];

char author[51];

char booknum;

char bookcreat[10];

char borrownum;

char turefalse; /*用于借書和還書模塊判斷一本書是否借出的條件*/

}book[1000];

struct car /*借書卡的數(shù)據(jù)類型*/

{

int carnum;

char studentname[10];

int studentclass;

int studentphone;

}car[100];

addcar()

{

FILE *fp;

int i=0;

double allnum,stillbook,outbook,allmoney,avemoney;

fp=fopen("car.txt","a+");

printf("請你輸入學(xué)生姓名\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");

fp=fopen("book.txt","r");

avemoney=allmoney/allnum;

fclose(fp);

printf("書籍總數(shù):%ld,已借出的書籍:%ld,在館的書籍:%ld,書籍貫總金額:%ld,書籍平均價(jià)格:%ld",

stillbook,outbook,allmoney,avemoney);

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張卡卡號(hào):%d 姓名:%s 班級:%d 手機(jī)號(hào)碼:%d\n",

i+1,car[i].carnum,car[i].studentname,car[i].studentclass,car[i].studentphone);

n=n+1;

}

fclose(fp);

printf("目前共有%d本書\n",n);

printf("按任意鍵\n");

getch();

}

void findbook()

{

FILE *fp;

char bookname[10];

int ture,i,booknum;

fp=fopen("book.txt","r");

printf("請輸入你要查找的booknum");

scanf("%d",booknum);

for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)

{

if(strcmp(booknum,book[i].booknum)==0)

{

if(book[i].turefalse==1)

printf("這本書的詳細(xì)資料是:%d %s %s 此書現(xiàn)在無人借閱\n按任意鍵返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat);

else

fclose(fp);

return FALSE;

}

else

printf("沒有你要查詢的書籍\n");

fclose(fp);}

return FALSE;

}

void borrowbook(struct book *m) //借閱圖書函數(shù)

{

int num;

struct book *b, *b1;

printf("輸入要借書的編碼:");

scanf("%d",num);

b = searchbook(num); /*調(diào)用查找圖書結(jié)點(diǎn)函數(shù)*/

if(b != NULL)

{

if(m-borrownum 10)

{

// b-status = '0';

// b1 = m-book[m-borrownum];

strcpy(b1-name,b-name);

strcpy(b1-author,b-author);

b1-booknum = b-booknum;

strcpy(b1-year,b-year);

b1-page = b-page;

strcpy(b1-publisher,b-publisher);

// b1-price = b-price;

// b1-status = b-status;

m-borrownum++;

printf("%s借書成功!",b-name);

getch();

}

else

{

printf("你已借滿10本書.");

getch();

}

}

else

{

printf("沒有你要借的書.");

getch();

}

}

huanbook() /*還書函數(shù)*/

{

FILE *fp,*fp2; /*定義兩個(gè)文件指針,fp2用于修改數(shù)據(jù)時(shí)設(shè)立臨時(shí)文件用,防止數(shù)據(jù)遭破壞*/

int i,n;

int carnum,booknum;

char lendbook[10];

printf("請你輸入你的卡號(hào)\n");

scanf("%d",carnum);

fp=fopen("car.txt","r"); /*讀取卡號(hào)記錄*/

{

if(car[i].carnum==carnum) /*卡號(hào)存在,進(jìn)入下一循環(huán)*/

{

n=i;

fclose(fp);

printf("請輸入你要還的書的booknum\n");

scanf("%d",booknum);

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) /*借閱了該書,進(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; /*刪除還掉的書的借書記錄*/

}

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"); /*清臨時(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í)文件,防止因?yàn)樾薷男畔⑵茐囊郧暗挠涗?/

{

if(i==n)

{

book[i].turefalse=1;

fwrite(book[i],sizeof(struct book),1,fp2); /*將還的書的原來狀態(tài)設(shè)為無人借閱的*/

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í)文件寫回*/

}

fclose(fp);

fclose(fp2);

fopen("bookl.txt","w"); /*清臨時(shí)文件*/

fclose(fp2);

printf("還書完畢,按任意鍵返回\n");

getch();

return 1;

}

else

printf("你沒有借這樣的書,任意鍵返回\n");}/*出錯(cuò)提示*/

fclose(fp);

getch();

return 0;

}

else

printf("系統(tǒng)沒這樣的卡,和管理員聯(lián)系,按任意鍵返回\n");}/*出錯(cuò)提示*/

fclose(fp);

getch();

}

void main()

{

struct book *m;

char ch5;

do

{

printf("---------------歡迎進(jìn)入圖書查詢系統(tǒng)!--------------\n");

printf(" 1:注冊卡號(hào)\n");

printf(" 2: 卡號(hào)信息\n");

printf(" 3:按書籍編號(hào)查找\n");

printf(" 4: 借書\n");

printf(" 5: 還書\n");

printf(" 0:返回\n");

printf("請輸入0--5,其他輸入非法!\n");

scanf("%s",ch5);

switch(ch5)

{

case '1':addcar();getch();

case '2':carcount();getch();break;

case '3':findbook();getch();break;

case '4':borrowbook(m );getch();break;

case '5':huanbook();getch();break;

case '0':break;

default:printf("無此操作\n");getch();break;

}

}while(ch5!='0');

//return FALSE;

}

自己改一下,應(yīng)該沒有什么問題的,

C語言讀取文件時(shí)如何統(tǒng)計(jì)函數(shù)個(gè)數(shù)

使用fopen函數(shù)打開文件,使用fgetc()一個(gè)字符一個(gè)字符的讀取,然后計(jì)數(shù)統(tǒng)計(jì)就可以啦,fget()從文件指針stream指向的文件中讀取一個(gè)字符,讀取一個(gè)字節(jié)后,光標(biāo)位置后移一個(gè)字節(jié),這個(gè)函數(shù)的返回值,是返回所讀取的一個(gè)字節(jié)。如果讀到文件末尾或者讀取出錯(cuò)時(shí)返回EOF。

#includestdio.h

int main()

{

FILE *fp;

char filename[50];

int num=0;

printf("輸入一個(gè)文件名: ");

gets(filename);

if((fp=fopen(filename,"r"))==NULL)

{

printf("文件打開失敗..\n");

return ;

}

while(!feof(fp))fgetc(fp)num++;

printf("%s 文件中共有字符個(gè)數(shù): %d\n",filename,num);

fclose(fp);

return ;

}

c語言圖書管理系統(tǒng)

#include stdio.h

#include stdlib.h

#include time.h

#include string.h

typedef int BOOL;

typedef struct bookinfo

{

char number[15];/*產(chǎn)品編號(hào)*/

char name[30];/*產(chǎn)品名稱*/

float price;/*單價(jià)*/

char auther[20];/*作者*/

BOOL isExit;/*存在狀態(tài)*/

char lendername[20];/*借書人姓名*/

char lendersex[2];/*借書人性別*/

char lendernum[15];/*借書人學(xué)號(hào)*/

}BOOKINFO;

void menu()

{

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

printf("\t\t\t圖書管理系統(tǒng)\n");

printf("\t\t\t1:新進(jìn)圖書基本信息的輸入\n");

printf("\t\t\t2:顯示全部記錄\n");

printf("\t\t\t3:根據(jù)圖書名稱查詢圖書基本信息\n");

printf("\t\t\t4:根據(jù)圖書名稱對撤銷的圖書信息進(jìn)行刪除\n");

printf("\t\t\t5:按照圖書名稱從小大到排序\n");

printf("\t\t\t6:統(tǒng)計(jì)某價(jià)格以上的圖書數(shù)量\n");

printf("\t\t\t7:列出所有未借出去的圖書信息\n");

printf("\t\t\t8:退出\n");

}

void choice_1_input_new()/*輸入新進(jìn)的圖書信息*/

{

char choice;

FILE *p;

BOOKINFO newbook;

system("cls");

while(1)

{

printf("輸入圖書編號(hào):");

gets(newbook.number);

printf("輸入圖書名稱:");

gets(newbook.name);

printf("輸入圖書單價(jià):");

scanf("%f",newbook.price);

while(getchar()!='\n');

printf("輸入圖書的作者:");

gets(newbook.auther);

printf("輸入借書人姓名:");

gets(newbook.lendername);

printf("輸入借書人性別:");

gets(newbook.lendersex);

printf("輸入借書人學(xué)號(hào):");

gets(newbook.lendernum);

printf("是否保存該條書目?(Y/N)\n");

choice=getch();

while(choice!='Y'choice!='y'choice!='N'choice!='n')

choice=getch();

if(choice=='Y'||choice=='y')

{

newbook.isExit=1;/*將圖書狀態(tài)設(shè)置成1,表示沒有借出*/

p=fopen("c:\\bookinfo.data","ab");

fwrite(newbook,sizeof(BOOKINFO),1,p);

fclose(p);

printf("\n該條書目已添加到c:\\bookinfo.data文件中!\n");

}

else

{

printf("\n本條書目未保存!\n");

}

printf("\n是否繼續(xù)添加書目?(Y/N)\n");

choice=getch();

while(choice!='Y'choice!='y'choice!='N'choice!='n')

choice=getch();

if(choice=='Y'||choice=='y')

continue;

else

break;

}

}

void choice_2_display_all()/*顯示全部圖書信息*/

{

FILE *p;

int n;

BOOKINFO bookinfo[100];

int booknumber=0;

system("cls");

p=fopen("c:\\bookinfo.data","rb");

while(!feof(p))

{

fread(bookinfo[booknumber],sizeof(BOOKINFO),1,p);

booknumber++;

}

/*booknumber--;使用feof()函數(shù)會(huì)多讀一行,因此需要booknumber自減一次,使書目的數(shù)量正確*/

fclose(p);

booknumber--;

if(booknumber==0)

{

printf("沒有任何圖書信息!\n\n");

}

else

{

n=0;

printf(" 圖書信息如下\n");

printf(" 圖書信息 | 借書人信息 \n");

printf("編號(hào) 名稱 單價(jià) 作者 圖書狀態(tài) | 姓名 性別 學(xué)號(hào)\n");

while(nbooknumber)

{

printf("%-6s%-12s%-8.1f%-8s%-9d| %-12s%-8s%-8s\n",

bookinfo[n].number,bookinfo[n].name,bookinfo[n].price,

bookinfo[n].auther,bookinfo[n].isExit,bookinfo[n].lendername,

bookinfo[n].lendersex,bookinfo[n].lendernum);

n++;

}

}

printf("\n\n按任意鍵回到主菜單!\n");

getch();

}

void choice_3_search_according_name()/*根據(jù)圖書名稱顯示圖書的信息*/

{

char search[20]="";/*search用來存放要查詢的書名*/

int n;

FILE *p;

char choice;

BOOKINFO bookinfo[100];

int booknumber=0;

system("cls");

p=fopen("c:\\bookinfo.data","rb");

while(!feof(p))

{

fread(bookinfo[booknumber],sizeof(BOOKINFO),1,p);

booknumber++;

}

booknumber--;/*使用feof()函數(shù)會(huì)多讀一行,因此需要booknumber自減一次,使書目的數(shù)量正確*/

fclose(p);

while(1)

{

printf("輸入要查詢的書本名稱:");

gets(search);

if(booknumber==0)

{

printf("書庫中沒有任何信息!\n\n");

printf("按任意鍵回到主菜單!\n\n");

getch();

break;

}/*if結(jié)束*/

else

{

for(n=0;nbooknumber;n++)

if(strcmp(bookinfo[n].name,search)==0)

{

printf("該書的詳細(xì)信息如下:\n");

printf(" 圖書信息 | 借書人信息 \n");

printf("編號(hào) 名稱 單價(jià) 作者 圖書狀態(tài) | 姓名 性別 學(xué)號(hào)\n");

printf("%-6s%-12s%-8.1f%-8s%-9d| %-12s%-8s%-8s\n",

bookinfo[n].number,bookinfo[n].name,bookinfo[n].price,

bookinfo[n].auther,bookinfo[n].isExit,bookinfo[n].lendername,

bookinfo[n].lendersex,bookinfo[n].lendernum);

break;

}

if(n=booknumber)

printf("沒有查找該書的任何信息!\n");

printf("\n\n是否繼續(xù)查詢?(Y/N)\n");

choice=getch();

while(choice!='Y'choice!='y'choice!='N'choice!='n')

choice=getch();

if(choice=='Y'||choice=='y')

continue;

else

break;

}/*else結(jié)束*/

}/*while(1)結(jié)束*/

}

void choice_4_delete_according_name()/*根據(jù)圖書名稱對圖書信息進(jìn)行刪除*/

{

char search[20]="";/*search用來存放要?jiǎng)h除的書名*/

int n,i;

FILE *p;

char choice;

BOOKINFO bookinfo[100];

int booknumber;

system("cls");

while(1)

{

printf("輸入要?jiǎng)h除的書本名稱:");

gets(search);

p=fopen("c:\\bookinfo.data","rb");

booknumber=0;

while(!feof(p))

{

fread(bookinfo[booknumber],sizeof(BOOKINFO),1,p);

booknumber++;

}

booknumber--;/*使用feof()函數(shù)會(huì)多讀一行,因此需要booknumber自減一次,使書目的數(shù)量正確*/

fclose(p);

if(booknumber==0)

{

printf("書庫中沒有任何信息!\n\n");

printf("按任意鍵回到主菜單!\n\n");

getch();

break;

}/*if結(jié)束*/

else

{

for(n=0;nbooknumber;n++)

if(strcmp(bookinfo[n].name,search)==0)

{

break;

}

if(n=booknumber)

printf("沒有查找該書的任何信息!\n");

else

{

printf("是否確認(rèn)需要?jiǎng)h除該條書目?(Y/N)");

choice=getch();

while(choice!='Y'choice!='y'choice!='N'choice!='n')

choice=getch();

if(choice=='Y'||choice=='y')

{

for(i=n;ibooknumber-1;i++)

bookinfo[i]=bookinfo[i+1];

booknumber--;

p=fopen("c:\\bookinfo.data","wb");

for(n=0;nbooknumber;n++)

fwrite(bookinfo[n],sizeof(BOOKINFO),1,p);

fclose(p);

printf("刪除成功!\n");

}

else

printf("\n\n該條書目沒有被刪除!");

}

printf("\n\n是否繼續(xù)進(jìn)行刪除操作?(Y/N)\n");

choice=getch();

while(choice!='Y'choice!='y'choice!='N'choice!='n')

choice=getch();

if(choice=='Y'||choice=='y')

continue;

else

break;

}/*else結(jié)束*/

}/*while(1)結(jié)束*/

}

void choice_5_sort_according_name()/*根據(jù)圖書名稱排序*/

{

FILE *p;

int m,n;

BOOKINFO temp;

BOOKINFO bookinfo[100];

int booknumber;

p=fopen("c:\\bookinfo.data","rb");

booknumber=0;

system("cls");

while(!feof(p))

{

fread(bookinfo[booknumber],sizeof(BOOKINFO),1,p);

booknumber++;

}

booknumber--;/*使用feof()函數(shù)會(huì)多讀一行,因此需要booknumber自減一次,使書目的數(shù)量正確*/

fclose(p);

if(booknumber==0)

{

printf("沒有任何圖書信息!\n\n");

}

else

{

for(m=0;mbooknumber-1;m++)

for(n=m+1;nbooknumber;n++)

if(strcmp(bookinfo[m].name,bookinfo[n].name)0)

{

temp=bookinfo[m];

bookinfo[m]=bookinfo[n];

bookinfo[n]=temp;

}

p=fopen("c:\\bookinfo.data","wb");

for(m=0;mbooknumber;m++)

fwrite(bookinfo[m],sizeof(BOOKINFO),1,p);

fclose(p);

printf("\n\n完成排序!\n\n");

}

printf("按任意鍵回到主菜單!\n");

getch();

}

void choice_6_display_high_price()/*根據(jù)價(jià)格列出圖書信息*/

{

float price;

FILE *p;

int n;

int count=0;

BOOKINFO bookinfo[100];

int booknumber;

system("cls");

printf("請輸入價(jià)格:");

scanf("%f",price);

p=fopen("c:\\bookinfo.data","rb");

booknumber=0;

while(!feof(p))

{

fread(bookinfo[booknumber],sizeof(BOOKINFO),1,p);

booknumber++;

}

booknumber--;/*使用feof()函數(shù)會(huì)多讀一行,因此需要booknumber自減一次,使書目的數(shù)量正確*/

fclose(p);

if(booknumber==0)

{

printf("沒有任何圖書信息!\n\n");

}

else

{

for(n=0;nbooknumber;n++)

{

if(bookinfo[n].price=price)

count++;

}

if(count==0)

printf("書庫中沒有比%.1f$價(jià)格高的圖書!",price);

else

{

printf(" 價(jià)格高于%.1f$的圖書信息如下\n",price);

printf(" 圖書信息 | 借書人信息 \n");

printf("編號(hào) 名稱 單價(jià) 作者 圖書狀態(tài) | 姓名 性別 學(xué)號(hào)\n");

for(n=0;nbooknumber;n++)

{

if(bookinfo[n].price=price)

printf("%-6s%-12s%-8.1f%-8s%-9d| %-12s%-8s%-8s\n",

bookinfo[n].number,bookinfo[n].name,bookinfo[n].price,

bookinfo[n].auther,bookinfo[n].isExit,bookinfo[n].lendername,

bookinfo[n].lendersex,bookinfo[n].lendernum);

}

}

}

printf("\n\n按任意鍵回到主菜單!\n");

getch();

}

void choice_7_display_according_exitflag()/*根據(jù)存在狀態(tài)列出圖書信息*/

{

FILE *p;

int n;

int count=0;

BOOKINFO bookinfo[100];

int booknumber;

system("cls");

booknumber=0;

p=fopen("c:\\bookinfo.data","rb");

while(!feof(p))

{

fread(bookinfo[booknumber],sizeof(BOOKINFO),1,p);

booknumber++;

}

booknumber--;

fclose(p);

if(booknumber==0)

{

printf("書庫中沒有任何書目存在!\n");

}

else

{

for(n=0;nbooknumber;n++)

if(bookinfo[n].isExit==1)

count++;

if(count==0)

printf("書庫中的書籍全部借出!\n");

else

{

printf("書庫中未被借出的圖書信息如下:\n\n");

printf(" 圖書信息 | 借書人信息 \n");

printf("編號(hào) 名稱 單價(jià) 作者 圖書狀態(tài) | 姓名 性別 學(xué)號(hào)\n");

for(n=0;nbooknumber;n++)

if(bookinfo[n].isExit==1)

{

printf("%-6s%-12s%-8.1f%-8s%-9d| %-12s%-8s%-8s\n",

bookinfo[n].number,bookinfo[n].name,bookinfo[n].price,

bookinfo[n].auther,bookinfo[n].isExit,bookinfo[n].lendername,

bookinfo[n].lendersex,bookinfo[n].lendernum);

}

}

}

printf("\n按任意鍵返回主菜單!\n");

getch();

}

void main()

{

char choice;

clock_t tm;

FILE *p;

if((p=fopen("c:\\bookinfo.data","rb"))==NULL)

{

p=fopen("c:\\bookinfo.data","wb");

fclose(p);

}

while(1)

{

system("cls");

menu();

choice=getch();

switch(choice)

{

case '1':choice_1_input_new();break;/*輸入新進(jìn)的圖書信息*/

case '2':choice_2_display_all();break;/*顯示全部圖書信息*/

case '3':choice_3_search_according_name();break;/*根據(jù)圖書名稱顯示圖書的信息*/

case '4':choice_4_delete_according_name();break;/*根據(jù)圖書名稱對圖書信息進(jìn)行刪除*/

case '5':choice_5_sort_according_name();break;/*根據(jù)圖書名稱排序*/

case '6':choice_6_display_high_price();break;/*根據(jù)價(jià)格列出圖書信息*/

case '7':choice_7_display_according_exitflag();break;/*根據(jù)存在狀態(tài)列出圖書信息*/

case '8':printf("\n\n\t\t\t謝謝使用,再見!\n\t\t\t按任意鍵退出!\n");getch();return;

default:

printf("\n\n\t\t\t請輸入菜單中的數(shù)字!(1~8)");

tm=clock();

while(clock()tm+1800);

break;

}

}

}

寫的很趕,不知道行不行

程序很長,但是沒什么復(fù)雜的東西。

要是寫的不好,樓主就將就吧。

用C語言編寫一個(gè)簡單的圖書管理小程序

源代碼如下:

#includeiostream

#includeiomanip

#includestring

#includefstream

#includestdio.h

using namespace std;

const?? int?? maxb=10000;?? //最多的圖書

class?? book//圖書類

{

int?? tag;?? //刪除標(biāo)記1:已刪0:未刪

int?? number;?? //isbn書號(hào)

char?? name[20];?? //書名

char author[10]; //主編

char number2[10];//版次

char position[20];//出版社

char time[20];//出版年

void?? addbook(int n,char *na,char *au,char *n2,char *da,char *ti,int pr)?? //增加圖書??

{

tag=0;

number=n;

price=pr;

strcpy(name,na);

strcpy(author,au);

strcpy(number2,n2);

strcpy(position,da);

strcpy(time,ti);

onshelf=1;

}??

擴(kuò)展資料

1、源程序中,很多符號(hào)都是成對匹配出現(xiàn)的,為避免遺漏必須配對使用的符號(hào)。

2、用花括號(hào)括起來的部分,但從程序結(jié)構(gòu)清晰,便于閱讀、理解、維護(hù)的角度出發(fā),建議在書寫程序時(shí)應(yīng)遵循以下規(guī)則,以養(yǎng)成良好的編程習(xí)慣。

3、一個(gè)說明或一條語句占一行,與該結(jié)構(gòu)開始處的左花括號(hào)對齊。

c語言圖書資產(chǎn)統(tǒng)計(jì)系統(tǒng)

希望對你有用

#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 /*定義學(xué)生類型,用于存放借出的書籍*/

{

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 /*借書卡的數(shù)據(jù)類型*/

{

int carnum;

char studentname[10];

int studentclass;

}car[100];

huanbook() /*還書函數(shù)*/

{

FILE *fp,*fp2; /*定義兩個(gè)文件指針,fp2用于修改數(shù)據(jù)時(shí)設(shè)立臨時(shí)文件用,防止數(shù)據(jù)遭破壞*/

int i,n;

int carnum;

char lendbook[10];

printf("請你輸入你的卡號(hào)\n");

scanf("%d",carnum);

fp=fopen("car.txt","r"); /*讀取卡號(hào)記錄*/

for(i=0;fread(car[i],sizeof(struct car),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("請輸入你要還的書的名字\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) /*借閱了該書,進(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; /*刪除還掉的書的借書記錄*/

}

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"); /*清臨時(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í)文件,防止因?yàn)樾薷男畔⑵茐囊郧暗挠涗?/

{

if(i==n)

{

book[i].turefalse=1;

fwrite(book[i],sizeof(struct book),1,fp2); /*將還的書的原來狀態(tài)設(shè)為無人借閱的*/

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í)文件寫回*/

}

fclose(fp);

fclose(fp2);

fopen("bookl.txt","w"); /*清臨時(shí)文件*/

fclose(fp2);

printf("還書完畢,按任意鍵返回\n");

getch();

return 1;

}

}

printf("你沒有借這樣的書,任意鍵返回\n"); /*出錯(cuò)提示*/

fclose(fp);

getch();

return 0;

}

}

printf("系統(tǒng)沒這樣的卡,和管理員聯(lián)系,按任意鍵返回\n"); /*出錯(cuò)提示*/

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("這本書的詳細(xì)資料是:%d %s %s 此書現(xiàn)在無人借閱\n按任意鍵返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat);

}

else

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("這本書的詳細(xì)資料是:%d %s %s 此書現(xiàn)在無人借閱\n按任意鍵返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat);

}

else

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("卡號(hào):%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("---------------歡迎進(jìn)入圖書查詢系統(tǒng)!--------------\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("請你輸入你的卡號(hào)\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)

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("你的卡號(hào)不存在,請申請新卡,按任意鍵返回\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張卡卡號(hào):%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("請輸入你要?jiǎng)h除的卡號(hào)\n");

printf("如果你輸入的卡號(hào)存在,系統(tǒng)自動(dòng)刪除該信息!如果不存在,系統(tǒng)不做任何改動(dòng)\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("是否真的要?jiǎng)h除該卡?刪除后該書籍的所有信息將無法恢復(fù)《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("請你輸入卡號(hào)\n");

scanf("%d",car[i].carnum);

printf("請你輸入學(xué)生姓名\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語言圖書統(tǒng)計(jì)函數(shù) c語言 圖書館
本文URL:http://weahome.cn/article/doscicj.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部