| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1143 人关注过本帖
标题:学生管理系统输入多组数据后,最后一组重复输出是怎么回事
只看楼主 加入收藏
小小白22
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2018-6-16
结帖率:100%
收藏
 问题点数:0 回复次数:0 
学生管理系统输入多组数据后,最后一组重复输出是怎么回事
#include<windows.h>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>


#define N 100
void add();
void Find();
void shanchu();
void change();
void tongji();
void read();
void input();//oˉêyéùÃ÷
void menu1();
void menu2();

struct student
{
    char no[10];
    char name[20];
    char sex[10];
    char age[5];
    char NativePlace[20];
    char major[25];
    char grade[5];
}stu[N];

int main()//用户登录界面
{
    int part1,part2,part3,part4;
    char name1[10]="0011",password1[10]="0011";
    char name2[10]="9911",password2[10]="9911";
    char person[10],c[10];
    printf("**************欢迎进入学籍管理管理系统***************\n");
    printf("请输入您的帐号密码\n");
    printf("帐号:");
    scanf("%s",person);
    printf("密码:");
    scanf("%s",c);
    part1=strcmp(person,name1);
    part2=strcmp(c,password1);
    part3=strcmp(person,name2);
    part4=strcmp(c,password2);
    if(part1==0&&part2==0)
    {
        printf("登录成功!\n");
        menu1();
    }
    else if(part3==0&&part4==0)
    {
        printf("登录成功!\n");
        menu2();
    }
    else
        printf("登录失败!帐号/密码错误!\n");
    return 0;
}
/*************教师菜单****************/
void menu1()
{
    int choice,w1=1;
    do
    {
        puts("\t*********************************************");
        puts("\t*        欢迎使用学籍管理系统        *");
        puts("\t*        1)录入学生信息              *");
        puts("\t*        2)查找学生信息              *");
        puts("\t*        3)删除学生信息              *");
        puts("\t*        4)修改学生信息              *");
        puts("\t*        5)显示所有学生信息          *");
        puts("\t*        6)退出系统                  *");
        puts("\t*********************************************");
        printf("想选择的功能:");
        scanf("%d",&choice);
        if(choice<1||choice>6)
        {
            system("cls");
            printf("菜单选择错误,请重新选择\n");
        }
        switch(choice){//根据用户的菜单选择调用函数
            case 1:add();    break;//自定义的函数名
            case 2:Find();    break;
            case 3:shanchu();break;
            case 4:change();break;
            case 5:read();    break;
            case 6:exit(0);break;
            default:break;
        }
     }while(w1==1);
 }

   /***************学生菜单界面***********/
void menu2()
{
    int choice,w1=1;
    do
    {
        puts("\t*********************************************");
        puts("\t*        欢迎使用学籍管理系统        *");
        puts("\t*        1)录入学生信息              *");
        puts("\t*        2)修改学生信息              *");
        puts("\t*        3)退出系统                  *");
        puts("\t*********************************************");
        printf("想选择的功能:");
        scanf("%d",&choice);
        if(choice<1||choice>3)
        {
            system("cls");
            printf("菜单选择错误,请重新选择\n");
        }
        switch(choice){//根据用户的菜单选择调用函数
            case 1:add();    break;//自定义的函数名
            case 2:change();break;
            case 3:exit(0);break;
            default:break;
        }
    }while(w1==1);
}

 int load()
 {
     FILE*fp;
     int i=0;
     fp=fopen("student.txt","rb");
     if(fp==NULL)
     {
         printf("文件打开错误");
         return 0;
     }
     while(!feof(fp)){
        fscanf(fp,"%s%s%s%s%s%s%s",stu[i].no,stu[i].name,stu[i].sex,stu[i].age,stu[i].NativePlace,
                stu[i].major,stu[i].grade);
        i++;
     }
     fclose(fp);
     return(i);
 }
 /***************保存函数*****************/
 void save(int n)
 {
     int i;
     FILE *fp;
     fp=fopen("student.txt","wb");
     if(fp==NULL)
     {
         printf("文件打开错误");
    }
     for(i=0;i<n;i++){
        fprintf(fp,"%s %s %s %s %s %s %s\r\n",stu[i].no,stu[i].name,stu[i].sex,stu[i].age,stu[i].NativePlace,
                stu[i].major,stu[i].grade);
     }
     fclose(fp);
  }
/************查看(显示)函数****************/
 void read()
 {
     int n,m;
     int xz,choice;//选择返回还是退出系统的变量//
     n=load();
     printf("学号\t姓名\t性别\t年龄\t籍贯\t专业\t年级\t");
     for(m=0;m<n;m++)
     {
         printf("\n%s",stu[m].no);
         printf("\t %s",stu[m].name);
         printf("\t %s",stu[m].sex);
         printf("\t %s",stu[m].age);
         printf("\t %s",stu[m].NativePlace);
         printf("\t %s",stu[m].major);
         printf("\t %s",stu[m].grade);
    }
    do
    {
        printf("\n 1-返回主菜单;2-退出系统\n");
        scanf("%d",&choice);
        if(choice<1||choice>2)
        {
            xz=1;system("cls");
            printf("输入错误,请重新选择!\n");
        }
        else xz=0;
    }while(xz==1);
    switch(choice)
    {
        case 1:return;break;//调用菜单函数
        case 2:exit(0);break;//退出系统
    }

 }
 //******************录入学生信息*****************//
 void add()
 {
     int i,n,m;
     int xz,choice;//选择返回还是退出系统的变量
     n=load();

    printf("你想要录入多少个学生信息?");
    scanf("%d",&m);
    for(i=0;i<m;i++)
    {
        printf("\n学号:");
        scanf("%s",stu[n+i].no);
        printf("姓名:");
        scanf("%s",stu[n+i].name);
        printf("性别:");
        scanf("%s",stu[n+i].sex);
        printf("年龄:");
        scanf("%s",stu[n+i].age);
        printf("籍贯:");
        scanf("%s",stu[n+i].NativePlace);
        printf("专业: ");
        scanf("%s",stu[n+i].major);
        printf("年级:");
        scanf("%s",stu[n+i].grade);
        printf("输入完成");
        save(n+m);
        }
    do
    {
        printf("\n 1-返回主菜单;2-退出系统\n");
        scanf("%d",&choice);
        if(choice<1||choice>2)
        {
            xz=1;system("cls");
            printf("输入错误,请重新选择!\n");
        }
        else xz=0;
    }while(xz==1);
    switch(choice)
    {
        case 1:return;break;//调用菜单函数
        case 2:exit(0);break;//退出系统
    }

  }
/**************修改函数*****************/
void change()
{
    int n,i,j;
    char m[9];
    n=load();
    printf("输入你要修改的学生的学号:");
    scanf("%s",m);
    for(i=0;i<n;i++)
    {
        if(!strcmp(stu[i].no,m))
        {
            printf("你要修改的项目: \n1)学号 2)姓名 3)性别 4)年龄 5)籍贯 6)专业 7)年级\n");
            printf("你选择的功能是:");
            scanf("%d",&j);
            switch(j)
            {
                case 1:
                    printf("输入你修改后的学号:");
                    scanf("%s",stu[i].no);
                    break;
                case 2:
                    printf("输入你修改后的姓名:");
                    scanf("%s",stu[i].name);
                    break;
                case 3:
                    printf("输入你修改后的性别: ");
                    scanf("%s",stu[i].sex);
                    break;
                case 4:
                    printf("输入你修改后的年龄:");
                    scanf("%s",stu[i].age);
                    break;
                case 5:
                    printf("输入你修改后的籍贯: ");
                    scanf("%s",stu[i].NativePlace);
                    break;
                case 6:
                    printf("输入你修改后的专业: ");
                    scanf("%s",stu[i].major);
                    break;
                case 7:
                    printf("输入你修改后的年级: ");
                    scanf("%s",stu[i].grade);
                    break;
                default:
                printf("选择的功能错误\n");
                int getch();
                change();
                break;
                 }
        }
    }
    {
        int xz,choice;
        do
        {
            printf("\n1-返回主菜单;2-退出系统\n");
            scanf("%d",&choice);
            if(choice<1||choice>2)
            {
                xz=1;
                system("cls");
                printf("输入错误,请重新选择!\n");
            }
            else xz=0;
        }while(xz==1);
        switch(choice)
        {case 1:
            return;break;
            case 2:
            exit(0);break;
        }

    }
}

//**********删除函数************
void shanchu()
{int n,i,j;
 char m[9];
 n=load();
 printf("输入你要删除资料的学生的学号:");
 scanf("%s",m);
 for(i=0;i<n;i++)
 if(!strcmp(stu[i].no,m))
 {for(j=i;j<n-1;j++)
  {
      strcpy(stu[j].no,stu[j+1].no);
      strcpy(stu[j].name,stu[j+1].name);
      strcpy(stu[j].sex,stu[j+1].sex);
      strcpy(stu[j].age,stu[j+1].age);
      strcpy(stu[j].NativePlace,stu[j+1].NativePlace);
      strcpy(stu[j].major,stu[j+1].major);
      strcpy(stu[j].grade,stu[j+1].grade);

  }save(n-1);
 }
     {
        int xz,choice;
        do
        {
            printf("\n1-返回主菜单;2-退出系统\n");
            scanf("%d",&choice);
            if(choice<1||choice>2)
            {xz=1;system("cls");printf("输入错误,请重新选择!\n");
            }
            else xz=0;
         }while(xz==1);
        switch(choice)
        {case 1:
            return;break;
            case 2:
            exit(0);break;
        }

    }
}

//*************查找函数*********
void Find()
{
    int meau();
    int n,i;
    char m[9];
    n=load();
    printf("\t\t\t请输入你要查找的学生的学号: ");
    scanf("%s",m);
    for(i=0;i<n;i++)
    {
        if(!strcmp(stu[i].no,m))
        {
            printf("学号\t 姓名\t 性别\t 年龄\t 籍贯\t 专业\t 年级\n");
            printf("%s",stu[i].no);
            printf("\t%s",stu[i].name);
            printf("\t%s",stu[i].sex);
            printf("\t%s",stu[i].age);
            printf("\t%s",stu[i].NativePlace);
            printf("\t%s",stu[i].major);
            printf("\t%s",stu[i].grade);

        }
    }
    {
        int xz,choice;
        do
        {
            printf("\n1-返回主菜单;2-退出系统\n");
            scanf("%d",&choice);
            if(choice<1||choice>2)
            {xz=1;system("cls");printf("输入错误,请重新选择!\n");
            }
            else xz=0;
        }while(xz==1);
        switch(choice)
        {
            case 1:
                return;break;
            case 2:
                exit(0);break;
        }

    }
}
搜索更多相关主题的帖子: stu printf scanf choice break 
2018-06-18 08:09
快速回复:学生管理系统输入多组数据后,最后一组重复输出是怎么回事
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018673 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved