c语言 图书管理系统 大佬们能不能看一下~

图片说明
大作业,大一刚学c语言,好难啊。。

#include <stdio.h>
#include<string.h>
#include <stdlib.h>
int user_count=0;
int book_count=0;
int borrower_count=0;

struct account{
    char ID[20];
    char password[20];
}user[100];

struct detailbook{
    char book_name[20];
    char book_code[20];
    char book_sort[20];
    char book_number[20];
}book[1000];

struct detailborrow{
    char brw_name[20];
    char brw_id[20];
    char brw_level[3];
    char brw_number[3];
}borrower[100];

void save_user(void);
void add_user(void);
void user_menu(void);#include <stdio.h>
#include<string.h>
#include <stdlib.h>
int user_count=0;
int book_count=0;
int borrower_count=0;

struct account{
    char ID[20];
    char password[20];
}user[100];

struct detailbook{
    char book_name[20];
    char book_code[20];
    char book_sort[20];
    char book_number[20];
}book[1000];

struct detailborrow{
    char brw_name[20];
    char brw_id[20];
    char brw_level[3];
    char brw_number[3];
}borrower[100];

void load_user(void);
void load_book(void);
void save_book(void);
void backlogin(void);
void backadmin(void);
void bookinput(void);
void brwinput(void);
void load_borrower(void);
void save_borrower(void);
void frontlogin(void);
void frontadmin(void);
void lend(void);
void save_history(void);


void main(){
    load_user();
    load_book();
    load_borrower();
    user_menu();
}


void user_menu(void)
{
    int choose;
    system("cls");
    printf("\n\n\t\t*****************************************");
    printf("\n\t\t*\t\t\t\t\t*");
    printf("\n\t\t*\t\t\t\t\t*");
    printf("\n\t\t*\t 欢迎来到图书管理系统\t*");
    printf("\n\t\t*\t\t\t\t\t*");
    printf("\n\t\t*\t      登录后台请按1\t\t*");
    printf("\n\t\t*\t\t\t\t\t*");
    printf("\n\t\t*\t      登录前台请按2\t\t*");
    printf("\n\t\t*\t\t\t\t\t*");
    printf("\n\t\t*\t      注册账号请按3\t\t*");
    printf("\n\t\t*\t\t\t\t\t*");
    printf("\n\t\t*\t      退出系统请按0\t\t*");
    printf("\n\t\t*\t\t\t\t\t*");
    printf("\n\t\t*****************************************");
    printf("\n\t\t\t\t");
    printf("\n\t\t\t       请输入选项:\n\t\t\t\t   ");
    scanf("%d",&choose);
    switch(choose){
        case 1:
            backlogin();
        case 2:
            frontlogin();
        case 3:
            add_user(); break;
        case 0:
            return;
        default:
            printf("\n\t\t\t   输入错误,请重新输入\n\n\t\t\t    ");
            system("PAUSE");
            system("cls");
            user_menu();
    }
}

void add_user(void)//注册账号
{
    FILE *fp;
    int i;
    char str[101];
    system("cls");
    printf("\n");
    printf("\t\t\t请输入账号:\n\n\t\t\t   ");
    scanf("%s",str);
    if(strlen(str)>16)
    {
        printf("\t\t账号长度大于16位,请重新输入\n");
        system("PAUSE");
        system("cls");
        printf("\n");
        add_user();
        return;
    }
    for(i=0;i<user_count;i++)
        if(strcmp(user[i].ID,str)==0)
        {
            printf("\t\t该账号已被注册,请重新注册\n\n\t\t\t   ");
            system("PAUSE");//按任意键继续
            add_user();
        }
    strcpy(user[i].ID,str);
    printf("\t\t\t请输入密码:\n\n\t\t\t   ");
    scanf("%s",str);
    while(strlen(str)>16)
    {
        system("cls");
        printf("\n");
        printf("\t\t密码长度大于16位,请重新输入\n\n");
        printf("\t\t\t请输入密码:\n\n\t\t\t   ");
        scanf("%s",str);
    }
    strcpy(user[i].password,str);
    save_user();//将账号写入磁盘
    printf("\t\t\t账号申请成功\n\n\t\t\t");
    user_count++;
    system("PAUSE");
    user_menu();
}



void save_user(void)//将账号写入磁盘
{
    int i;
    FILE *fp;
    fp=fopen("账号.txt","w");
    for(i=0;i<=user_count;i++)
    {
        fprintf(fp,"%s\n",user[i].ID);
        fprintf(fp,"%s\n",user[i].password);
    }
    fclose(fp);
}


void load_user(void)//将账号读入内存
{
    FILE *fp;
    fp=fopen("账号.txt","r");
    while(fscanf(fp,"%s",user[user_count].ID)!=EOF)
    {
        fscanf(fp,"%s",user[user_count].password);
        user_count++;
    }
    fclose(fp);
}


void backlogin(void)//后台人员登录
{
    int i,flag=0;
    char str[20];
    system("cls");
    printf("\n");
    printf("\t\t\t请输入账号:\n\n\t\t\t   ");
    scanf("%s",str);
    for(i=0;i<user_count;i++)
        if(strcmp(user[i].ID,str)==0)
        {
            flag=1;
            break;
        }
    if(flag==0)
    {
        printf("\t\t该账号不存在,请重新登录\n\n\t\t\t");
        system("PAUSE");
        system("cls");
        printf("\n");
        backlogin();
        return;
    }
    printf("\t\t\t请输入密码:\n\n\t\t\t   ");
    scanf("%s",str);
    while(strcmp(user[i].password,str)!=0)
    {
        system("cls");
        printf("\n");
        printf("\t\t\t密码错误,请重新输入\n\n\t\t\t\t");
        scanf("%s",str);
    }
    printf("\t\t\t登录成功\n\n\t\t\t");
    backadmin();
}







void backadmin(void)//后台人员操作选项
{
    int choose;
    while(1){
        system("cls");
        printf("\n\n\t\t*****************************************");
        printf("\n\t\t*\t\t\t\t\t*");
        printf("\n\t\t*\t      书籍录入请输入1\t\t*");
        printf("\n\t\t*\t      书籍增加请输入2\t\t*");
        printf("\n\t\t*\t      借阅人信息录入请输入3\t\t*");
        printf("\n\t\t*\t      借阅人信息增加请输入4\t\t*");
        printf("\n\t\t*\t      返回到上一层请按0\t\t*");
        printf("\n\t\t*\t\t\t\t\t*");
        printf("\n\t\t*****************************************");
        printf("\n\t\t\t       请输入选项:\n\t\t\t\t   ");
        scanf("%d",&choose);
        switch(choose){
            case 0:
                user_menu();return;
            case 1:
                bookinput();

            case 3:
                brwinput();
        }
    }
}


void bookinput(void)//图书录入功能
{
    int i;
    system("cls");
    printf("\n\t\t\t   请输入要录入的图书数\n\t\t\t\t");
    scanf("%d",&book_count);
    for(i=0;i<book_count;i++){
         system("cls");
         printf("\n\t\t\t   这是第%d本书的录入\n\t\t\t\t",i+1);
         printf("\n\t\t\t   请输入书名\n\t\t\t\t");
         scanf("%s",book[i].book_name);
         printf("\n\t\t\t   请输入书的序号\n\t\t\t\t");
         scanf("%s",book[i].book_code);
         printf("\n\t\t\t   请输入书的类别\n\t\t\t\t");
         scanf("%s",book[i].book_sort);
         printf("\n\t\t\t   请输入书的数量\n\t\t\t\t");
         scanf("%s",book[i].book_number);
    }
    save_book();
    printf("按任意键结束");
    system("PAUSE");
}

void load_book(void)//将图书读入内存
{
    FILE *fp;
    fp=fopen("图书.txt","r");
    while(fscanf(fp,"%s",book[book_count].book_name)!=EOF)
    {
        fscanf(fp,"%s",book[book_count].book_name);
        fscanf(fp,"%s",book[book_count].book_code);
        fscanf(fp,"%s",book[book_count].book_sort);
        fscanf(fp,"%s",book[book_count].book_number);
        book_count++;
    }
    fclose(fp);
}


void save_book(void)//将图书写入磁盘
{
    int i;
    FILE *fp;
    fp=fopen("图书.txt","w");
    for(i=0;i<=book_count;i++)
    {
        fprintf(fp,"%s\n",book[i].book_name);
        fprintf(fp,"%s\n",book[i].book_code);
        fprintf(fp,"%s\n",book[i].book_sort);
        fprintf(fp,"%s\n",book[i].book_number);
    }
    fclose(fp);
}



void brwinput(void)//录入借书者
{
    int i;
    system("cls");
    printf("\n\t\t\t   请输入要录入的借书者数\n\t\t\t\t");
    scanf("%d",&borrower_count);
    for(i=0;i<borrower_count;i++){
         system("cls");
         printf("\n\t\t\t   这是第%d个借书者的录入\n\t\t\t\t",i+1);
         printf("\n\t\t\t   请输入借书者姓名\n\t\t\t\t");
         scanf("%s",borrower[i].brw_name);
         printf("\n\t\t\t   请输入借书者id\n\t\t\t\t");
         scanf("%s",borrower[i].brw_id);
         printf("\n\t\t\t   请输入借书者等级\n\t\t\t\t");
         scanf("%s",borrower[i].brw_level);
         printf("\n\t\t\t   请输入借书者已借数量\n\t\t\t\t");
         scanf("%s",borrower[i].brw_number);
    }
    save_borrower();
    printf("按任意键结束");
    system("PAUSE");
}



void load_borrower(void)//将借书者读入内存
{
    FILE *fp;
    fp=fopen("借书者.txt","r");
    while(fscanf(fp,"%s",borrower[borrower_count].brw_name)!=EOF)
    {
        fscanf(fp,"%s",borrower[borrower_count].brw_name);
        fscanf(fp,"%s",borrower[borrower_count].brw_id);
        fscanf(fp,"%s",borrower[borrower_count].brw_level);
        fscanf(fp,"%s",borrower[borrower_count].brw_number);
        borrower_count++;
    }
    fclose(fp);
}


void save_borrower(void)//将借书者写入磁盘
{
    int i;
    FILE *fp;
    fp=fopen("借书者.txt","w");
    for(i=0;i<=borrower_count;i++)
    {
        fprintf(fp,"%s\n",borrower[i].brw_name);
        fprintf(fp,"%s\n",borrower[i].brw_id);
        fprintf(fp,"%s\n",borrower[i].brw_level);
        fprintf(fp,"%s\n",borrower[i].brw_number);
    }
    fclose(fp);
}


void frontlogin(void)//前台人员登录
{
    int i,flag=0;
    char str[20];
    system("cls");
    printf("\n");
    printf("\t\t\t请输入账号:\n\n\t\t\t   ");
    scanf("%s",str);
    for(i=0;i<user_count;i++)
        if(strcmp(user[i].ID,str)==0)
        {
            flag=1;
            break;
        }
    if(flag==0)
    {
        printf("\t\t该账号不存在,请重新登录\n\n\t\t\t");
        system("PAUSE");
        system("cls");
        printf("\n");
        frontlogin();
        return;
    }
    printf("\t\t\t请输入密码:\n\n\t\t\t   ");
    scanf("%s",str);
    while(strcmp(user[i].password,str)!=0)
    {
        system("cls");
        printf("\n");
        printf("\t\t\t密码错误,请重新输入\n\n\t\t\t\t");
        scanf("%s",str);
    }
    printf("\t\t\t登录成功\n\n\t\t\t");
    frontadmin();
}


void frontadmin(void)//前台人员操作选项
{
    int choose;
    while(1){
        system("cls");
        printf("\n\n\t\t*****************************************");
        printf("\n\t\t*\t\t\t\t\t*");
        printf("\n\t\t*\t      日常记录被借书籍请输入1\t\t*");
        printf("\n\t\t*\t      日常记录被还书籍2\t\t*");
        printf("\n\t\t*\t      查询到期未还的书输入3\t\t*");

        printf("\n\t\t*\t\t\t\t\t*");
        printf("\n\t\t*****************************************");
        printf("\n\t\t\t       请输入选项:\n\t\t\t\t   ");
        scanf("%d",&choose);
        switch(choose){
            case 1:
                lend();

            case 3:
                ;
        }
    }
}

借鉴了https://blog.csdn.net/HeZhiYing_/article/details/80627622

写到了前台管理员身份,感觉有点写不来了,暴风哭泣。有大佬能拯救捞一下我吗,非常非常感谢。

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