图书管理系统1.0by P_LarT

原创 2016年06月01日 08:40:05

结构图
VS下预编译头

#include "stdafx.h"
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <process.h>

char password_admin[]="123456";

struct student
{
    int stu_num;//20个字节
    char password[20];
    char stu_name[20];
    char stu_sex;
    int stu_class;
}stu[20];

struct book
{
    int book_num;
    char book_name[20];
    char book_writer[20];
    float book_price;
    char book_press[20];
    int book_lastnum; 
    int book_frequency;
}bk[20];

struct recordofbook
{
    char book_name[20];
    int book_user;
}recordbook[20];

/********************辅助函数**************************/

void DisplayBook()//显示书籍信息
{
    int i;
    printf("\t\t/*******************************/\n");
    printf("\t\t/**********现有书籍状况***********/\n");
    printf("\t\t/*******************************/\n");

    FILE* fp = fopen("book.txt","r");
    for (i=0;fread(&bk[i],sizeof(struct book),1,fp)!=0;i++)
    {
        printf("/--------------%d------------------/\n",i+1);
        printf("书号:%d\n",bk[i].book_num);
        printf("书名:%s\n",bk[i].book_name);
        printf("作者:%s\n",bk[i].book_writer);
        printf("单价:%.2f\n",bk[i].book_price);
        printf("书社:%s\n",bk[i].book_press);
        printf("数量:%d\n",bk[i].book_lastnum);
        printf("频率:%d\n",bk[i].book_frequency);
        printf("/--------------%d------------------/\n",i+1);
    }
    fclose(fp);
}

void DisplayStu()
{
    printf("\t\t/*******************************/\n");
    printf("\t\t/**********现有学生状况***********/\n");
    printf("\t\t/*******************************/\n");
    int i;
    FILE* fp = fopen("student.txt","r");
    for (i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0;i++)
    {
        printf("/--------------%d------------------/\n",i+1);
        printf("学号:%d\n",stu[i].stu_num);
        printf("密码:%s\n",stu[i].password);
        printf("性别:%c\n",stu[i].stu_sex);
        printf("名字:%s\n",stu[i].stu_name);
        printf("班级:%d\n",stu[i].stu_class);
        printf("/--------------%d------------------/\n",i+1);
    }
    fclose(fp);
}

void Hello()
{
    system("cls");
    printf("\t\t********************************\n");
    printf("\t\t********************************\n");
    printf("\t\t******欢迎进入图书管理系统******\n");
    printf("\t\t********************************\n");
    printf("\t\t********************************\n");
}

/************************图书操作*************************/

void AddBook()
{
    FILE *fp;
    int i = 0;

    fp = fopen("book.txt","a+");
    do
    {
        Hello();
        DisplayBook();
        printf("书号:");
        scanf("%d",&bk[i].book_num);
        printf("书名:");
        scanf("%s",bk[i].book_name);
        printf("作者:");
        scanf("%s",bk[i].book_writer);
        printf("单价:");
        scanf("%f",&bk[i].book_price);
        printf("书社:");
        scanf("%s",bk[i].book_press);
        printf("数量:");
        scanf("%d",&bk[i].book_lastnum);
        bk[i].book_frequency = 0;
        fwrite(&bk[i],sizeof(struct book),1,fp);
        printf("成功入库一本书:《%s》\n",bk[i++].book_name);
        fclose(fp);

        DisplayBook();
        printf("若还想加书可以按y;其他任意键返回上一级\n");
    }while(getch() == 'y');
}

void DeleteBook()
{
    FILE *fp1,*fp2;
    int i;
    char bookname[20];

    do 
    {
        Hello();
        DisplayBook();
        printf("书名:\n");
        fflush(stdin);
        gets(bookname);

        fp1 = fopen("book.txt","r");
        fp2 = fopen("book1.txt","w");
        for(i=0;fread(&bk[i],sizeof(struct book),1,fp1)!=0;i++)
        {
            if(strcmp(bookname,bk[i].book_name)!=0)
            {
                fwrite(&bk[i],sizeof(struct book),1,fp2);
            }
        }
        fclose(fp1);
        fclose(fp2);

        fp1 = fopen("book.txt","w");
        fp2 = fopen("book1.txt","r");

        for(i=0;fread(&bk[i],sizeof(struct book),1,fp2)!=0;i++)
        {
            fwrite(&bk[i],sizeof(struct book),1,fp1);
        }
        fclose(fp1);
        fclose(fp2);

        fp2 = fopen("book1.txt","w");
        fclose(fp2);

        DisplayBook();
        printf("删除成功,若还想删书可以按y;其他任意键退出\n");
    } while (getch() == 'y');
}

