⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 programe.c

📁 这是我2005年寒假开学时的C语言程序实践项目,其中包括学生管理系统,员工管理系统,通讯录,图书馆管理系统,机场售票系统五个C程序合成在一起.
💻 C
📖 第 1 页 / 共 4 页
字号:
        }
        else
        {
            printf("Your input is error!");
            printf("确定还书?——————y/n::\n");
            break;
        }

    }
    return;
}

void huanshu1(book *p,reader *k)
{
    book *boo2,*b2;
    int i,n,mark=0,d;
    reader *read3;
    read3=k;
    b2=p;
    boo2=b2->next;
    if(boo2==NULL)
    {
        printf("这是空文件!...");
        return;
    }
    printf("请输入书号:\n");
    scanf("%d",&i);
    while(boo2)
    {
        if(boo2->num==i)
        {
            downdate1(boo2,read3);
            mark=1;
            return;
        }
        else
        {
            p=p->next;
            boo2=boo2->next;
        }
    }
    if(mark==0) printf("对不起 请确定所输入的号是否存在!");
}

/*删除图书信息(按书号)*/
shanchu1(book *p)
{
    book* boo,*t;
    int i,mark=0;
    char ch;
    t=p;
    boo=t->next;
    if(boo==NULL)
    {
        printf("The List is empty!...");
        return;
    }
    printf("Please enter the num of the student:\n");
    scanf("%d",&i);
    while(boo)
    {
        if(boo->num==i)
        {
            printf("Really delet it?(Y or N):\n");
            ch=getch();
            if(ch=='Y'||ch=='y')
            {
                printf("Wait......\n");
                t->next=boo->next;
                free(boo);
                mark=1;
                printf("Success delet the book's information!");
            }
            else return;
        }
        else
        {
            t=t->next;
            boo=boo->next;
        }
    }
    if(mark==0) printf("The book of this num is not exit!");
}

shanchu2(reader *p)
{
    reader *read,*t;
    int i,mark=0;
    char ch;
    t=p;
    read=t->next;
    if(read==NULL)
    {
        printf("The List is empty!...");
        return;
    }
    printf("请输入学号:\n");
    scanf("%d",&i);
    while(read)
    {
        if(read->num==i)
        {
            printf("Really delet it?(Y or N):\n");
            ch=getch();
            if(ch=='Y'||ch=='y')
            {
                printf("Wait......\n");
                t->next=read->next;
                free(read);
                mark=1;
                printf("Success delet the book's information!");
            }
            else return;
        }
        else
        {
            t=t->next;
            read=read->next;
        }
    }
    if(mark==0) printf("The reader of this num is not exit!");
}

/*保存图书的整个链表信息到文件中*/
void saveInfo1(book *p)
{
    book *boo;
    FILE *fp;
    boo=p->next;
    if(boo==NULL)
    {
        printf("The List is empty!");
        return;
    }
    fp=fopen("cheng.txt","wt");
    if(fp==NULL)
    {
        printf("The file open error!");
        return;
    }
    if(boo==NULL)
    {
        printf("The list is empty!");
        fputc('#',fp);
        fclose(fp);
        return;
    }
    printf("Wait......\n");
    while(boo)
    {
        fputc('*',fp);
        fprintf(fp,"%d\n%s\n%f\n%d\n%c\n",boo->num,boo->name,boo->price,boo->CD,boo->not);
        boo=boo->next;
    }
    fputc('#',fp);
    fclose(fp);
    printf("Success to save the file!\n");
}

saveInfo2(reader *p)    /*保存读者的整个链表信息到文件中*/
{
    reader *read;
    FILE *fp;
    read=p->next;
    if(read==NULL)
    {
        printf("The List is empty!");
        return;
    }
    fp=fopen("hou.txt","wt");
    if(fp==NULL)
    {
        printf("The file open error!");
        return;
    }
    if(read==NULL)
    {
        printf("The list is empty!");
        fputc('#',fp);
        fclose(fp);
        return;
    }
    printf("Wait......\n");
    while(read)
    {
        fputc('*',fp);
        fprintf(fp,"%s\n%d\n%s\n%d\n%d\n%d\n%d\n",read->name,read->num,read->sex,read->lend,read->wrong,read->gread,read->classes);
        read=read->next;
    }
    fputc('#',fp);
    fclose(fp);
    printf("Success to save the file!\n");
}

