WEB开发网
开发学院软件开发C++ 通过键盘操作的,想进行c图形化编程的可能有参考价... 阅读

通过键盘操作的,想进行c图形化编程的可能有参考价值

 2008-03-08 12:48:54 来源:WEB开发网   
核心提示:/*通过键盘操作的,想进行c图形化编程的可能有参考价值*/#include<stdio.h>#include<string.h>#include<conio.h>#include<stdlib.h>#include<ctype.h>#define back t
/*通过键盘操作的,想进行c图形化编程的可能有参考价值*/
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#include<ctype.h>
#define back textbackground
strUCt student      /*定义学生类型,用于存放借出的书籍*/
{
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        /*借书卡的数据类型*/
{
int carnum;
char studentname[10];
int studentclass;
}car[100];
winset(int txtcolor,int backcolor,int choice)
{
char a1[]="查询图书",a2[]="借阅图书",a3[]="治理员",a4[]="还书",a5[]="退出";
window(33,5+choice,53,5+choice);
back(backcolor);
textcolor(txtcolor);
clrscr();
switch(choice)
{
case 1: cPRintf("%s",a1); break;
case 2: cprintf("%s",a2); break;
case 3: cprintf("%s",a3); break;
case 4: cprintf("%s",a4); break;
case 5: cprintf("%s",a5); break;
}
}
winset3(int txtcolor,int backcolor,int choice)
{
char d1[]="增加卡号",d2[]="删除卡号",d3[]="卡号统计",d4[]="借书统计",d5[]="返回";
window(33,5+choice,53,5+choice);
back(backcolor);
textcolor(txtcolor);
clrscr();
switch(choice)
{
case 1: cprintf("%s",d1); break;
case 2: cprintf("%s",d2); break;
case 3: cprintf("%s",d3); break;
case 4: cprintf("%s",d4); break;
case 5: cprintf("%s",d5); break;
}
}
winset2(int txtcolor,int backcolor,int choice)
{ char c1[]="增加职工",c2[]="修改职工资料",c3[]="删除职工",c4[]="职工统计",c5[]="返回";
window(33,5+choice,53,5+choice);
back(backcolor);
textcolor(txtcolor);
clrscr();
switch(choice)
{
case 1: cprintf("%s",c1); break;
case 2: cprintf("%s",c2); break;
case 3: cprintf("%s",c3); break;
case 4: cprintf("%s",c4); break;
case 5: cprintf("%s",c5); break;
}
}
winset1(int txtcolor,int backcolor,int choice)
{
char b1[]="增加图书",b2[]="修改图书",b3[]="删除图书",b4[]="书籍统计",b5[]="职工治理系统",b6[]="学生治理系统",b7[]="返回";
window(33,5+choice,53,5+choice);
back(backcolor);
textcolor(txtcolor);
clrscr();
switch(choice)
{
case 1: cprintf("%s",b1); break;
case 2: cprintf("%s",b2); break;
case 3: cprintf("%s",b3); break;
case 4: cprintf("%s",b4); break;
case 5: cprintf("%s",b5); break;
case 6: cprintf("%s",b6); break;
case 7: cprintf("%s",b7); break;
}
}
lendcount()       /*其他的自己看就懂了,不行也可以QQ联系:258032791,人妖也!愿意交爱好编程的交友,毕业没时间了,找工作忙,有其他的模块没写,发现什么问题自己改,*/
{
FILE *fp;
int i,n=0;
fp=fopen("record.txt","r");
clrview();
for(i=0;fread(&student[i],sizeof(struct student),1,fp)!=0;i++)
{
window(1,15+i,79,15+i);
back(9);
textcolor(3);
printf("卡号:%d 借出的书籍:%s ",student[i].carnum,student[i].lendbook);
n=n+1;
}
fclose(fp);
printf("目前共有%d本书借出\n",n);
printf("按任意键\n");
getch();
stuview();
}
huanbook()        /*还书函数*/
{
FILE *fp,*fp2;      /*定义两个文件指针,fp2用于修改数据时设立临时文件用,防止数据遭破坏*/
int i,n;
int carnum;
char lendbook[10];
clrview();
window(1,15,79,15);
back(9);
textcolor(3);
printf("请你输入你的卡号\n");
scanf("%d",&carnum);
fp=fopen("car.txt","r");    /*读取卡号记录*/
for(i=0;fread(&car[i],sizeof(struct car),1,fp)!=0;i++)  /*for循环判定卡号是否存在*/
{
if(car[i].carnum==carnum)    /*卡号存在,进入下一循环*/
{
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)    /*借阅了该书,进入下一循环,否则出错显示*/
{
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");           /*清临时文件的记录*/
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++)   /*将书的记录写入临时文件,防止因为修改信息破坏以前的记录*/
{
if(i==n)
{
book[i].turefalse=1;
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();
firstview();
}
}
printf("你没有借这样的书,不要耍我,任意键返回\n");   /*出错提示*/
fclose(fp);
getch();
firstview();
}
}
printf("系统没这样的卡,和治理员联系,按任意键返回\n");  /*出错提示*/
fclose(fp);
getch();
firstview();
}
lendbook()
{
FILE *fp,*fp2;
int i,n;
int carnum;
clrview();
window(1,15,79,15);
back(9);
textcolor(3);
printf("请你输入你的卡号\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) {printf("对不起,此书有人借出,请借其他书\n");fclose(fp);getch();firstview();}
else
fclose(fp);
fp

Tags:通过 键盘 操作

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接