void ModifyBook()
{
    FILE *fp1,*fp2;
    int i;
    char bookname[20];

    do 
    {
        Hello();
        DisplayBook();
        printf("书名:");
        fflush(stdin);
        gets(bookname);

        fp1 = fopen("book.txt","r");
        fp2 = fopen("book1.txt","w");
        for(i=0;fread(&bk[i],sizeof(struct book),1,fp1)!=0;i++)
        {
            if(strcmp(bk[i].book_name,bookname)==0)
            {
                printf("你所要修改的书的资料如下,请选择你要修改的内容:\n");
                printf("/----------------%d----------------/\n",i+1);
                printf("书号:%d\n",bk[i].book_num);
                printf("书名:%s\n",bk[i].book_name);
                printf("作者:%s\n",bk[i].book_writer);
                printf("单价:%.2f\n",bk[i].book_price);
                printf("书社:%s\n",bk[i].book_press);
                printf("数量:%d\n",bk[i].book_lastnum);
                printf("/---------------%d-----------------/\n",i+1);
                printf("1: 修改书号:\n");
                printf("2: 修改书名:\n");
                printf("3: 修改作者:\n");
                printf("4: 修改书价:\n");
                printf("5: 修改书社:\n");
                printf("6: 修改数量:\n");
                printf("0: 退出;\n");
                printf("请输入0~6:");
                fflush(stdin);
                switch(getch())
                {
                case '1':
                    {
                        printf("新书号:");
                        scanf("%d",&bk[i].book_num);
                        fwrite(&bk[i],sizeof(struct book),1,fp2);
                        break;
                    }
                case '2':
                    {
                        printf("新书名:");
                        scanf("%s",bk[i].book_name);
                        fwrite(&bk[i],sizeof(struct book),1,fp2);
                        break;
                    }
                case '3':
                    {
                        printf("新作者:");
                        scanf("%s",bk[i].book_writer);
                        fwrite(&bk[i],sizeof(struct book),1,fp2);
                        break;
                    }
                case '4':
                    {
                        printf("新书价:");
                        scanf("%f",bk[i].book_price);
                        fwrite(&bk[i],sizeof(struct book),1,fp2);
                        break;
                    }
                case '5':
                    {
                        printf("新书社:");
                        scanf("%s",bk[i].book_press);
                        fwrite(&bk[i],sizeof(struct book),1,fp2);
                        break;
                    }
                case '6':
                    {
                        printf("新数目:");
                        scanf("%d",bk[i].book_lastnum);
                        fwrite(&bk[i],sizeof(struct book),1,fp2);
                        break;
                    }
                case '0':
                    return;
                default:
                    printf("没有这样的操作!");
                }
            }
            fwrite(&bk[i],sizeof(struct book),1,fp2);
        }
        fclose(fp1);
        fclose(fp2);

        fp1=fopen("book.txt","w");
        fp2=fopen("book1.txt","r");
        for(i=0;fread(&bk[i],sizeof(struct book),1,fp2)!=0;i++)
        {
            fwrite(&bk[i],sizeof(struct book),1,fp1);
        }
        fclose(fp1);

        fp2=fopen("book1.txt","w");
        fclose(fp2);
        DisplayBook();
        printf("若还想改书可以按y;其他任意键退出\n");
    } while (getch() == 'y');
}

void CountBook()//将统计出被借频率最高的三本书
{
    FILE *fp;
    book temp_book;
    int i,j,k,t,bookfrequency[20],flag;
    Hello();

    fp = fopen("book.txt","r");
    for(i=0;fread(&bk[i],sizeof(struct book),1,fp)!=0;i++)
    {}
    fclose(fp);

    for(i=0;i<19;i++ )
    {
        k=i;
        flag=1;                 
        for(j=i+1;j<20;j++)
        {
            if(bk[j].book_frequency >bk[k].book_frequency)
            {
                k=j;
                flag=0;
            }
        }
        if(flag) 
        {
            break;  
        }
        if(k!=i)
        {
            temp_book = bk[i];
            bk[i] = bk[i+1];
            bk[i+1] = temp_book;
        }
    }
    int count = 0;
    for( i=0; i<3; i++)  
    {       
        if (bk[i].book_frequency == 0)
        {
            count++;
            continue;
        }
        printf("/----------------%d----------------/\n",i+1);
        printf("书号:%d\n",bk[i].book_num);
        printf("书名:%s\n",bk[i].book_name);
        printf("作者:%s\n",bk[i].book_writer);
        printf("单价:%.2f\n",bk[i].book_price);
        printf("书社:%s\n",bk[i].book_press);
        printf("数量:%d\n",bk[i].book_lastnum);
        printf("频率:%d\n",bk[i].book_frequency);
        printf("/----------------%d----------------/\n",i+1);
    }
    if (count == 3)
    {
        printf("尚未有书被借过...");
    }
}

void FindBook()
{
    FILE *fp;
    char bookname[20];
    int i,flag;


    do 
    {   
        Hello();
        printf("请输入你要查找的书名:");
        fflush(stdin);
        scanf("%s",bookname);
        flag=0;
        fp=fopen("book.txt","r");
        for(i=0;fread(&bk[i],sizeof(struct book),1,fp)!=0;i++)
        {
            if(strcmp(bookname,bk[i].book_name) == 0)
            {
                printf("/--------------%d------------------/\n",i+1);
                printf("书号:%d\n",bk[i].book_num);
                printf("书名:%s\n",bk[i].book_name);
                printf("作者:%s\n",bk[i].book_writer);
                printf("单价:%.2f\n",bk[i].book_price);
                printf("书社:%s\n",bk[i].book_press);
                printf("数量:%d\n",bk[i].book_lastnum);
                printf("频率:%d\n",bk[i].book_frequency);
                printf("/--------------%d------------------/\n",i+1);
                flag=1;
                break;
            }
        }
        fclose(fp);
        if (flag == 0)
        {
            printf("抱歉无此书!\n");
        }
        printf("若还想查书可以按y;其他任意键退出\n");
    } while (getch() == 'y');

}

void BorrowBook()
{
    FILE *fp1,*fp2;
    int i,n=-1,flag;
    int stunum;

    do 
    {
        Hello();
        printf("书名:");
        fflush(stdin);
        gets(recordbook[++n].book_name);
        flag=0;
        fp1=fopen("book.txt","r");
        for(i=0;fread(&bk[i],sizeof(struct book),1,fp1)!=0;i++)
        {
            if(strcmp(bk[i].book_name,recordbook[n].book_name) == 0)
            {
                if(bk[i].book_lastnum == 0) 
                {
                    printf("已全部借出,按任意键返回\n");
                    fclose(fp1);
                    getch();
                    break;
                }
                fclose(fp1);

                fp1=fopen("record.txt","a+");//记录借书信息
                printf("请输您的学号:\n");
                scanf("%d",&stunum);
                recordbook[n].book_user = stunum;
                fwrite(&recordbook[n],sizeof(struct student),1,fp1);
                fclose(fp1);

                fp1=fopen("book.txt","r");
                fp2=fopen("book1.txt","w");
                for(i=0;fread(&bk[i],sizeof(struct book),1,fp1)!=0;i++)
                {
                    if(strcmp(bk[i].book_name,recordbook[n].book_name) == 0)
                    {
                        bk[i].book_lastnum -= 1;
                        bk[i].book_frequency +=1;
                        fwrite(&bk[i],sizeof(struct book),1,fp2);
                        continue;
                    }
                    fwrite(&bk[i],sizeof(struct book),1,fp2);
                }
                fclose(fp1);
                fclose(fp2);

                fp1=fopen("book.txt","w");
                fp2=fopen("book1.txt","r");
                for(i=0;fread(&bk[i],sizeof(struct book),1,fp2)!=0;i++)
                {
                    fwrite(&bk[i],sizeof(struct book),1,fp1);
                }
                fclose(fp1);
                fclose(fp2);

                fopen("book1.txt","w");
                fclose(fp2);

                printf("借书成功,按任意键返回...\n");
                getch();
                flag = 1;
                break;
            }
        }
        if (flag == 0)
        {
            printf("此书不存在...\n");
            fclose(fp1);
        }
        printf("若还想借书可以按y;其他任意键退出\n");  
    } while (getch() == 'y');   
}

void RerurnBook()
{
    FILE *fp,*fp1,*fp2; 
    int i,flag=0;
    int stunum=0;
    char lendbook[20];

    Hello();
    printf("请输入学号:");
    scanf("%d",&stunum);

    fp=fopen("student.txt","r");
    for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0;i++)//是否注册
    {
        if(stu[i].stu_num == stunum)//寻找到学生信息
        {
            flag = 1;
        }
    }
    if (flag == 0)
    {
        printf("您未注册...\n");
        return;
    }

    do 
    {
        flag = 0;
        printf("请输入你要还的书的名字:");
        fflush(stdin);
        gets(lendbook);

        fp=fopen("record.txt","r");
        for(i=0;fread(&recordbook[i],sizeof(struct student),1,fp)!=0;i++) /*判断是否是该用户借阅了输入的书*/
        {
            if(strcmp(recordbook[i].book_name,lendbook)==0 && recordbook[i].book_user == stunum)
            {
                fclose(fp);

                fp1=fopen("record.txt","r");
                fp2=fopen("book1.txt","w");
                for(i=0;fread(&recordbook[i],sizeof(struct student),1,fp1)!=0;i++)
                {
                    if(strcmp(recordbook[i].book_name,lendbook) != 0)//删除借阅信息
                    {
                        fwrite(&recordbook[i],sizeof(struct student),1,fp2); 
                    }
                }
                fclose(fp1);
                fclose(fp2);

                fp1=fopen("record.txt","w");
                fp2=fopen("book1.txt","r");
                for(i=0;fread(&recordbook[i],sizeof(struct student),1,fp2)!=0;i++)
                {
                    fwrite(&recordbook[i],sizeof(struct student),1,fp1);
                }
                fclose(fp1);
                fclose(fp2);

                fopen("book1.txt","w");
                fclose(fp2);

                fp1=fopen("book.txt","r");
                fp2=fopen("book1.txt","w");
                for(i=0;fread(&bk[i],sizeof(struct book),1,fp1)!=0;i++)
                {
                    if(bk[i].book_name == lendbook)
                    {
                        bk[i].book_lastnum += 1; //还回书籍
                    }
                    fwrite(&bk[i],sizeof(struct book),1,fp2);
                }
                fclose(fp1);
                fclose(fp2);

                fp1=fopen("book.txt","w");
                fp2=fopen("book1.txt","r");
                for(i=0;fread(&bk[i],sizeof(struct book),1,fp2)!=0;i++)
                {
                    fwrite(&bk[i],sizeof(struct book),1,fp1); 
                }
                fclose(fp1);
                fclose(fp2);

                fopen("book1.txt","w");
                fclose(fp2);

                printf("还书完毕,按任意键返回...\n");
                getch();
                flag=1;
                break;
            }
        }
        if (flag == 0)
        {
            printf("您未借此书...\n");
            fclose(fp);
        }
        printf("若还想还书可以按y;其他任意键退出\n");  
    } while (getch() == 'y');
}

void ShowBook()
{
    int i,stunum;
    printf("请输入学号:");
    scanf("%d",&stunum);
    FILE* fp = fopen("record.txt","r");
    for(i=0;fread(&recordbook[i],sizeof(struct recordofbook),1,fp)!=0;i++)
    {
        if (recordbook[i].book_user == stunum)
        {
            printf("%s\n",recordbook[i].book_name);
        }
    }
    fclose(fp);
}

/*********************用户相关***************************/

void DeleteUser()
{
    FILE *fp1,*fp2;
    int i;
    int stunum;
    do 
    {
        Hello();
        DisplayStu();
        printf("学号:");
        scanf("%d",&stunum);

        fp1 = fopen("student.txt","r");
        fp2 = fopen("student1.txt","w");
        for(i=0;fread(&stu[i],sizeof(struct student),1,fp1)!=0;i++)
        {
            if(stunum != stu[i].stu_num)
            {
                fwrite(&stu[i],sizeof(struct student),1,fp2);
            }
        }
        fclose(fp1);
        fclose(fp2);

        fp1 = fopen("student.txt","w");
        fp2 = fopen("student1.txt","r");
        for(i=0;fread(&stu[i],sizeof(struct student),1,fp2)!=0;i++)
        {
            fwrite(&stu[i],sizeof(struct student),1,fp1);
        }
        fclose(fp1);
        fclose(fp2);

        fp2 = fopen("student1.txt","w");
        fclose(fp2);

        DisplayStu();
        printf("删除成功,继续删除请输入'y';其他键退出...\n");
    } while (getch() == 'y');
}

