c语言实现通讯录管理体系(c课程设计)

工具:Visual C++6.0

最主要目的:实现对实验室的硬件资源和软件资源的采用以及治本。

说明:

数信息:用户登录信息(分普通成员–管理员:信息根本有用户称、密码、性别、专业班级、学号、联系电话、QQ等)

       本系统根据C语言实现班级通讯录管理网,为很一时学习C语言刚入门所做的课程设计。功能包括多、删、查、改等,非常适合初大家练手。通讯录包括的个人信息有姓名、学号、性别、籍贯、政治面貌、手机号、QQ号、宿舍等。主要使用了指针、结构体、遍历链表、文件读取等知识点。

硬件器材信息(编号、名称、数量、存放地点、所属种类、主要用途)

运转效果:

书本资源信息(图书编号、图书名称、图书数量、图书类、主要用途)

图片 1

主要功用:

代码:

1.登录界面:实现不同用户之报到、找回密码、注册新用户。

  1 #include<stdio.h>
  2 #include<string.h>
  3 #include<stdlib.h>
  4 #include<windows.h>
  5 typedef struct student     //定义结构体
  6 {
  7     char name[20];    //姓名
  8     char num[15];      //学号
  9     char sex[10];     //性别
 10     char from[20];    //籍贯
 11     char political[10];    //政治面貌
 12     char phone[15];      //手机号
 13     char QQ[15];         //QQ号
 14     char dorm[10];     //宿舍
 15     struct student *next;  //结构体指针
 16 }stu;
 17 stu *head;
 18 
 19 void print()    //主菜单
 20 {
 21     system("cls");
 22     printf("\n\n\n");
 23     printf("      ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n");
 24     printf("      ***********************************************************\n");
 25     printf("      \t\t\t班级通讯录管理系统\n");
 26     printf("\n");
 27     printf("      \t\t1. 输入数据");
 28     printf("\t\t2. 显示数据\n");
 29     printf("      \t\t3. 插入数据");
 30     printf("\t\t4. 删除数据\n");
 31     printf("      \t\t5. 查看数据");
 32     printf("\t\t6. 修改数据\n");
 33     printf("      \t\t7. 保存数据");
 34     printf("\t\t8. 返回主菜单\n");
 35     printf("      ***********************************************************\n");
 36     printf("      ~~~~~退~~~~~~~~~~出~~~~~~~~~~请~~~~~~~~~~按~~~~~~~~~~9~~~~~\n");
 37     printf("      -----------------------------------------------------------\n\n");
 38 }
 39 
 40 
 41 void input(stu *p1)    //输入相关数据
 42 {
 43     printf("姓名:");
 44     scanf("%s",&p1->name);
 45     printf("学号:");
 46     scanf("%s",&p1->num);
 47     printf("性别:");
 48     scanf("%s",&p1->sex);
 49     printf("籍贯:");
 50     scanf("%s",&p1->from);
 51     printf("政治面貌:");
 52     scanf("%s",&p1->political);
 53     printf("手机号:");
 54     scanf("%s",&p1->phone);
 55     printf("QQ号:");
 56     scanf("%s",&p1->QQ);
 57     printf("宿舍:");
 58     scanf("%s",&p1->dorm);
 59 }
 60 
 61 
 62 stu * inputdata()     //数据输入的函数
 63 {
 64     stu *p1,*p2;
 65     int i=1;
 66     p1=(stu *)malloc(sizeof(stu));
 67     if(p1!=NULL)
 68     {
 69         head=p1;
 70         printf("\n\t\t\t☆☆☆输入数据☆☆☆\n");
 71         printf("------------------------------------------------------------------\n");
 72         printf("在姓名处输入“ok”代表输入数据结束\n");
 73         while(i)
 74         {
 75             printf("姓名:");
 76             scanf("%s",&p1->name);
 77             if(strcmp(p1->name,"ok")==0)
 78             {
 79                 printf("\n输入完毕!\n");
 80                 printf("========================================================================\n");
 81                 i=0;
 82                 p2->next=NULL;
 83                 free(p1);
 84                 p1=p2;
 85             }
 86             else
 87             {
 88                 printf("学号:");
 89                 scanf("%s",&p1->num);
 90                 printf("性别:");
 91                 scanf("%s",&p1->sex);
 92                 printf("籍贯:");
 93                  scanf("%s",&p1->from);
 94                 printf("政治面貌:");
 95                 scanf("%s",&p1->political);
 96                 printf("手机号:");
 97                 scanf("%s",&p1->phone);
 98                 printf("QQ号:");
 99                 scanf("%s",&p1->QQ);
100                 printf("宿舍:");
101                 scanf("%s",&p1->dorm);
102                 printf("=====================================\n");
103                 p2=p1;
104                 p1=(stu *)malloc(sizeof(stu));
105                 if(p1!=NULL)
106                 {
107                     p2->next=p1;
108                 }
109             }
110         }
111         return(p1->next);
112     }
113 }
114 
115 
116 stu * lookdata(stu *p1)     //查看数据的函数
117 {
118     printf("\n\t\t\t☆☆☆显示数据☆☆☆\n");
119     printf("----------------------------------------------------------------------\n");
120     while(p1!=NULL)
121     {
122         printf("姓名:%s\n",p1->name);
123         printf("学号:%s\t",p1->num);
124         printf("性别:%s\t",p1->sex);
125         printf("籍贯:%s\t",p1->from);
126         printf("政治面貌:%s\t",p1->political);
127         printf("手机号:%s\t",p1->phone);
128         printf("QQ号:%s\t",p1->QQ);
129         printf("宿舍:%s\n",p1->dorm);
130         printf("======================================================================\n");
131         p1=p1->next;
132     }
133     return p1;
134 }
135 
136 
137 void insert()      //插入数据
138 {
139     int i;
140     char named[20];
141     stu *p1,*p2,*p3;
142     p1=head;
143     p3=(stu *)malloc(sizeof(stu));
144     p3->next=NULL;
145     printf("\n\t\t\t☆☆☆插入数据☆☆☆\n");
146     printf("----------------------------------------------------------------------\n");
147     printf("请输入插入者的资料:\n");
148     input(p3);
149     printf("\n插入选项\n");
150     printf("1.首位置插入\t2.尾位置插入\t3.前插\n");
151     printf("请输入你的选择:");
152     scanf("%d",&i);
153     switch(i)
154     {
155     case 1:p3->next=p1;
156         head=p3;
157         break;
158     case 2:while(p1->next!=NULL)
159            {
160                p2=p1;
161                p1=p1->next;
162            }
163         p1->next=p3;
164         break;
165     case 3:printf("请输入姓名(前插):");
166         scanf("%s",named);
167         while(strcmp(named,p1->name)!=0)
168         {
169             p2=p1;
170             p1=p1->next;
171         }
172         p2->next=p3;
173         p3->next=p1;
174         break;
175     }
176     printf("插入成功!\n");
177     printf("======================================================================\n");
178     return;
179 }
180 
181 void deleted()          //删除数据
182 {
183     stu *p1,*p2;
184     char Name[20];  //想要删除的人的姓名
185     printf("\n\t\t\t☆☆☆删除数据☆☆☆\n");
186     printf("----------------------------------------------------------------------\n");
187     printf("请输入要删除的姓名:");
188     scanf("%s",Name);
189     p1=head;
190     if(head==NULL)
191     {
192     printf("内存空空神马都没有!\n");
193     printf("======================================================================\n");
194     return;
195     }
196     if(strcmp(Name,p1->name)==0)
197     {
198     head=p1->next;
199     printf("删除成功!\n");
200     printf("======================================================================\n");
201     return;
202     }
203     while(p1!=NULL&&(strcmp(Name,p1->name)!=0))
204     {
205     p2=p1;
206     p1=p1->next;
207     }
208     if(p1==NULL)
209     {
210     printf("此人不存在!\n");
211     printf("======================================================================\n");
212     return;
213     }
214     if(p1->next!=NULL)
215     {
216     p1=p1->next;
217     p2->next=p1;
218     printf("删除成功!\n");
219     printf("======================================================================\n");
220     return;
221     }
222     else
223     {
224     p2->next=NULL;
225     printf("删除成功!\n");
226     printf("======================================================================\n");
227     return;
228     }
229 }
230 
231 
232 find(stu *p2)        //通过姓名查找查看数据的函数
233 {
234     char name[20];
235     int b=0;
236     printf("\n\t\t\t☆☆☆查看数据☆☆☆\n");
237     printf("----------------------------------------------------------------------\n");
238     printf("请输入您想查找人的姓名:");
239     scanf("%s",name);
240     while(p2!=NULL)
241     {
242         if(strcmp(name,p2->name)==0)
243         {
244             printf("你要找到的数据\n");
245             printf("姓名:%s\n",p2->name);
246             printf("学号:%s\t",p2->num);
247             printf("性别:%s\t",p2->sex);
248             printf("籍贯:%s\t",p2->from);
249             printf("政治面貌:%s\t",p2->political);
250             printf("手机号:%s\t",p2->phone);
251             printf("QQ号:%s\t",p2->QQ);
252             printf("宿舍:%s\n",p2->dorm);
253             printf("======================================================================\n");
254             b=1;
255         }
256         p2=p2->next;
257     }
258     if(b==0)
259     {
260         printf("\n您要查找的人不存在!\n");
261     }
262 }
263 
264 
265 update(stu *p2)   //通过姓名查找修改数据
266 {
267     char name[20];
268     int b=0,i;
269     printf("\n\t\t\t☆☆☆修改数据☆☆☆\n");
270     printf("----------------------------------------------------------------------\n");
271     printf("请输入将要修改人的姓名:");
272     scanf("%s",name);
273     while(p2!=NULL)
274     {
275         if(strcmp(name,p2->name)==0)
276         {
277             printf("该同学的基本信息\n");
278             printf("姓名:%s\n",p2->name);
279             printf("学号:%s\t",p2->num);
280              printf("性别:%s\t",p2->sex);
281             printf("籍贯:%s\t",p2->from);
282             printf("政治面貌:%s\t",p2->political);
283             printf("手机号:%s\t",p2->phone);
284             printf("QQ号:%s\t",p2->QQ);
285             printf("宿舍:%s\n",p2->dorm);
286             printf("\n请选择要修改的信息\n");
287             printf("\t1.姓名\t2.学号\t3.性别\t4.籍贯\n\t5.政治面貌\t6.手机号\t7.QQ\t8.宿舍\n");
288             printf("\n您的选择是(1~8):");
289             scanf("%d",&i);
290             printf("请输入修改之后的内容\n");
291             switch(i)
292             {
293             case 1:printf("姓名:");
294                 scanf("%s",&p2->name);
295                 break;
296             case 2:printf("学号:");
297                 scanf("%s",&p2->num);
298                 break;
299             case 3:printf("性别:");
300                 scanf("%s",&p2->sex);
301                 break;
302             case 4:printf("籍贯:");
303                 scanf("%s",&p2->from);
304                 break;
305             case 5:printf("政治面貌:");
306                 scanf("%s",&p2->political);
307                 break;
308             case 6:printf("手机号:");
309                 scanf("%s",&p2->phone);
310                 break;
311             case 7:printf("QQ:");
312                 scanf("%s",&p2->QQ);
313                 break;
314             case 8:printf("宿舍:");
315                 scanf("%d",&p2->dorm);
316                 break;
317             }
318             printf("\n修改成功!\n");
319             printf("=========================================================================\n");
320             b=1;
321         }
322         p2=p2->next;
323     }
324     if(b==0)
325     {
326         printf("没有找到该人的资料!\n");
327     }
328 }
329 
330 
331 save(stu *p2)   //保存数据
332 {
333     FILE *fp;
334     char file[15];
335     printf("\n\t\t\t☆☆☆保存数据☆☆☆\n");
336     printf("----------------------------------------------------------------------\n");
337     printf("输入文件名:");
338     scanf("%s",file);
339     if((fp=fopen(file,"w"))==NULL)
340     {
341         printf("cannot open this file\n");
342         exit(0);
343     }
344     fprintf(fp,"姓名\t学号\t性别\t籍贯\t政治面貌\t手机号\tQQ号\t宿舍\n");
345     while(p2!=NULL)
346     {
347         fprintf(fp,"%s\t",p2->name);
348         fprintf(fp,"%s\t",p2->num);
349         fprintf(fp,"%s\t",p2->sex);
350         fprintf(fp,"%s\t",p2->from);
351         fprintf(fp,"%s\t",p2->political);
352         fprintf(fp,"%s\t",p2->phone);
353         fprintf(fp,"%s\t",p2->QQ);
354         fprintf(fp,"%s\n",p2->dorm);
355         p2=p2->next;
356     }
357     printf("\n保存成功!\n");
358     printf("======================================================================\n");
359     fclose(fp);
360 }
361 
362 
363 void screen()  
364 {
365     int i;
366     char s[251]={"欢迎使用由ZM制作班级通讯录管理系统,\n\n\t\t\t本系统用于通讯录管理----排序,打印\n\n\n\t\tWelcome to use produced by ZM class address book\n\n\t\t management system,sorting,printing"};
367     
368     printf("\n================================================================================\n");
369     printf("\n\n\n\t\t\t");
370     for(i=0;s[i]!=NULL;i++)
371     {
372         Sleep(30);
373         printf("%c",s[i]);
374     }
375     printf("\n\n\n\n\n\n\n\n\t\t ~ Hi~ o(* ̄▽ ̄*)ブ~ ~ ~祝您旅途愉快~ ~\n");
376     printf("================================================================================\n");
377 
378 }
379 
380 
381 void main()
382 {
383     int i;
384     system("color 4e");
385     screen();
386     Sleep(3000);
387     print();
388     while(1)
389     {
390         printf("请输入你的选择(1~9):");
391         loop:scanf("%d",&i);
392         if(i<1||i>9)
393         {
394             printf("输入有误,请在1~9中进行选择:");
395             goto loop;
396         }
397         switch(i)
398         {
399         case 1:
400             inputdata();
401             break;
402         case 2:
403             lookdata(head);
404             break;
405         case 3:
406             insert();
407             break;
408         case 4:
409              deleted();
410             break;
411         case 5:
412             find(head);
413             break;
414         case 6:
415             update(head);
416             break;
417         case 7:
418             save(head);
419             break;
420         case 8:
421             print();
422             break;
423         case 9:
424             exit(1);
425             break;
426         }
427     }
428 }

2。普通用户登录后效果选择:查询资源记录、借还资源、修改个人信息。

 

3.管理登录可以长新的耗材记录、修改用户信息。

 

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

#include<conio.h>

 

struct personal_message{          //个人信息 

char name[10];

char num[12];

char sex[6];

char classes[15];

char QQ[12];

char Tel[12];

}p;

 

struct book{                          //图书信息        

char name[20];

char num[10];

int member;

int borrow;

}books,book1[50];

 

struct sysuser{                          //用户名和密码 

char username[16];

char password[7];

}sd,sy;

 

struct consumables{                  //耗材信息 

char name[20];

int member;

}con,con1;

 

void registe();                        //注册 

void enter();        //登录 

int validate();             
 //验证管理员(root) 

void find_password();               //找回密码 

void modification_information();     //修改信息 

void modification_password();       //修改密码 

void resource_record();       
//查询书籍信息 

void add_book();        //添加书籍 

void borrow_repay();                     //书籍借还 

void borrow();                 
//借书 

void repay();            //还书 

void consumables_record();         //查询耗材 

void check_consumables();          //耗材信息 

void add_consumables();              // 添加耗材 

void add_administrator();              //添加管理员

void star(char mima[]);                 //密码变 *

void page_design1();                    //登录页面 

void page_design2();        

void page_design3();  

void page_design4();

void page_design5();  

void page_design6();

FILE *fp;

FILE *fp1;

FILE *fp2;

FILE *fp3;

int fog=0,j=0;

char mima[7];

 

int main(void)

{

struct personal_message h,*o;

o=&h;

int n,m,flag;

char st[100],s[20];

//
loop:printf(“1-登录\t2-注册\n”);

  loop:page_design1();

scanf(“%d”,&n);

system(“CLS”);

 

switch(n)

{

case 1:

{

enter();

validate();

system(“CLS”);

}break;

 

case 2:

{

registe();

system(“CLS”);

goto loop;

}break;

case 3:

{

find_password();

system(“CLS”);

goto loop;

}break;

}

 

lo:if((fp=fopen(“information.txt”,”r”))==NULL)    /*著个人信息
*/

{

printf(“File open error!\n”);

exit(0);

}

 

rewind(fp);

fseek(fp,j*sizeof(struct
personal_message),0);

    fread(&h,sizeof(struct
personal_message),1,fp);

printf(“姓名:%s\n”,h.name);

printf(“性别:%s\n”,h.sex);

printf(“学号:%s\n”,h.num);

printf(“专业班级:%s\n”,h.classes);

printf(“QQ:%s\n”,h.QQ);

printf(“电话:%s\n”,h.Tel);

 

if(fclose(fp))

{

printf(“Can not close the
file!\n”);

exit(0);

}

 

//printf(“1-修改个人信息\t2-查询图书资源\t3-借还资源\t4-修改密码\n”); 

page_design2();    

if(fog==1)

page_design3();    

//
printf(“5-添加图书\t6-耗材信息\t7-添加领队\n”);

printf(“\t\t\t*———————-*\n”);

printf(“\t\t\t************************\n”);

scanf(“%d”,&m);

system(“CLS”);

 

switch(m)

{

case
1:modification_information();break;

case 2:resource_record();break;

case 3:borrow_repay();break;

case
4:modification_password();break;

case 5:add_book();break;

case 6:consumables_record();break;

case 7:add_administrator();break;

}

//
printf(“按1键返回首页,按2键退出\n”);

page_design6();

scanf(“%d”,&flag);

system(“CLS”);

if(flag==1)

goto lo;

 

return 0;

}

 

void registe() /*注册*/ 

{

char c[7];

    struct sysuser sa;

printf(“用户名:”);

scanf(“%s”,sa.username);

for(;;)

{

printf(“密码:”);

//scanf(“%s”,sa.password);

star(sa.password);

printf(“确认密码:”);

//scanf(“%s”,c);

star(c);

if(strcmp(c,sa.password)==0)

break;

}

if((fp3=fopen(“sysusers.txt”,”a”))==NULL)

{

printf(“File open error!\n”);

exit(0);

}

//fputs(&sa,fp3);

fwrite(&sa,sizeof(struct
sysuser),1,fp3);

 

if(fclose(fp3))

{

printf(“Can not close the
file!\n”);

exit(0);

}

system(“CLS”);

 

printf(“姓名:”);

scanf(“%s”,p.name);

printf(“性别:”);

scanf(“%s”,p.sex);

printf(“学号:”);

scanf(“%s”,p.num);

printf(“专业班级:”);

scanf(“%s”,p.classes);

printf(“QQ:”);

scanf(“%s”,p.QQ);

printf(“电话:”);

scanf(“%s”,p.Tel);

 

if((fp=fopen(“information.txt”,”a”))==NULL)

{

printf(“File open error!\n”);

exit(0);

}

 

fwrite(&p,sizeof(struct
personal_message),1,fp);

 

if(fclose(fp))

{

printf(“Can not close the
file!\n”);

exit(0);

}

printf(“注册成功!\n”);

}

 

void enter() /*登录 */

int count=0;

for(;;)

{

printf(“用户名:”);

scanf(“%s”,sy.username);

printf(“密码:”);

//
scanf(“%s”,sy.password);

star(sy.password);

if((fp3=fopen(“sysusers.txt”,”r”))==NULL)

{

printf(“File open error!\n”);

exit(0);

}

while(!feof(fp3))

{

fread(&sd,sizeof(struct
sysuser),1,fp3);

if(strcmp(sy.username,sd.username)==0 &&
strcmp(sy.password,sd.password)==0)

{

count=1;

break;

}

j++;

}

 

if(fclose(fp3))

{

printf(“Can not close the
file!\n”);

exit(0);

}

 

if(count == 1)

{

printf(“登录成功!\n”);

break;

}

else

printf(“用户称以及密码不般配!\n”);

 

}

}

 

int validate() /*证是否是管理员(root)
*/

{

int l1;

l1=strlen(sd.username);

if(sd.username[l1-4]==’r’ &&
sd.username[l1-3]==’o’ && sd.username[l1-2]==’o’ &&
sd.username[l1-1]==’t’)

fog=1;

else

fog=0;

return fog;

}

 

void find_password()    //找回密码 

{

struct sysuser sr,sr1;

int b=0;

char b1[7];

lp:printf(“请输入用户称:”);

scanf(“%s”,sr1.username);

if((fp3=fopen(“sysusers.txt”,”r+”))==NULL)

{

printf(“File open error!\n”);

exit(0);

}

while(!feof(fp3))

{

 

fread(&sr,sizeof(struct
sysuser),1,fp3);

if(strcmp(sr.username,sr1.username)==0)

break;

else

    b++;

}

if(feof(fp3)==-1)

{

printf(“找不交该用户名”);

goto lp;

}

else

{

for(;;)

{

printf(“请输入新密码:”);

//
scanf(“%s”,sr1.password);

star(sr1.password);

printf(“请确认新密码:”);

//
scanf(“%s”,b1);

star(b1);

if(strcmp(b1,sr1.password)==0)

break;

}

rewind(fp3);

strcpy(sr.password,sr1.password);

fseek(fp3,b*sizeof(struct
sysuser),0);

fwrite(&sr,sizeof(struct
sysuser),1,fp3);

}

if(fclose(fp3))

{

printf(“Can not close the
file!\n”);

exit(0);

}

}

 

void modification_information() 
/*改个人信息 */

{

struct personal_message p1;

printf(“姓名:”);

scanf(“%s”,p1.name);

printf(“性别:”);

scanf(“%s”,p1.sex);

printf(“学号:”);

scanf(“%s”,p1.num);

printf(“专业班级:”);

scanf(“%s”,p1.classes);

printf(“QQ:”);

scanf(“%s”,p1.QQ);

printf(“电话:”);

scanf(“%s”,p1.Tel);

if((fp=fopen(“information.txt”,”w”))==NULL)

{

printf(“File open error!\n”);

exit(0);

}

rewind(fp);

fseek(fp,j*sizeof(personal_message),0);

fwrite(&p1,sizeof(personal_message),1,fp);

if(fclose(fp))

{

printf(“Can not close the
file!\n”);

exit(0);

}

}

 

void modification_password()  //修改密码 

{

struct sysuser su,su1;

char b[7];

for(;;)

{

printf(“请输入新密码:”);

//scanf(“%s”,su.password);

star(su.password);

if(strcmp(su.password,b)==0)

break;

 

printf(“请确认密码:”);

//scanf(“%s”,b);

star(b);

if(strcmp(b,su.password)==0)

break;

}

if((fp3=fopen(“sysusers.txt”,”r+”))==NULL)

{

printf(“File open error!\n”);

exit(0);

}

rewind(fp3);

fseek(fp3,j*sizeof(struct
sysuser),0);

fread(&su1,sizeof(struct
sysuser),1,fp3);

strcpy(su1.password,su.password);

fseek(fp3,j*sizeof(struct
sysuser),0);

fwrite(&su1,sizeof(struct
sysuser),1,fp3);

if(fclose(fp3))

{

printf(“Can not close the
file!\n”);

exit(0);

}

printf(“修改成功!\n”);

}

 

void resource_record() /* 图书资源查看
*/

{

int w;

if((fp1=fopen(“resource.txt”,”r”))==NULL)

{

printf(“File open error!\n”);

exit(0);

}

fseek(fp1,0,2); //文件末 

    w=ftell(fp1);           //文件指针的职位 

fseek(fp1,0,0);  //文件首 

while(w!=ftell(fp1))

// while(!feof(fp1))              

{

fread(&books,sizeof(struct
book),1,fp1);

printf(“书名:%s\n”,books.name);

printf(“编号:%s\n”,books.num);

printf(“数量:%d\n”,books.member);

printf(“已借:%d\n”,books.borrow);

printf(“\n”);

}

if(fclose(fp1))

{

printf(“Can not close the
file!\n”);

exit(0);

}

}

 

void add_book() /*上加图书 */

{

int count;

printf(“请输入而增补加书的本数:”);

scanf(“%d”,&count);

while(count–)

{

printf(“书名:”);

scanf(“%s”,books.name);

printf(“编号:”);

scanf(“%s”,books.num);

printf(“数量:”);

scanf(“%d”,&books.member);

printf(“已借:”);

scanf(“%d”,&books.borrow);

if((fp1=fopen(“resource.txt”,”a”))==NULL)

{

printf(“File open error!\n”);

exit(0);

}

 

fwrite(&books,sizeof(struct
book),1,fp1);

 

if(fclose(fp1))

{

printf(“Can not close the
file!\n”);

exit(0);

}

if(count!=0)

printf(“\n”);

}

}

 

void borrow_repay() /*书籍借还 */

{

int k;

//printf(“1-借\t2-还\n”);

page_design4();

scanf(“%d”,&k);

switch(k)

{

case 1:borrow();break;

case 2:repay();break;

}

}

 

void borrow() /*借书 */

{

int i=0;

char a2[20];

printf(“请输入而借的开之号子:”);

scanf(“%s”,a2);

if((fp1=fopen(“resource.txt”,”r+”))==NULL)

{

printf(“File open error!\n”);

exit(0);

}

while(!feof(fp1))

{

fread(&book1[i],sizeof(struct
book),1,fp1);

if(strcmp(a2,book1[i].num)==0)

{

 

book1[i].member–;

book1[i].borrow++;

rewind(fp1);

fseek(fp1,i*sizeof(struct
book),0);

fwrite(&book1[i],sizeof(struct
book),1,fp1);

break;

}

i++;

}

if(fclose(fp1))

{

printf(“Can not close the
file!\n”);

exit(0);

}

printf(“借书成功!\n”);

}

 

void repay() /*还书*/ 

{

int i=0;

char a3[20];

printf(“请输入而还的书的编号:”);

scanf(“%s”,a3);

if((fp1=fopen(“resource.txt”,”r+”))==NULL)

{

printf(“File open error!\n”);

exit(0);

}

while(!feof(fp1))

{

fread(&book1[i],sizeof(struct
book),1,fp1);

if(strcmp(a3,book1[i].num)==0)

{

 

book1[i].member++;

book1[i].borrow–;

rewind(fp1);

fseek(fp1,i*sizeof(struct
book),0);

fwrite(&book1[i],sizeof(struct
book),1,fp1);

break;

}

i++;

}

if(fclose(fp1))

{

printf(“Can not close the
file!\n”);

exit(0);

}

printf(“还开成功!\n”);

}

 

void consumables_record() /*耗材管理
*/

{

int m1;

//printf(“1-查看耗材\t2-增加耗材\n”);

page_design5();

scanf(“%d”,&m1);

switch(m1)

{

case 1:check_consumables();break;

case 2:add_consumables();break;

}

}

 

void check_consumables() /*查阅耗材
*/

{

system(“CLS”);

int w1;

if((fp2=fopen(“consumables.txt”,”r”))==NULL)

{

printf(“File open error!\n”);

exit(0);

}

fseek(fp2,0,2); //文件末 

    w1=ftell(fp2);           //文件指针的职位 

fseek(fp2,0,0);

while(w1!=ftell(fp2))

// while(!feof(fp2))              

{

fread(&con,sizeof(struct
consumables),1,fp2);

printf(“名称:%s\n”,con.name);

printf(“数量:%d\n”,con.member);

printf(“\n”);

}

if(fclose(fp2))

{

printf(“Can not close the
file!\n”);

exit(0);

}

}

 

void add_consumables()  /*加耗材
*/

{

system(“CLS”);

printf(“请输入增加的耗材名称:”);

scanf(“%s”,con1.name);

printf(“请输入该耗材的数量:”);

scanf(“%d”,&con1.member);

if((fp2=fopen(“consumables.txt”,”a”))==NULL)

{

printf(“File open error!\n”);

exit(0);

}

 

fwrite(&con1,sizeof(struct
consumables),1,fp2);

 

if(fclose(fp2))

{

printf(“Can not close the
file!\n”);

exit(0);

}

printf(“添加事业有成!\n”);

}

 

void add_administrator()
/*长领队*/ 

{

struct sysuser sw;

char a4[16];

char a5[5]={“root”};

int l2=0,w2;

loop:printf(“请输入而加加成管理员的用户称:”);

scanf(“%s”,a4);

if((fp3=fopen(“sysusers.txt”,”r+”))==NULL)

{

printf(“File open error!\n”);

exit(0);

}

fseek(fp3,0,2);

    w2=ftell(fp3);

fseek(fp3,0,0);

while(!feof(fp3))

{

fread(&sw,sizeof(struct
sysuser),1,fp3);

 

if(strcmp(sw.username,a4)==0)

{

strcat(sw.username,a5);

//
rewind(fp3);

//
fseek(fp3,l2*sizeof(struct sysuser),0);

fseek(fp3,l2*sizeof(struct
sysuser),0);

fwrite(&sw,sizeof(struct
sysuser),1,fp3);

printf(“添加事业有成!\n”);

break;

}

else

{

l2++;

if(w2==ftell(fp3))

{

printf(“找不至该用户!\n”);

goto loop;

}

}

}

if(fclose(fp3))

{

printf(“Can not close the
file!\n”);

exit(0);

}

}

 

void star(char mima[])

{

for(int i=0;;i++)
//以*号显示所输入密码,i并无紧要,这里可以安装成最循环。 

{

mima[i]=getch();

if(mima[i]==’\r’)
//getch()函数读到转车键则脱离

{

printf(“\n”);

mima[i]=’\0′;

break;

}

else if((mima[i]==8)&&i>0)
//关于是否退格的判定

{

printf(“\b \b”);

i=i-2;

}

else if(mima[i]!=8)
//如果输入的未是退格键(8凡是退格键的Ascii码值),那么尽管输出星号。

{

printf(“*”);

}

}

}

 

 

void page_design1()

{

printf(“\n\n\n”);

printf(“\t\t\t************************\n”);

printf(“\t\t\t*———————-*\n”);

printf(“\t\t\t*—1-登录————-*\n”);

printf(“\t\t\t*—2-注册————-*\n”);

printf(“\t\t\t*—3-找回密码———*\n”);

printf(“\t\t\t*———————-*\n”);

printf(“\t\t\t************************\n”);

}

 

void page_design2()

{

printf(“\n\n”);

printf(“\t\t\t************************\n”);

printf(“\t\t\t*———————-*\n”);

printf(“\t\t\t*—1-修改个人信息—–*\n”);

printf(“\t\t\t*—2-查询图书资源—–*\n”);

printf(“\t\t\t*—3-借还资源———*\n”);

printf(“\t\t\t*—4-修改密码———*\n”);

}

 

void page_design3()

{

printf(“\t\t\t*—5-添加图书———*\n”);

printf(“\t\t\t*—6-耗材信息———*\n”);

printf(“\t\t\t*—7-添加管理员——-*\n”);

}

void page_design4()

{

printf(“\t\t\t************************\n”);

printf(“\t\t\t*———————-*\n”);

printf(“\t\t\t*—1-借—————*\n”);

printf(“\t\t\t*—2-还—————*\n”);

printf(“\t\t\t*———————-*\n”);

printf(“\t\t\t************************\n”);

}

void page_design5()

{

printf(“\t\t\t************************\n”);

printf(“\t\t\t*———————-*\n”);

printf(“\t\t\t*—1-查看耗材———*\n”);

printf(“\t\t\t*—2-添加耗材———*\n”);

printf(“\t\t\t*———————-*\n”);

printf(“\t\t\t************************\n”);

}

 

void page_design6()

{

printf(“\t\t\t************************\n”);

printf(“\t\t\t*———————-*\n”);

printf(“\t\t\t*—1-返回首页———*\n”);

printf(“\t\t\t*—2-退出————-*\n”);

printf(“\t\t\t*———————-*\n”);

printf(“\t\t\t************************\n”);

}

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图