/*释放整个链表*/
void freeinfo1(book *p)
{
    book *boo,*t;
    boo=p->next;
    while(boo)
    {
        t=boo;
        boo=boo->next;
        free(t);
    }
    free(p);
}

/*释放整个链表*/
void freeinfo2(reader *p)
{
    reader *read,*t;
    read=p->next;
    while(read)
    {
        t=read;
        read=read->next;
        free(t);
    }
    free(p);
}

/*函数从文件中调数据上来*/
void duqu1(book *boo)
{
    FILE *fp;
    book *p,*q;
    char ch;
    int i=0;
    q=boo;
    fp=fopen("cheng.txt","r");
    if(fp==NULL)
    {
        printf("File error!\npress any key to exit!...");
        getch();
        exit(1);
    }
    ch=fgetc(fp);
    while(ch!='#')
    {
        p=(book *)malloc(sizeof(book));
        fscanf( fp,"%d\n%s\n%f\n%d\n%c\n",&p->num,p->name,&p->price,&p->CD,&p->not);
        q->next=p;
        i++;
        q=p;
        p++;
        ch=fgetc(fp);
    }
    if(i==0)
    {
        printf("The file is empty!\npress any key to continue...");
        getch();
        return;
    }
    else
    {
        q->next=NULL;
        printf("There is %d book' information!\npress any key...",i);
        getch();
        return;
    }
}

void duqu2(reader *read)
{
    FILE *fp;
    reader *r,*y;
    char ch;
    int i=0;
    y=read;
    fp=fopen("hou.txt","r");
    if(fp==NULL)
    {
        printf("File error!\npress any key to exit!...");
        getch();
        exit(1);
    }
    ch=fgetc(fp);
    while(ch!='#')
    {
        r=(reader *)malloc(sizeof(reader)); fscanf( fp,"%s\n%d\n%s\n%d\n%d\n%d\n%d\n",r->name,&r->num,r->sex,&r->lend,&r->wrong,&r->gread,&r->classes);
        y->next=r;
        i++;
        y=r;
        r++;
        ch=fgetc(fp);
    }
    if(i==0)
    {
        printf("The file is empty!\npress any key to continue...");
      getch();
      return;
    }
    else
    {
        y->next=NULL;
        printf("There is %d readers' information!\npress any key...",i);
        getch();
        return;
    }
}

/*图书的基本情况显示出来*/
void jutixinxi1(book *p)
{
    book *boo;
    boo=p->next;
    if(boo==NULL)
    {
        printf("The List is empty!...");
        return;
    }
    while(boo)
    {
        printf("**********\n");
        textcolor(7);
        printf("      图书号---:%d\n     \n\r书名--:%s\n      \n\r定价---:%f\n       \n\rCD数:%d\n      ",boo->num,boo->name,boo->price,boo->CD);
        if(boo->not=='y') cprintf("             \n\r在库中可借");
        if(boo->not=='n') cprintf("             \n\r已经借出");
        printf("**********\n");
        boo=boo->next;
        getch();
        clrscr();
    }
}

/*读者的基本情况显示出来*/
void jutixinxi2(reader *p)
{
    reader *read;
    read=p->next;
    if(read==NULL)
    {
        textcolor(6);
        cprintf("The List is empty!...");
        return;
    }
    while(read)
    {
        printf("**********\n");
        textcolor(12);
        cprintf("  姓名------:%s\n \r\n 借书号:%d\n\r\n     性别------:%s\n\r\n  已借图书------:%d\n\r\n    违纪次数--------:%d\n\r\n         %d  级%d  班\n\r\n  ",read->name,read->num,read->sex,read->lend,read->wrong,read->classes,read->gread);
        printf("**********\n");
        read=read->next;
        getch();
        clrscr();
    }
}

