⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 library.c

📁 c 语言学习220例
💻 C
📖 第 1 页 / 共 2 页
字号:
# include<stdio.h>
# include<conio.h>
# include<dos.h>
# include<string.h>
# include<math.h>

# define TRUE 1
# define FALSE 0

struct member
{
   int mid;
   char mname[20],madd[30];
   struct msince
   {
    int day,mon,year;
   } ms;
   struct mexpir
   {
     int day,mon,year;
   } me;

} M;


struct book
{
   struct bkid
   {
      int gno,bno,no;
   } b;
   char bname[20],author[15],pub[20];
   int price;
} B;


struct transaction
{
   int mid,tid;
   struct bookid
   {
      int gno,bno,no;
   } b;
   struct issued
   {
    int day,mon,year;
   } i;

   struct returned
   {
    int day,mon,year;
   } r;

   float fine;
   char reason;
} T;

struct date d;

FILE *fm,*fb,*ft;

char *mainmenu[]={
		  "Member",
		  "Book",
		  "Reports",
		  "Help",
		  "Exit"
		};

char *memmenu[]={
		 "Add New Member",
		 "Renew Existing Member",
		 "Issue Duplicate I-Card",
		 "Back"
		};

char *bookmenu[]={
		  "Add New Books",
		  "Issue Book",
		  "Return Book",
		  "Back"
		 };


char *rptmenu[]={
		  "Members Details",
		  "Books Details",
		  "Transactions Details",
		  "Back"
		 };

void mainscr();
void showmenu(char **menu,int count,int sr,int sc);
int getchoice(char **menu,char *hotkeys,int r,int c,int count);

void addmember();
void renewmem();
void memdupid();
int memcheck(int id);

void addbook();
void issbook();
void retbook();
int  chkbook(int bno,int gno,int no);

void transac1(int mid,char ch);
void transac2(int mid,int bno,int gno,int no,char c);

void allmem();
void allbook();
void alltransac();

void showhelp();


/**************************** MAIN ******************************************/

void main()
{
   int ch,ch1,ch2,ch3;
   fm=fopen("member.dat","a+");
   ft=fopen("trans.dat","a+");
   fb=fopen("book.dat","a+");

   mainscr();

   while(1)
   {
    bk:
    showmenu(mainmenu,5,10,35);
    ch=getchoice(mainmenu,"MBRHE",10,35,5);
   switch(ch)
   {
    case 1:bk1:
	   showmenu(memmenu,4,10,35);
	   ch1=getchoice(memmenu,"ARIB",10,35,4);
	   switch(ch1)
	   {
	     case 1: addmember(); goto bk1;
	     case 2: renewmem();  goto bk1;
	     case 3: memdupid();  goto bk1;
	     case 4: goto bk;
	   }
	   break;
    case 2:bk2:
	   showmenu(bookmenu,4,10,35);
	   ch2=getchoice(bookmenu,"AIRB",10,35,4);
	   switch(ch2)
	   {
	     case 1: addbook(); goto bk2;
	     case 2: issbook(); goto bk2;
	     case 3: retbook(); goto bk2;
	     case 4: goto bk;
	   }
	   break;
    case 3:bk3:
	   showmenu(rptmenu,4,10,35);
	   ch3=getchoice(rptmenu,"MBTB",10,35,4);
	   switch(ch3)
	   {
	     case 1: allmem(); goto bk3;
	     case 2: allbook();goto bk3;
	     case 3: alltransac();goto bk3;
	     case 4: goto bk;
	   }
	   break;
    case 4:
	   showhelp(); break;
    case 5:fclose(ft); fclose(fm); fclose(fb);
	   exit();
   }
  }
}
/******************** Function Do Display The Main Screen *******************/

void mainscr()
{
  int i,j;
  clrscr();
  textcolor(BLUE);
  for(i=1;i<80;i++)
   for(j=1;j<24;j++)
   {
     gotoxy(i,j); cprintf("?);
   }
  textbackground(BLUE);
  textcolor(LIGHTMAGENTA);
   gotoxy(8,1);
   cprintf("赏屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯突");
   gotoxy(8,2);
   cprintf("?                   赏屯屯屯屯屯屯屯屯屯屯屯屯?                ?);
   gotoxy(8,3);
   cprintf("掏屯屯屯屯屯屯屯屯屯凸  Welcome To Obaid Books 掏屯屯屯屯屯屯屯屯?);
   gotoxy(8,4);
   cprintf("?                   韧屯屯屯屯屯屯屯屯屯屯屯屯?                ?);
   gotoxy(8,5);
   cprintf("韧屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯图");
   textcolor(RED);
   gotoxy(1,10);
   cprintf("Loading Files Please Wait...");
   textcolor(DARKGRAY);
   for(i=1;i<81;i++)
   {
     gotoxy(i,12);
     cprintf("?);
   }
   delay(200);
   textcolor(LIGHTGRAY);
    for(i=1;i<81;i++)
   {
     gotoxy(i,12);
     cprintf("?);
     delay(50);
   }
   textcolor(WHITE);
   for(i=1;i<81;i++)
   {
     gotoxy(i,12);
     cprintf("?);
     delay(20);
   }
  textcolor(WHITE);
}


/************************** The Showmenu function ***************************/
   void showmenu(char **menu,int count,int sr,int sc)
    {
       int i;  clrscr();
	   textcolor(LIGHTMAGENTA);
	   gotoxy(8,1);
	   cprintf("赏屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯突");
	   gotoxy(8,2);
	   cprintf("?                   赏屯屯屯屯屯屯屯屯屯屯屯屯?                ?);
	   gotoxy(8,3);
	   cprintf("掏屯屯屯屯屯屯屯屯屯凸  Welcome To Obaid Books 掏屯屯屯屯屯屯屯屯?);
	   gotoxy(8,4);
	   cprintf("?                   韧屯屯屯屯屯屯屯屯屯屯屯屯?                ?);
	   gotoxy(8,5);
	   cprintf("韧屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯图");

       for(i=0;i<count;i++)
	{
	  gotoxy(sc,sr++);  textcolor(DARKGRAY); cprintf(menu[i]);
	}
    }


/***********************Funtion To Get User's Choice*************************/
  int getchoice(char **menu,char *hotkeys,int r,int c,int count)
  {
   int choice=1,hotkeychoice=1,ascii,scan;
   char *s;
     while(1)
      {
	gotoxy(c,r+choice-1);  textcolor(WHITE+BLINK); cprintf(menu[choice-1]);
	while(!kbhit())
	;
	ascii=getch();
	if(ascii==0)
	     scan=getch();

	gotoxy(c,r+choice-1);  textcolor(DARKGRAY);    cprintf(menu[choice-1]);

	if(ascii==0)
	 {
		if(scan==80)
		    choice++;

		if(scan==72)
		choice--;

		if(choice==0)
		choice=count;

		if(choice>count)
		choice=1;
	  }
	 else
	  {
		if(ascii==13)
		return(choice);

		s=hotkeys;
		hotkeychoice=1;

		while(*s)
		 {
		   if(ascii==*s)
		   return(hotkeychoice);

		   hotkeychoice++;
		   s++;
		 }

	   }
       }
  }


/*********************Function To Add New Members****************************/
  void addmember()
  {
     clrscr();
     rewind(fm);
     while( fread(&M,sizeof(M),1,fm)==1)
     ;
     M.mid+=1;
     fseek(fm,0,SEEK_END);
     printf("\n\t Enter Name::");
     fflush(stdin);gets(M.mname);  M.mname[19]=' ';  M.mname[20]='\0';
     printf("\n\t Enter Add::");
     fflush(stdin);gets(M.madd);   M.madd[29]=' ';   M.madd[30]='\0';

     getdate(&d);
     M.ms.year=d.da_year;     M.ms.day=d.da_day;     M.ms.mon=d.da_mon;
     M.me.day=M.ms.day;       M.me.year=M.ms.year;   M.me.mon=(M.ms.mon+6);
     /*To Set Month After Dec To Jan*/
     if(M.me.mon>12)
      {
	M.me.year+=1;  M.me.mon=(M.me.mon-12);
      }
     /*If Say The Old Date is 31/12/2003 i.e 31 Dec Then   The New Date is 31/06/2004 i.e 31 Jun
     But Jun consists of Only 30 days so we shall add 1 day extra so the correct Date is 01/07/2004 */
     if(M.me.day==31)
     { /*Months Like Apr,Jun,Sep, & Nov have 30 days*/
       if(M.me.mon==4 || M.me.mon==6 || M.me.mon==9 || M.me.mon==11)
       {
	M.me.day=1;
	M.me.mon+=1;
       }

       /*For the Month of Feb there are 28 OR 29 days*/
       if(M.me.mon==2)
	{/*For Years like(1996,2000,2004 etc there are 29 days in Feb */
	 if( (M.me.year%4)==0)
	  {
	    M.me.day=31-29;   M.me.mon+=1;
	  }
	 else
	  {
	    M.me.day=31-28;  M.me.mon+=1;
	  }
	}
     }
     fwrite(&M,sizeof(M),1,fm);
     transac1(M.mid,'A');
  }


/**********************Function To Renew A Member****************************/
  void renewmem()
  {
     FILE *tt;
     int no,ch;
     clrscr();
     tt=fopen("temp1.dat","w");
     printf("\n\t Enter Membership Id::");  scanf("%d",&no);
     ch=memcheck(no);
     if(ch==FALSE)
     {
	printf("\n\t No Such Member....."); getch(); return;
     }
     rewind(fm);
     while( fread(&M,sizeof(M),1,fm)==1 )
      {
	  if(M.mid==no)
	    {
	      M.me.mon=(M.me.mon+6);
		if(M.me.mon>12 && M.me.mon!=12)
		      {
			M.me.year+=1;  M.me.mon=(M.me.mon-12);
		      }
		if(M.me.day==31)
		      {
			 if(M.me.mon==4 || M.me.mon==6 || M.me.mon==9 || M.me.mon==11)
			       {
					M.me.day=1;
					M.me.mon+=1;
			       }
			 if(M.me.mon==2)
			       {
				 if( (M.me.year%4)==0)
				  {
				    M.me.day=31-29;   M.me.mon+=1;
				  }
				 else
				  {
				    M.me.day=31-28;  M.me.mon+=1;
				  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -