class person{
public:
char name[20];
char phone[15];
};
class book{
public:
char title[20];
int no[20];
char state[4];
void binput();
};
class user:public person{
public:
int id[20];
void uinput();
void borrow();
};
void user::uinput()
{
FILE *fp;
int i;
clrscr();
printf("\n\n\n\n");
printf(" /**********************************************/\n");
printf(" /* */\n");
printf(" /* welcome to the user-inputing system */\n");
printf(" /* */\n");
printf(" /**********************************************/\n");
fp=fopen("a:\\oo\\temp\\user.dbf","a");
i=0;
printf("\n\n @@@@ Please input id (0 => stop inputing) :");scanf("%d",&id[i]);
if(id[i]!=0)
{
printf("\n name :");scanf("%s",name);
printf("\n phone :");scanf("%s",phone);
fprintf(fp,"%s %d %s\n",name,id[i],phone);
}
while(id[i]!=0)
{
i=i+1;
printf("\n @@@@ Please input id (0 => stop inputing) :");scanf("%d",&id[i]);
if(id[i]!=0)
{
printf("\n name :");scanf("%s",name);
printf("\n phone :");scanf("%s",phone);
fprintf(fp,"%s %d %s\n",name,id[i],phone);
}
}
printf("\n\n You have inputed %d-user's database.\n\n",i);
fclose(fp);
printf("\n\n Please wait 3 seconds.\n");
sleep(3);
return;
}
void book::binput()
{
FILE *fp;
int i;
clrscr();
printf("\n\n\n\n");
printf(" /*********************************************/\n");
printf(" /* */\n");
printf(" /* welcom to the book-inputing system */\n");
printf(" /* */\n");
printf(" /*********************************************/\n");
fp=fopen("a:\\oo\\temp\\book.dbf","a");
i=0;
printf("\n\n @@@@ Please input no (0 => stop inputing) :");scanf("%d",&no[i]);
if(no[i]!=0)
{
printf("\n title :");scanf("%s",title);
printf("\n state :");scanf("%s",state);
fprintf(fp,"%s %d %s\n",title,no[i],state);
}
while(no[i]!=0)
{
i=i+1;
printf("\n @@@@ Please input no (0 => stop inputing) :");scanf("%d",&no[i]);
if(no[i]!=0)
{
printf("\n title :");scanf("%s",title);
printf("\n state :");scanf("%s",state);
fprintf(fp,"%s %d %s\n",title,no[i],state);
}
}
printf("\n\n You have inputed %d-book's database.\n\n",i);
fclose(fp);
printf("\n\n Please wait 3 seconds.\n");
sleep(3);
return;
}
void user::borrow()
{
int uid; //user-id
int yorn; //book has be borrowed or not
void store();
clrscr();
printf("\n\n\n\n");
printf(" /****************************************/\n");
printf(" /* */\n");
printf(" /* welcome to the borrow system */\n");
printf(" /* */\n");
printf(" /****************************************/\n");
printf("\n\n @@@@ Please input your id :");scanf("%d",&uid);
if(uid>0 && uid<1001)
store();
else
printf("\n Sorry! You don't have the borrow-right.");
printf("\n\n\n Please wait 3 seconds.");
sleep(3);
return;
}
void store()
{
FILE *fp;
int i,j,k;
char *str1="yes", *str2="no";
char bt[20];
book b[30];
fp=fopen("a:\\oo\\temp\\book.dbf","r");
i=0;
while(!feof(fp) && fscanf(fp,"%s%d%s",b[i].title,&b[i].no,b[i].state)!=NULL)
i++;
fclose(fp);
printf("\n Please input the book's title :");scanf("%s",bt);
j=0;
while(strcmp(b[j].title,bt)!=0) // 0 => bt==b[j].title
j++;
if(strcmp(b[j].state,str1)==0) //0=>this book now can be borrowed
{
strcpy(b[j].state,str2);
fp=fopen("a:\\oo\\temp\\book.dbf","w");
for(k=0;k<i;k++)
fprintf(fp,"%s %d %s\n",b[k].title,b[k].no,b[k].state);
fclose(fp);
printf("\n You have borrowed the book successfully.");
}
else
printf("\n Sorry! The book is not stored now.");
return;
}
void menu()
{
char c;
user us;
book bo;
clrscr();
printf("\n\n\n\n /***************************************/\n");
printf("\n /* */\n");
printf("\n /* 1=>input user`s database */\n");
//printf("\n /* 2=>input librarian`s database */\n");
printf("\n /* 3=>input book`s database */\n");
printf("\n /* 4=>borrow */\n");
printf("\n /* */\n");
printf("\n /* 0=>ending */\n");
printf("\n /* */\n");
printf("\n /***************************************/\n");
printf("\n\n @@@@ Please input your choice:");
}
void main()
{
char c;
user us;
book bo;
void menu();
menu();
while((c=getch())!='0')
{
switch(c)
{
case'1':
us.uinput();
break;
// case'2':
// librarian.linput();
// break;
case'3':
bo.binput();
break;
case'4':
us.borrow();
break;
default:
printf("\n Inputing error! Try again.(wait 3 seconds)");
sleep(3);
}
menu();
}
printf("\n Thank you for using this system.");
printf("\n Please wait 3 seconds.");
sleep(3);
}
:這個程式有點問題,能不能幫我看一下說!~謝謝
--
※ Origin: 奇摩 大摩域 (bbs.kimo.com.tw) ◆ From: 163.25.13.45