Houxiaocheng()
{
    int x;
    int a1,a2;
    char e;
    char ch,mark;
    book *p;
    reader *u;
    x=sin(0.0);
    p=(book *)malloc(sizeof(book));
    p->next=NULL;
    u=(reader *)malloc(sizeof(reader));
    u->next=NULL;
    textbackground(9);
    clrscr();
    yemian();
    duqu1(p);
    duqu2(u);
    ch=access();
    while (ch=access())
    {
        switch(ch)
        {
            case '0':
                textcolor(4);
                cprintf("输入错误!Press any key contiune...");
                getch();
                break;
            case '1':
                duqu2(u);
                jutixinxi2(u);
                textcolor(0);
                cprintf("\nPress any key to continue!...");
                getch();
                break;
            case '2':
                jieshu1(p,u);
                textcolor(3);
                cprintf("\nPress any key to continue!...");
                getch();
                break;
            case '3':
                huanshu1(p,u);
                textcolor(5);
                printf("\nPress any key to continue!...");
                getch();
                break;
            case '4':
            {
                clrscr();
                caidan();
                scanf("%d",&e);
                switch(e)
                {
                    case 1:
                        printf("欢迎进入读者信息查询栏");
                        textcolor(14);
                        cprintf("\n\n\r         1--增加读者\n\n \r     2--删除读者信息\n\n \r     3--显示读者信息\n\n\r\n");
                        scanf("%d",&a1);
                        switch (a1)
                        {
                            case 1:
                                zengjia2(u);
                                saveInfo2(u);
                                getch();
                                break;
                            case 2:
                                shanchu2(u);
                                saveInfo2(u);
                                getch();
                                break;
                            case 3:
                                jutixinxi2(u);
                                getch();
                                clrscr();
                                break;
                                default :  textcolor(8);cprintf("输入有误  请重新输入"); break;
                        }
                    break;
                    case 2:
                        cprintf("欢迎进入图书信息栏 ");
                        cprintf("\n\n\r\n\n\r1----增加图书\n\n\r\n\n\r2----删除图书\n\n\r\n\n\r3----显示所有图书信息\n\n\r\n");
                        scanf("%d",&a2);
                        clrscr();
                        switch (a2)
                        {
                            case 1:
                                zengjia1(p);
                                saveInfo1(p);
                                clrscr();
                                getch();
                                break;
                            case 2:
                                shanchu1(p);
                                saveInfo1(p);
                                clrscr();
                                getch();
                                break;
                            case 3:
                                jutixinxi1(p);
                                getch();
                                clrscr();
                                break;
                            default:printf("输入有误  请重新输入");
                        }
                    break;
                }
                printf("\nPress any key to continue!...");
                getch();
                break;
            }
            case '5':
                duqu1(p);
                clrscr();
                duqu2(u);
                getch();
                break;
            case '6':
                saveInfo1(p);
                printf("test1");
                saveInfo2(u);
                printf("test2");
                freeinfo1(p);
                freeinfo2(u);
                main();
        }
    }
    getch();
}


main()
{
    char ch;
    textcolor(15);
    textbackground(0);
    clrscr();
    printf("欢迎进入我们的程序!\n");
    printf("您想选择谁的程序?(请输入序号)\n");
    printf("1.段磊(组长)\n2.陈新峰\n3.段伟\n4.侯晓成\n5.侯树超\n0.退出\n");
    while ((ch=getch())!='0')
    {
        clrscr();
        switch(ch)
        {
            case '1':
                printf("您选择了段磊的程序.\n");
                Duanlei();
                break;
            case '2':
                printf("您选择了陈新峰的程序.\n");
                Chenxinfeng();
                break;
            case '3':
                printf("您选择了段伟的程序.\n");
                Duanwei();
                break;
            case '4':
                printf("您选择了侯晓成的程序.\n");
                Houxiaocheng();
                break;
            case '5':
                printf("您选择了侯树超的程序.\n");
                Houshuchao();
                break;
            default: printf("您的输入错误!\n");
        }
    }
    printf("\n\n为了我们更好地发展,请注册您的程序!");
    exit();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -