/*代码包含的函数库申明*/
#include<stdio.h>
#include <dos.h>

/*定义影片信息结构体*/
typedef struct //影片info
{
	char No[10];
	char name[10];
	int state;
}DI;

/*定义会员信息结构体*/
typedef struct MemberInfo
{
char No[10];
char name[10];
char password[20];
float balance;
DI borrow [3];
int state;
}MI;

/*会员按月自动缴费模块*/
void month()
{
FILE *fp1;
FILE *fp2;
MI mem[500];
int month;
int pmonth;
int cost;
int j;
int i;
int date;
struct date;
getdate(&curr_date);
month=curr_date.da_mon;
fp1=fopen("month","r+");
fp2=fopen("meminfo","r+");
if(fp1==NULL)exit(0);
if(fp2==NULL)exit(0);
fread(&pmonth,sizeof(int),1,fp1);
if(pmonth!=month)
{
cost=5*abs(month-pmonth);
for(j=0;fread(&mem[j],sizeof(struct MemberInfo),1,fp2)!=0;j++)
{
mem[j].balance-=cost;
}
rewind(fp2);
for(i=0;i<j;i++)fwrite(&mem[i],sizeof(struct MemberInfo),1,fp2);
}
fwrite(&month,sizeof(int),1,fp1);
fclose(fp1);
fclose(fp2);
}

/*会员注册模块*/
int reg()
{
FILE *fp;
MI newmem;
int choice;
int i=0;
int result;
fp=fopen("meminfo","r+");
clrscr();
printf("***************************************************\n");
printf("Please fill in the information of new members\n");
printf("***************************************************\n");
printf("The movie club rules:\n");
printf("1.Please pay for your renting every month per month\n");
printf("2.You are allowed to rent less than 4 影片s\n");
printf("3.Please protect 影片s you rented from club\n");
printf("If you destory it,you will pay for it\n");
printf("4.Please remember your own password that is very\n");
printf("important.If you forget it,you will afford all\n");
printf("---------------------------------------------------\n");
printf("Do you agree all above?\n");
printf("---------------------------------------------------\n");
printf("1.YES\n");
printf("2.NO\n");
printf("---------------------------------------------------\n");
printf("Your chice:\n");
scanf("%d",&result);
if(result==1)
{
printf("---------------------------------------------------\n");
printf("Please input your nickname:\n");
scanf("%s",newmem.No);
printf("Please input your true name:\n");
scanf("%s",newmem.name);
printf("Please input your password:\n");
scanf("%s",newmem.password);
for(;i<3;i++)
{
strcpy(newmem.borrow影片[i].No,"");
strcpy(newmem.borrow影片[i].name,"");
newmem.borrow影片[i].state=0;
}
newmem.balance=0;
newmem.state=0;
if(fp==NULL)exit(0);
fseek(fp,0L,2);
fwrite(&newmem,sizeof(struct MemberInfo),1,fp);
fclose(fp);
}
printf("------------------------------------\n");
printf("1.Increasing value of my balance now\n");
printf("2.Return to welcome page\n");
printf("------------------------------------\n");
printf("Your Choice:");
scanf("%d",&choice);
if(choice==1)return(2);
if(choice==2)return(-1);
}

/*添加影片信息入库模块*/
int add影片()
{
FILE *fp;
DI new影片;
fp=fopen("影片info","r+");
if(fp==NULL)exit(0);
clrscr();
printf("*****************************************\n");
printf("Please fill in the information of new 影片\n");
printf("*****************************************\n");
printf("Please input 影片 number:\n");
scanf("%s",new影片.No);
printf("Please input 影片 name:\n");
scanf("%s",new影片.name);
printf("Please input 影片 state:\n");
scanf("%d",&new影片.state);
fseek(fp,0L,2);
fwrite(&new影片,sizeof(struct 影片info),1,fp);
fclose(fp);
}

/*会员账户充值模块*/
void money(char name[])
{
MI fuser[500];
int i;
int j;
float balance;
FILE *fp;
clrscr();
printf("***********************************************\n");
printf("You are being to increase value of your balance\n");
printf("***********************************************\n");
fp=fopen("meminfo","r+");
if(fp==NULL)exit(0);
for(i=0;fread(&fuser[i],sizeof(struct MemberInfo),1,fp)!=0;i++)
{
if(strcmp(fuser[i].name,name)==0)
{
printf("The value you want to increase:");
scanf("%f",&balance);
fuser[i].balance+=balance;
printf("------------------------------------\n");
printf("OK,now your balance is:%f\n",fuser[i].balance);
getch();
}
}
rewind(fp);
for(j=0;j<i;j++)fwrite(&fuser[j],sizeof(struct MemberInfo),1,fp);
fclose(fp);
}