int CheckStu( int stunum)
{
    FILE *fp;
    int i;

    fp=fopen("student.txt","r");
    for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0;i++)
    {
        if(stu[i].stu_num == stunum)
        {
            fclose(fp);
            return 1;
        }
    }
    fclose(fp);
    return 0;
}

void ModifyUser(int AorU)
{
    FILE *fp1,*fp2;
    int i,j,flag;
    int stunum;
    do 
    {
        Hello();
        if (AorU == 0)
        {
            DisplayStu();
        }
        printf("学号:");
        scanf("%d",&stunum);
        if (CheckStu(stunum) == 0)
        {
            printf("您所输入的学生不存在...");
            break;
        }

        flag = 0;
        fp1 = fopen("student.txt","r");
        fp2 = fopen("student1.txt","w");
        for(i=0;fread(&stu[i],sizeof(struct student),1,fp1)!=0;i++)
        {
            if(stu[i].stu_num == stunum)
            {
                if (AorU == 1)//用户
                {
                    printf("密码:");
                    char temppassword[20];
                    fflush(stdin);
                    gets(temppassword);
                    if (strcmp(temppassword,stu[i].password) != 0)
                    {
                        printf("\n密码错误,不可修改...\n");
                        flag = 1;
                        break;
                    }
                }

                printf("以下是该学生信息:\n");
                printf("学号:");
                printf("%d\n",stu[i].stu_num); 
                printf("密码:");
                printf("%s\n",stu[i].password);
                printf("姓名:");
                printf("%s\n",stu[i].stu_name);
                printf("性别:");
                printf("%c\n",stu[i].stu_sex);
                printf("班级:");
                printf("%d\n",stu[i].stu_class);
                printf("1: 修改学号:\n");
                printf("2: 修改密码:\n");
                printf("3: 修改姓名:\n");
                printf("4: 修改性别:\n");
                printf("5: 修改班级:\n");
                printf("请输入1~5:\n");

                switch(getch())
                {
                case '1':
                    {
                        printf("新学号:");
                        scanf("%d",&stu[i].stu_num);
                        fwrite(&stu[i],sizeof(struct student),1,fp2);
                        break;
                    }
                case '2':
                    {
                        printf("新密码:");
                        scanf("%s",stu[i].password);
                        fwrite(&stu[i],sizeof(struct student),1,fp2);
                        break;
                    }
                case '3':
                    {
                        printf("新姓名:");
                        scanf("%s",stu[i].stu_name);
                        fwrite(&stu[i],sizeof(struct student),1,fp2);
                        break;
                    }
                case '4':
                    {
                        printf("新性别:");
                        scanf("%c",&stu[i].stu_sex);
                        fwrite(&stu[i],sizeof(struct student),1,fp2);
                        break;
                    }
                case '5':
                    {
                        printf("新班级:");
                        scanf("%d",&stu[i].stu_class);
                        fwrite(&stu[i],sizeof(struct student),1,fp2);
                        break;
                    }
                default:
                    {
                        printf("没有这样的操作!\n");
                        break;
                    }
                }
                break;
            }
            fwrite(&stu[i],sizeof(struct student),1,fp2);
        }
        if (flag == 0)
        {
            fclose(fp1);
            fclose(fp2);

            fp1=fopen("student.txt","w");
            fp2=fopen("student1.txt","r");
            for(i=0;fread(&stu[i],sizeof(struct student),1,fp2)!=0;i++)
            {
                fwrite(&stu[i],sizeof(struct student),1,fp1);
            }
            fclose(fp1);
            fp2=fopen("student1.txt","w");
            fclose(fp2);

            if (AorU == 0)
            {
                DisplayStu();
            }
        }

        printf("继续修改请输入'y';其他键退出...\n");
    } while (getch() == 'y');
}

void Enroll()
{
    Hello();
    FILE *fp;
    fp = fopen("student.txt","a+");

    printf("学号:");
    scanf("%d",&stu[0].stu_num);
    printf("密码:");
    int i=0;
    while(stu[0].password[i]=getch())
    {
        if(stu[0].password[i] == 13 || stu[0].password[i] == 10)
        {
            break;
        }
        if(stu[0].password[i]!='\b')
        {
            printf("*");
            i++;
        }
        else
        {
            if (i == 0)
            {
                continue;
            }
            printf("\b \b");
            i--;
        }
    }
    stu[0].password[i]='\0';

    fflush(stdin);
    printf("\n性别(m/w):");
    scanf("%c",&stu[0].stu_sex);
    printf("名字:");
    scanf("%s",stu[0].stu_name);
    printf("班级:");
    scanf("%d",&stu[0].stu_class);

    fwrite(&stu[0],sizeof(struct student),1,fp);
    fclose(fp);
    printf("注册成功,请按任意键进行其他操作...\n");
    getch();
}

void ManageStu()
{
    Hello();
    DisplayStu();
    printf("1:增加用户 \n");
    printf("2:删除用户 \n");
    printf("3:修改用户 \n");
    printf("0:退出 \n");
    printf("请输入0~3\n");

    switch(getch())
    {
    case '1':
        {
            Enroll();
            break;
        }
    case '2':
        {
            DeleteUser();
            break;
        }
    case '3':
        {
            ModifyUser(0);
            break;
        }
    default:
        return;
    }
}

int Password(int AorU, int stunum)
{
    char p[20];
    int i=0;
    printf("请输入密码:");
    while(p[i]=getch())
    {
        if(p[i] == 13 || p[i] == 10)//回车或换行
        {
            break;
        }
        if(p[i]!='\b')
        {
            printf("*");
            i++;
        }
        else
        {
            if (i == 0)
            {
                continue;
            }
            printf("\b \b");
            i--;
        }
    }
    p[i]='\0';

    if ( AorU == 0)
    {
        if(strcmp(p,password_admin) != 0)
        {
            printf("\n密码有误,请重新输入...\n");
            return 0;//密码有误
        }
        return 1;
    }

    FILE* fp;
    fp =fopen("student.txt","r");
    for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0;i++)
    {
        if(stu[i].stu_num == stunum)
        {
            if(strcmp(p,stu[i].password) == 0)
            {
                fclose(fp);
                return 1;
            }
            fclose(fp);
            printf("\n密码错误\n");
            return 0;
        }
    }
    return 0;
} 

void MyInformation()//学生信息管理。。。信息查看,修改
{
    FILE *fp;
    do 
    {
        Hello();
        printf("请选择:\n");
        printf("查看:0;修改:1\n");
        switch(getch())
        {
        case '0':
            {
                int stunum;
                int i,flag;
                printf("请输入你的学号:");
                scanf("%d",&stunum);
                flag=CheckStu(stunum);
                if (flag == 0)
                {
                    printf("您未注册...\n");
                    return;
                }

                fp=fopen("student.txt","r");
                for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0;i++)
                {
                    if(stu[i].stu_num == stunum)
                    {
                        printf("");
                        do 
                        {
                            printf("密码:");
                            char tempnum[20];
                            scanf("%s",tempnum);
                            if (strcmp(tempnum,stu[i].password) == 0)
                            {
                                printf("以下是您的信息:\n");
                                printf("学号:");
                                printf("%d\n",stu[i].stu_num); 
                                printf("密码:");
                                printf("%s\n",stu[i].password);
                                printf("姓名:");
                                printf("%s\n",stu[i].stu_name);
                                printf("性别:");
                                printf("%c\n",stu[i].stu_sex);
                                printf("班级:");
                                printf("%d\n",stu[i].stu_class);
                                break;
                            }
                            printf("密码错误,重输请按y...\n");
                        } while (getch() == 'y');
                    }
                }
                fclose(fp);
                break;
            }
        case '1':
            {
                ModifyUser(1);
                printf("修改完成...\n");
                break;
            }
        default:
            printf("没有这样的操作...\n");
        }
        printf("若还想查看或修改,可以按y;其他任意键退出\n");  
    }while (getch() == 'y');
}

void Users()
{
    Hello();
    printf("请选择:\n");
    printf("已注册:1;未注册:0\n");

    char ch;
    do 
    {
        printf("");
        ch = getch();
    } 
    while (ch != '0' && ch != '1');

    if (ch == '1')
    {
        Hello();
        int stunum,flag;
        printf("请输入你的学号:");
        scanf("%d",&stunum);
        flag = CheckStu(stunum);
        if (flag == 0)
        {
            printf("请先注册...\n");
            return;
        }
        if (Password(1,stunum) == 0)
        {
            return;
        }
    }
    else
    {
        Enroll();
    }

    do 
    {
        Hello();
        printf("1:查找图书 \n");
        printf("2:借阅图书 \n");
        printf("3:归还图书 \n");
        printf("4:借书记录 \n");
        printf("5:信息管理 \n");
        printf("0:退出 \n");
        printf("请输入0~5:\n");
        fflush(stdin);
        switch(getch())
        {
        case '1':
            {
                FindBook();
                break;
            }
        case '2':
            {
                BorrowBook();
                break;
            }
        case '3':
            {
                RerurnBook();
                break;
            }
        case '4':
            {
                ShowBook();
                break;
            }
        case '5':
            {
                MyInformation();
                break;
            }
        case '0':
            {
                return;
            }
        default:printf("请输入0~5\n");
        }
        printf("\n有其他操作请按y\n");
        fflush(stdin);
    } while (getch() == 'y');
    printf("");
}

void Admin()
{
    do 
    {
        Hello();
        if (Password(0,0) == 1)
        {
            break;
        }
        printf("\n按任意键继续...");
    } while (getch());

    do 
    {
        Hello();
        printf("1:增加图书 \n");
        printf("2:删除图书 \n");
        printf("3:修改图书 \n");
        printf("4:图书统计 \n");
        printf("5:学生管理 \n");
        printf("0:退出 \n");
        printf("请输入0~5:\n");
        switch(getch())
        {
        case '1':
            {
                AddBook();
                break;
            }
        case '2':
            {
                DeleteBook();
                break;
            }
        case '3':
            {
                ModifyBook();
                break;
            }
        case '4':
            {
                CountBook();
                break;
            }
        case '5':
            {
                ManageStu();
                break;
            }
        case '0':
            {
                return;
            }
        default:printf("请输入0~5:\n");
        }
        printf("\n有其他操作请按y\n");
    } while (getch() == 'y');
    printf("谢谢使用...\n");
}

void main()
{
    Hello();
    printf("请选择:\n");
    printf("Admin:0;User:1:\n");
    char ch;
    do 
    {
        printf("");
        ch = getch();
    } while (ch != '0' && ch != '1');

    if (ch == '1')
    {
        Users();
    }
    else
    {
        Admin();
    }
}
版权声明:本文为博主原创文章,欢迎大家指正。

相关文章推荐

图书管理系统LibSystemV1.0

  • 2010年07月18日 06:21
  • 23KB
  • 下载

图书管理系统之登录界面实现

实现效果图如下,通过输入的用户名链接到数据库并判断该用户是否存在,存在与否都会给出提示,若存在点击登录时判断密码是否正确,若正确则登录成功,否则登录失败。 其中用户名输入框用到的监听较多,有Acti...

c#做的图书管理系统1.0

  • 2008年10月09日 12:32
  • 378KB
  • 下载

习题5-8 图书管理系统(Borrowers, UVa230)

习题5-8 图书管理系统(Borrowers, UVa230) Before they are returned to the shelves, the returned books are sort...
  • chcnsn
  • chcnsn
  • 2017年07月02日 14:00
  • 64

宛枫书社图书管理系统 V1.0

  • 2006年02月23日 09:05
  • 526KB
  • 下载

书社图书管理系统 V1.0

  • 2004年07月09日 00:00
  • 536KB
  • 下载

简单的图书管理系统php实现

数据库的结构: create table book( id int not null auto_increment primary key, bookname varchar(50) not nul...

图书管理系统V1.0

  • 2006年03月16日 00:00
  • 7.7MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:图书管理系统1.0by P_LarT
举报原因:
原因补充:

(最多只允许输入30个字)