标题:学生管理系统 出现好多问题 求解
取消只看楼主
爱因斯谭
Rank: 1
等 级:新手上路
帖 子:4
专家分:1
注 册:2011-11-28
结帖率:0
已结贴  问题点数:5 回复次数:2 
学生管理系统 出现好多问题 求解
//学生管理系统模拟   
//该系统能够模拟学生基本信息管理。
#include <stdio.h>
#include <stdlib.h>
#include<iostream.h>
#include<string.h>
#define LEN sizeof(struct student)
//定义学生结构体
struct student
{
    long num;
    long key;
    char name[10];
    char sex[4];
    int E;
    int C;
    struct student *next;
}stu[LEN],s;
int n, flag=0,a;
char q;
//***********************************************菜单模块***********************************************************
//退出函数
void  logout()
 {   
    printf("___________退出系统,欢迎下次使用____________)\n");
 }
//注册函数
void zhuce()
{  
    FILE *fp;
    printf("* 请输入8位学号:");
    scanf("%d",&s.num);
    printf("* 请输入密码:");
    scanf("%d",&s.key);
    fp=fopen("new file1","ab+");
    fwrite(&s,sizeof(struct student),1,fp);
    printf("                     注册成功!");
    system("pause");
    system("cls");
    printf("                 进入登录界面......\n");
    a=0;
    fclose(fp);
}
//登录函数
void login()
{   long num,key,i;
    FILE *fp;
    system("cls");
    printf("登陆中.........\n");
    printf("进入本系统需要输入用户帐号和密码\n");
    printf("        1-------------------没有用户名,进入注册\n");
    printf("        0-------------------已注册,进入系统\n");
    printf("请选择__");
    scanf("%d",&a);   
    if(a==1)
        zhuce();
    fp=fopen("new file1","rb");
   while(a==0)
   for(i=3;i>0;i--)
   {                        
          while(fread(&s,sizeof(struct student),1,fp)==1)
              printf("-------------------请输入用户帐号:");
              scanf("%d",&num);
              printf("-------------------请输入密码:");
              scanf("%d",&key);         
              if(num==s.num&&key==s.key)
              {   
                  a=2;
                  flag=1;              
                  break;
              }
              else           
                  printf("用户名和密码不匹配,还有%d次!输入机会\n",i-1);      
                if(i==1)
              {
                  printf("!!!三次机会已到,请退出系统 重新进入!!!<<<\n");   
                  flag=0;a=2;
              }
         
                fclose(fp);
   }
}
//菜单函数
void menu()
{

   printf("*****************************『学生管理系统』*********************************\n");
   printf("                       1------------‖登录系统‖\n");
   printf("                       0------------‖退出系统‖\n");
   printf("请选择1 or 0?");
   scanf("%d",&n);
   switch(n)
   {
   case 1:login();break;
   case 0:logout();break;
   default: {system("cls");
       printf("输入错误,请重新输入或者退出系统\n");
             menu();break;}
      
   }
}
//*****************************************学生录入模块***************************************************
void input()
{     system("cls");
     struct student *head,*p1,*p2;
     char f='y';
     FILE *fp;
    printf("*****************************『欢迎进入录入系统』******************************\n");        
    n=0;
    p1=p2=(struct student *)malloc(LEN);
    head=NULL;
    while(f=='y'||f=='Y')
    {    n=n+1;
        if(n==1)head=p1;
        else p2->next=p1;
        p2=p1;
        p1=(struct student*)malloc(LEN);
        printf("学号:\n");
        scanf("%ld",&p1->num);
        printf("姓名:\n");
        scanf("%s",p1->name);
        printf("性别:\n");
        scanf("%s",p1->sex);
        printf("英语成绩:\n");
        scanf("%d",&p1->E);
        printf("C语言成绩:\n");
        scanf("%d",&p1->C);
        printf("是否继续录入学生信息?y or n\n");
        scanf("%c",&f);
    }
    p2->next=NULL;
    p1=head;      //必须有头指针
    fp=fopen("new file3","wb+");
    do
      fwrite(p1,sizeof(struct student),1,fp);
      while(p1->next=NULL);
      fclose(fp);
}
//*********************************************学生浏览模块**************************************************
void brower()
{   system("cls");
    printf("**************************『欢迎进入浏览系统』*******************************\n");
    FILE *fp;
    struct student *p;
    p=(struct student *)malloc(LEN);
    fp=fopen("new file3","rb");
        printf("------------------------------------------------------------------------\n");
        printf("【学号】     【姓名】     【性别】     【英语成绩】     【C语言成绩】\n ");
        printf("------------------------------------------------------------------------\n");
    while(fread(p,sizeof(struct student),1,fp)==1)
    {   
        printf("%ld%         %s             %d           %d             %d\n",&p->num,&p->name,&p->sex,&p->E,&p->C);
        printf("------------------------------------------------------------------------\n");
        p=p->next;
    }
    getchar();
    fclose(fp);
}
//********************************************学生查询模块***************************************************
//按姓名查找函数
void xingming()
{    char name[10];
     FILE *fp;
     struct student *p;
    printf("请输入要查找学生的姓名:\n");
    scanf("%s",&name);
    fp=fopen("new file3","rb");
    p=(struct student *)malloc(LEN);
    while(fread(p,sizeof(struct student),1,fp)==1)
    {     
        if(strcmp(p->name,name)==0)
    {   
        printf("该学生的学习信息是:\n");
        printf("------------------------------------------------------------------------\n");
        printf("【学号】     【姓名】     【性别】     【英语成绩】     【C语言成绩】\n ");
        printf("------------------------------------------------------------------------\n");
        printf("%ld%          %s           %d            %d             %d\n",&p->num,&p->name,&p->sex,&p->E,&p->C);
        printf("------------------------------------------------------------------------\n");
        break;
    }
        else p=(struct student *)malloc(LEN);
    }   
    fclose(fp);   
    printf("没有对应的学生信息,请重新输入学生姓名\n");
    printf("输入q,返回主菜单");
        scanf("%c",&q);
}
//按学号查找函数
void xuehao()
{   int num;
    FILE *fp;
    struct student *p;
    printf("请输入要查找学生的学号:\n");
    scanf("%d",&num);
    fp=fopen("new file3","rb");
    p=(struct student *)malloc(LEN);
    while(fread(p,sizeof(struct student),1,fp)==1)
    {     if(num==p->num)
    {   printf("该学生的学习信息是:\n");
        printf("------------------------------------------------------------------------\n");
        printf("【学号】     【姓名】     【性别】     【英语成绩】     【C语言成绩】\n ");
        printf("------------------------------------------------------------------------\n");
        printf("%ld%           %s           %d           %d               %d\n",&p->num,&p->name,&p->sex,&p->E,&p->C);
        printf("------------------------------------------------------------------------\n");
        break;
    }
        else p=(struct student *)malloc(LEN);
    }   
    fclose(fp);
        printf("没有对应的学生信息,请重新输入学生姓名");
        printf("输入q,返回主菜单");
        scanf("%c",&q);
}
//查找主函数
void search()
{   system("cls");
    printf("***************************『欢迎进入查询系统』****************************\n");
    printf("             1---------------------‖按照姓名查找‖\n");
    printf("             2---------------------‖按照学号查找‖\n");
    printf("请选择输入1 or 2?");
    scanf("%d",&n);
    switch(n)
    {
        case 1:xingming();break;
        case 2:xuehao();break;
        default :
            {    system("cls");
                  printf("输入错误,请重新输入!\n");         
                 search();

            }
    }
}
//***********************************************学生删除模块*************************************************
//按学号删除
void numdel()
{   
    FILE *fp;
    struct student *p1,*p2;
    int num;
    char m='y';
    fp=fopen("new file3","rb");
    p2=p1=(struct student *)malloc(LEN);
    printf("请输入要删除的学生学号:\n");
    scanf("%d",&num);
    while(m=='Y'||m=='y')
    {
        do
         fread(p1,sizeof(struct student),1,fp);
         p2=p1;         p1=p1->next;
        if(num==p1->num)
            p2->next=p1->next;
            printf("成功删除!");
        if(num!=p1->num)
            printf("该学生不存在!");
        printf("是否继续删除学生信息?y or n?");
        scanf("%c",&m);
        while(num!=p1->num&&p1->next==NULL);
    }
    fclose(fp);
}
//按姓名查找
void namedel()
{   
    FILE *fp;
    struct student *p1,*p2;
    char name[10];
    char m='y';
    fp=fopen("new file3","rb");
    p2=p1=(struct student *)malloc(LEN);
    printf("请输入要删除的学生姓名:\n");
    scanf("%s",name);
    while(m=='Y'||m=='y')
    {
    while((fread(p1,sizeof(struct student),1,fp)==1)&&strcmp(p1->name,name)!=0)
    {   p2=p1;p1=p1->next;   }
        if(strcmp(p1->name,name)==0)
            p2->next=p1->next;
            printf("成功删除!");
        if(strcmp(p1->name,name)!=0)
            printf("该学生不存在!");
        printf("是否继续删除学生信息?y or n?");
        scanf("%c",&m);
    }
    fclose(fp);
}
//删除主函数
void delet()
{   system("cls");
    printf("************************『欢迎进入删除系统』******************************\n");
    printf("             1---------------------‖按照姓名删除‖\n");
    printf("             2---------------------‖按照学号删除‖\n");
    printf("请选择输入1 or 2?");
    scanf("%d",&n);
    switch(n)
    {
        case 1:namedel();break;
        case 2:numdel();break;
        default :
            {    system("cls");
                  printf("输入错误,请重新输入!\n");         
                 delet();
            }
    }
}
//*********************************************成绩统计模块*************************************************
//按照英语成绩排序函数
void esort()
{     
    FILE *fp;
    int i,j;
    struct student t;
    fp=fopen("new file3","rb");
        printf("------------------------------------------------------------------------\n");
        printf("【学号】     【姓名】     【性别】     【英语成绩】     【C语言成绩】\n ");
        printf("------------------------------------------------------------------------\n");
    while(fread(&stu[LEN],sizeof(struct student),1,fp)==1)
    {   
    for(i=0;i<LEN;i++)
        {for(j=0;j<LEN-i;j++)
            if(stu[i].E<stu[i-1].E)
            { stu[i]=t,t=stu[i-1],stu[i-1]=stu[i];}
        printf("%ld     %s     %s     %d     %d\n",&stu[i].num,&stu[i].name,&stu[i].sex,&stu[i].E,&stu[i].C);
        printf("------------------------------------------------------------------------\n");
        }
    }
    fclose(fp);
}
//按照C语言成绩排序函数
void csort()
{
    FILE *fp;
    int i,j;
    struct student t;
    fp=fopen("new file3","rb");
        printf("------------------------------------------------------------------------\n");
        printf("【学号】     【姓名】     【性别】     【英语成绩】     【C语言成绩】\n ");
        printf("------------------------------------------------------------------------\n");
    while(fread(&stu[LEN],sizeof(struct student),1,fp)==1)
    {   
    for(i=0;i<LEN;i++)
        {for(j=0;j<LEN-i;j++)
            if(stu[i].C<stu[i-1].C)
            { stu[i]=t,t=stu[i-1],stu[i-1]=stu[i];}
        printf("%ld     %s     %s     %d     %d\n",&stu[i].num,&stu[i].name,&stu[i].sex,&stu[i].E,&stu[i].C);
        printf("------------------------------------------------------------------------\n");
        }
    }
    fclose(fp);
}
//按照总分排序
void ssort()
{
    FILE *fp;
    int i,j;
    struct student t;
    fp=fopen("new file3","rb");
        printf("------------------------------------------------------------------------\n");
        printf("【学号】     【姓名】     【性别】     【英语成绩】     【C语言成绩】\n ");
        printf("------------------------------------------------------------------------\n");
    while(fread(&stu[LEN],sizeof(struct student),1,fp)==1)
    {   
    for(i=0;i<LEN;i++)
        {for(j=0;j<LEN-i;j++)
            if(stu[i].E+stu[i].C <stu[i-1].E+stu[i-1].C)
            { stu[i]=t,t=stu[i-1],stu[i-1]=stu[i];}
        printf("%ld     %s     %s     %d     %d\n",&stu[i].num,&stu[i].name,&stu[i].sex,&stu[i].E,&stu[i].C);
        printf("------------------------------------------------------------------------\n");
        }
    }
    fclose(fp);
}
//统计主函数
void tongji()
{   system("cls");
    printf("***********************『欢迎进入统计系统』****************************\n");
    printf("             1---------------------‖查看按英语成绩排序‖\n");
    printf("             2---------------------‖查看按C语言成绩排序‖\n");
    printf("             3---------------------‖查看按总分排序‖\n");
    printf("");
    printf("请选择输入1 ,2 or 3?");
    scanf("%d",&n);
    switch(n)
    {
        case 1:esort();break;
        case 2:csort();break;
        case 3:ssort();break;
        default :
            {    system("cls");
                  printf("输入错误,请重新输入!\n");         
                 tongji();
            }
    }
}
//主函数

void main()
{      menu();
       while(flag)
       {
           system("cls");
        printf("*****************************『学生管理系统』*********************************\n");
           printf("                   1----------【学生录入】\n");
           printf("                   2----------【学生浏览】\n");
           printf("                   3----------【学生查询】\n");
           printf("                   4----------【学生删除】\n");
           printf("                   5----------【成绩统计】\n");
           printf("                   0----------【退出系统】\n");     
           printf("请选择:(0----5)\n");
           scanf("%d",&n);
           switch(n)
        {
            case 0:logout();break;
               case 1:input();break;
            case 2:brower();break;
            case 3:search();break;
            case 4:delet();break;
            case 5:tongji();break;
            default :printf("输入错误,请重新输入!");
           }
       }
}
搜索更多相关主题的帖子: 管理系统 include logout 结构体 信息 
2012-03-20 09:09
爱因斯谭
Rank: 1
等 级:新手上路
帖 子:4
专家分:1
注 册:2011-11-28
得分:0 
回复 2楼 木头lbj
这个怎么追加分数呢 嘿嘿~新手不懂哈
2012-03-20 16:53
爱因斯谭
Rank: 1
等 级:新手上路
帖 子:4
专家分:1
注 册:2011-11-28
得分:0 
回复 3楼 C_戴忠意
嘿嘿 没写注释
2012-03-20 16:53



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-363715-1-1.html




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

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