/*浏览俱乐部影片信息模块*/
void 影片info()
{
DI 影片[500];
int p=0;
FILE *fp;
int j;
fp=fopen("影片info","r");
if(fp==NULL)exit(0);
printf("------------影片S-INFORMATION----------\n");
printf("  No             Name            State\n");
for(j=0;fread(&影片[j],sizeof(struct 影片info),1,fp)!=0;j++)
{
p++;
if((p%10)==0)
{
getch();
printf("----------MEMBERS-<%d to %d>---------\n",(p-10),p);
}
printf("%s   %s    %d\n",影片[j].No,影片[j].name,影片[j].state);
}
fclose(fp);
getch();
}

/*浏览俱乐部会员信息模块*/
void meminfo()
{
MI mem[500];
FILE *fp;
int j;
int p=0;
fp=fopen("meminfo","r");
if(fp==NULL)exit(0);
printf("-------------------MEMBERS-INFORMATION-----------------\n");
printf("No     Name    Balance    Borrow影片(No \ Name)    State\n");
for(j=0;fread(&mem[j],sizeof(struct MemberInfo),1,fp)!=0;j++)
{
p++;
if((p%10)==0)
{
getch();
printf("-------------------MEMBERS-<%d to %d>-------------------\n",(p-10),p);
}
printf("%s   %s   %f    %s  %s  %s       %d\n",mem[j].No,mem[j].name,mem[j].balance,mem[j].borrow影片[0].name,mem[j].borrow影片[1].name,mem[j].borrow影片[2].name,mem[j].state);
}
fclose(fp);
getch();
}

/*浏览俱乐部交易信息模块*/
void sell()
{
MI mem[500];
FILE *fp;
int j;
fp=fopen("meminfo","r");
if(fp==NULL)exit(0);
printf("-------------------SELLS-INFORMATION-------------------\n");
printf("No     Name    Password    Balance    Borrow影片   State\n");
for(j=0;fread(&mem[j],sizeof(struct MemberInfo),1,fp)!=0;j++)
{
if(mem[j].state>0)printf("%s   %s   %s    %f    %s         %d\n",mem[j].No,mem[j].name,mem[j].password,mem[j].balance,mem[j].borrow影片,mem[j].state);
}
getch();
fclose(fp);
}

/*会员租借影片模块*/
void rent(char name[],char 影片num[])
{
DI 影片[500];
MI mem[500];
int mm;
int md;
int j;
int k;
int i;
int f;
FILE *fp1;
FILE *fp2;
fp1=fopen("meminfo","r+");
fp2=fopen("影片info","r+");
if(fp1==NULL)exit(0);
if(fp2==NULL)exit(0);
for(j=0;fread(&mem[j],sizeof(struct MemberInfo),1,fp1)!=0;j++)
{
if(strcmp(mem[j].name,name)==0)mm=j;
}
for(k=0;fread(&影片[k],sizeof(struct 影片info),1,fp2)!=0;k++)
{
if(strcmp(影片num,影片[k].No)==0)md=k;
}
if(影片[md].state==1 && mem[mm].state<3 && mem[mm].balance>0)
{
影片[md].state=0;
mem[mm].state++;
for(f=0;f<3;f++)
{
if(strcmp("",mem[mm].borrow影片[f].No)==0)
{
mem[mm].borrow影片[f]=影片[md];
break;
}
}
}
rewind(fp1);
rewind(fp2);
for(i=0;i<j;i++)fwrite(&mem[i],sizeof(struct MemberInfo),1,fp1);
for(i=0;i<k;i++)fwrite(&影片[i],sizeof(struct 影片info),1,fp2);
fclose(fp1);
fclose(fp2);
}

/*会员归还影片模块*/
void back(char name[],char 影片num[])
{
DI 影片[500];
MI mem[500];
int mm;
int md;
int j;
int k;
int i;
int f;
FILE *fp1;
FILE *fp2;
fp1=fopen("meminfo","r+");
fp2=fopen("影片info","r+");
if(fp1==NULL)exit(0);
if(fp2==NULL)exit(0);
for(j=0;fread(&mem[j],sizeof(struct MemberInfo),1,fp1)!=0;j++)
{
if(strcmp(name,mem[j].name)==0)mm=j;
}
for(k=0;fread(&影片[k],sizeof(struct 影片info),1,fp2)!=0;k++)
{
if(strcmp(影片num,影片[k].No)==0)md=k;
}
if(影片[md].state==0 && mem[mm].state>0)
{
影片[md].state=1;
for(f=0;f<3;f++)
{
if(strcmp(影片num,mem[mm].borrow影片[f].No)==0)
{
strcpy(mem[mm].borrow影片[f].No,"");
strcpy(mem[mm].borrow影片[f].name,"");
mem[mm].borrow影片[f].state=1;
}
}
mem[mm].state--;
}
rewind(fp1);
rewind(fp2);
for(i=0;i<j;i++)fwrite(&mem[i],sizeof(struct MemberInfo),1,fp1);
for(i=0;i<k;i++)fwrite(&影片[i],sizeof(struct 影片info),1,fp2);
fclose(fp1);
fclose(fp2);
}

/*会员浏览账户信息模块*/
void count(char name[])
{
MI mem[500];
FILE *fp;
int j;
printf("\n--------------------YOUR-ACCOUNT-DETAILS--------------------------\n");
printf("No     Name    Password    Balance    Borrow影片(Num \ Name)   State\n");
fp=fopen("meminfo","r");
if(fp==NULL)exit(0);
for(j=0;fread(&mem[j],sizeof(struct MemberInfo),1,fp)!=0;j++)
{
if(strcmp(name,mem[j].name)==0)printf("%s   %s   %s    %f    %s %s    %s %s   %s %s      %d\n",mem[j].No,mem[j].name,mem[j].password,mem[j].balance,mem[j].borrow影片[0].No,mem[j].borrow影片[0].name,mem[j].borrow影片[1].No,mem[j].borrow影片[1].name,mem[j].borrow影片[2].No,mem[j].borrow影片[2].name,mem[j].state);
}
fclose(fp);
getch();
}

/*主函数*/
void main()
{
int answer1;
int answer2;
int answer3;
int m;
int menu1;
int menu2;
char name[10];
char tname[10];
char password[20];
char 影片num[10];
MI mem[500];
FILE *fp;
int a;
int j;
int choice;
int k;
for(m=0;m<1;m++)
{
clrscr();
printf("************************************\n");
printf("Welcome come to movie club verb  1.0\n");
printf("Free software Designed & Programmed\n");
printf("                  by ZhangBin of CUG\n");
printf("    All rights reserved @ 2007.7.18.\n");
printf("************************************\n");
printf("Press any key to countinue");
getch();
clrscr();
month();
printf("************************************\n");
printf("Do you want to register now?(*^_^*)\n");
printf("************************************\n");
printf("1.Resister new member now\n");
printf("2.Log on system now\n");
printf("------------------------------------\n");
printf("Your choice:");
scanf("%d",&choice);
if(choice==1)
{
m=reg();
if(m==2)
{
printf("------------------------------------\n");
printf("Please input your name now\n");
scanf("%s",tname);
money(tname);
}
}
}
clrscr();
printf("************************************\n");
printf("Which part do you want to enter?\n");
printf("************************************\n");
printf("1.Administer part\n");
printf("2.Common member part\n");
printf("------------------------------------\n");
printf("Your choice:");
scanf("%d",&answer1);
if(answer1==1)
{
for(menu1=2;menu1<3;menu1++)
{
clrscr();
printf("******************************************\n");
printf("What do you want to do in administer part?\n");
printf("******************************************\n");
printf("1.Browse all 影片s' information in club\n");
printf("2.Browse all members' information in club\n");
printf("3.Glance over all sells in club\n");
printf("4.Add new 影片s to club\n");
printf("-----------------------------------------\n");
printf("Your choice:");
scanf("%d",&answer2);
if(answer2==1) 影片info();
if(answer2==2) meminfo();
if(answer2==3) sell();
if(answer2==4)
{
for(k=2;k<3;k++)
{
add影片();
printf("----------------");
printf("\n1.Go on adding 影片s");
printf("\n2.Stop adding 影片s\n");
scanf("%d",&k);
}
}
printf("----------------------------------------\n");
printf("1.Return to main menu of administer part\n");
printf("2.Quit form movie club management system\n");
printf("----------------------------------------\n");
printf("Your choice:");
scanf("%d",&menu1);
}
}
else
{
clrscr();
printf("*****************************************\n");
printf("Now,you are being into common member part\n");
printf("*****************************************\n");
printf("Please input your name and password now\n");
printf("Name:");
scanf("%s",name);
printf("Password:");
scanf("%s",password);
fp=fopen("meminfo","r");
if(fp==NULL)exit(0);
for(j=0;fread(&mem[j],sizeof(struct MemberInfo),1,fp)!=0;j++)
{
if(strcmp(name,mem[j].name)==0 && strcmp(password,mem[j].password)==0)
{
for(menu2=2;menu2<3;menu2++)
{
clrscr();
printf("*********************************************\n");
printf("What do you want to do in common member part?\n");
printf("*********************************************\n");
printf("1.Rent my favourite 影片s in club\n");
printf("2.Hand back 影片s I rented in the club\n");
printf("3.Increasing value of my balance\n");
printf("4.Details of my account\n");
printf("---------------------------------------------\n");
printf("Your choice:");
scanf("%d",&answer3);
if(answer3==1)
{
影片info();
count(name);
printf("\nPlease input the number of 影片 you want to rent from club\n");
scanf("%s",影片num);
rent(name,影片num);
}
if(answer3==2)
{
count(name);
printf("----------------------------------------------------\n");
printf("Please input the number of 影片 you want to hand back\n");
scanf("%s",影片num);
back(name,影片num);
}
if(answer3==3)money(name);
if(answer3==4)count(name);
printf("-------------------------------------------\n");
printf("1.Return to main menu of common member part\n");
printf("2.Quit form movie club management system\n");
printf("-------------------------------------------\n");
printf("Your choice:");
scanf("%d",&menu2);
}
}
}
fclose(fp);
}
}
说明:源代码编译、链接可生成目标程序MOVICE~1,但程序运行还需要< meminfo > + < 影片info > + < month > 三个文本文件。程序正常运行,四者缺一不可。