| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3874 人关注过本帖, 2 人收藏
标题:分享:我用c写的简单学生管理系统
只看楼主 加入收藏
yanhaolang
Rank: 1
等 级:新手上路
帖 子:60
专家分:7
注 册:2007-3-12
收藏(2)
 问题点数:0 回复次数:15 
分享:我用c写的简单学生管理系统
#include "stdio.h"
#include "stdlib.h"
#define M 10
struct student
{
    int num;
    char name[20];
    float score[3];
    float avg;
};
int input(struct student a[]);//函数声明
void output(struct student a[],int);
void sort(struct student a[],int);
int insert(struct student a[],int);
int del(struct student a[],int);
void main()
{
    int m,count=0;
    struct student stu[M];
    do
    {
    printf("\n\n\t***************************************\n");
    printf("\t\t学 生 成 绩 管 理 系 统 \n");
    printf("\t***************************************\n");
    printf("\t1、录入\t2、输出\t3、排序\t4、插入\t5、删除\n\n");
    scanf("%d",&m);

    switch(m)
    {
    case 1:
    count=input(stu);
    break;
    case 2:
   //sort(stu,count);
    output(stu,count);
    break;
    case 3:
    sort(stu,count);
    output(stu,count);
    break;
    case 4:
    sort(stu,count);
    count=insert(stu,count);
    break;
    case 5:
    count=del(stu,count);
    break;
    default:
    exit(0);
    }
    }while(m!=0);
}
int input(struct student a[])
{
 int count=0;char c;
    do
    {
        printf("请输入学号:\n");
        fflush(stdin);
        scanf("%d",&a[count].num);
        printf("请输入姓名:\n");
        fflush(stdin);
        gets(a[count].name);
        printf("请输入成绩1:\n");
        fflush(stdin);
        scanf("%f",&(a[count].score[0]));
        printf("请输入成绩2:\n");
        fflush(stdin);
        scanf("%f",&(a[count].score[1]));
        printf("请输入成绩3:\n");
        fflush(stdin);
        scanf("%f",&(a[count].score[2]));        
        a[count].avg=(a[count].score[0]+a[count].score[1]+a[count].score[2])/3;
        count++;        
        if(count>M)
        break;
        printf("你还要继续输入吗?(y/Y或n/N)\n");
        fflush(stdin);
        c=getchar();
    }while(c=='y'||c=='Y');
    return count;
}
void output(struct student a[],int count)
{
    printf("学号\t姓名\t成绩1\t成绩2\t成绩3\t平均成绩\n");
    for(int i=0;i<count;i++)
    {
      printf("%d\t%s\t%4.1f\t%4.1f\t%4.1f\t%4.1f\n",a[i].num,a[i].name,a[i].score[0],a[i].score[1],a[i].score[2],a[i].avg);
    }
}
void sort(struct student a[],int count)
{
    struct student temp;
    for(int i=0;i<count;i++)
        for(int j=0;j<count-i-1;j++)
            if(a[j].avg<a[j+1].avg)
            {
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
            }
}
int insert(struct student a[],int count)
{
    struct student temp;float sum=0;
    printf("请输入你要插入的学生的信息:\n");
    printf("学号:");
    scanf("%d",&temp.num);
    printf("姓名:");
    scanf("%s",temp.name);
    for(int i=0;i<3;i++)
    {
        printf("第%d门课成绩:\n",i+1);
        scanf("%f",&temp.score[i]);
        sum+=temp.score[i];
    }
    temp.avg=sum/3;
    for(i=0;i<count;i++)
    {
        if(temp.avg>a[i].avg)
        {
                for(int j=count-1;j>=i;j--)
                {
                    a[j+1]=a[j];
                }
                a[i]=temp;
                break;
        }
    }
    if(i==count)
    a[count]=temp;
    count++;
    return count;
}
int del(struct student a[],int count)
{
    int tempnum;
    printf("请输入你要删除的学员的学号:\n");
    scanf("%d",&tempnum);
    for(int i=0;i<count;i++)
    {
        if(tempnum==a[i].num)
        {
            for(int j=i;j<count-1;j++)
                a[j]=a[j+1];
        //    count--;
            break;
        }
    }
    if(i==count)
       printf("对不起,找不到你要删除的学员!\n");
    else
    {
        count--;
        printf("删除成功!\n");
    }
    return count;
}

以前写的,大家共同学习,多多指正。。。

[[it] 本帖最后由 yanhaolang 于 2008-2-8 17:54 编辑 [/it]]
搜索更多相关主题的帖子: int student struct quot 系统 
2008-02-08 17:42
闪闪4521
Rank: 1
等 级:新手上路
帖 子:196
专家分:0
注 册:2007-11-30
收藏
得分:0 
程序健壮性太差
当输入信息错误程序就不行了.....
其他没仔细看
继续加油吧
2008-02-08 20:49
蓝色神话
Rank: 2
等 级:论坛游民
威 望:1
帖 子:404
专家分:24
注 册:2006-5-11
收藏
得分:0 
嘿嘿,当年我学C语言时候,最后的课程设计也有类似的题目,初学者能独立写出这个程序已属不易了,加油!
2008-02-08 21:20
死了都要C
Rank: 4
来 自:四川成都
等 级:贵宾
威 望:13
帖 子:1582
专家分:116
注 册:2006-12-7
收藏
得分:0 
DEV-CPP4.9.9.2编译不通过``

女施主``我给你``送茶来了```师太``你就从了老衲吧``
代码本天成~~~妙头偶得之```
2008-02-09 18:53
hangeng
Rank: 2
等 级:论坛游民
帖 子:424
专家分:39
注 册:2007-7-23
收藏
得分:0 
给你个全的!
/*****************************************************************/
//              学生学籍管理系统v1.0测试版.      
//              开发者:☆ゞ天涯☆ゞ。           
//              开发时间:2007-05-15            
//              系统登陆密码:521314
//              QQ: 214880229                    
/*****************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <time.h>

#define NAME       20
#define SEX        10
#define BIRTH      20
#define ADDDR      30
#define POTO       12
#define DAK        10
#define SCHOOL     30
#define SORC       6
#define STUDENTMAX 1000                                      //学生最大人数
#define PASSWORD "521314"                                    //系统登陆密码

/************************学生信息结构体**********************/
struct studentinfo                                           //学生个人信息结构
{
    char name  [NAME];                                       //学生姓名
    char sex   [SEX];                                        //学生性别
    char birth [BIRTH];                                      //出生日期
    char adddr [ADDDR];                                      //学生地址
    char poto  [POTO];                                       //联系电话
    char dak   [DAK];                                        //邮证编码
    char school[SCHOOL];                                     //所在学校  
};
struct studentsorc                                           //学生成绩结构
{
    char name[NAME];                                         //学生姓名
    int   ID;                                                //学生学号
    float sorc[6];                                           //记录学生成绩
    float aver;                                              //平均分
    float sum;                                               //总分  
};
struct allstudentinfo                                        //学生全部结构
{
    struct studentinfo student;
    struct studentsorc student1;  
};

FILE *infofile=NULL;                                         //存学生个人信息数据文件
FILE *sorcfile=NULL;                                         //存学生成绩数据文件
char filename[]="c:\\学生个人信息登记.dat";                  //记录个人信息登记
char filename1[]="c:\\学生成绩.dat";                         //记录学生成绩

/************************函数块声明****************************/

void password();                                            //密码验证
int  showmeun();                                            //系统主菜单显示
int  submeun();                                             //子菜单显示
void sorcmeun(struct allstudentinfo *);                     //成绩管理子菜单
void submain(struct allstudentinfo *);                      //子系统
void inputinfo(struct allstudentinfo *);                    //输入学生个人信息
void modinfo(struct allstudentinfo *);                      //修改个人信息
void aboutinfo(struct allstudentinfo *);                    //查询个人信息
void allabout(struct allstudentinfo *);                     //查询所有信息
void delinfo(struct allstudentinfo *);                      //删除个人信息
void mofname(struct allstudentinfo *);                      //修改姓名
void mofsex(struct allstudentinfo *);                       //修改性别
void mofbirth(struct allstudentinfo *);                     //修改出生日期
void mofadddr(struct allstudentinfo *);                     //修改家庭住址
void mofpoto(struct allstudentinfo *);                      //修改电话号码
void mofdak(struct allstudentinfo *);                       //修改邮证编码
void mofschool(struct allstudentinfo *);                    //修改所在院校
int datfile(struct allstudentinfo *);                       //处理修改个人信息的文件
void inputsorc(struct allstudentinfo *);                    //个人成绩录入
void mofsorc  (struct allstudentinfo *);                    //修改成绩
void seasorc  (struct allstudentinfo *);                    //查找个人成绩
void seaallsorc(struct allstudentinfo *);                   //浏览所有成绩
void delsorc  (struct allstudentinfo *);                    //删除成绩
int sorcdatfile(struct allstudentinfo *);                   //成绩数据文件
void systemhelp();                                          //系统帮助信息

int main(void)
{
    struct allstudentinfo studentmax[STUDENTMAX];           //最大学生人数
    struct allstudentinfo *p_student;                       //指向结构指针
    int    in;
    time_t start,end;
   
    p_student=studentmax;                                   //指向结构体
    password();                                             //获取用户密码验证
   
    do
    {
        system("cls");
        in=showmeun();                                      //系统主菜单显示
        switch(in)
        {
            case 1 : submain(p_student);               
                     break;
            case 2 : sorcmeun(p_student);
                     break;
            case 3 : systemhelp();
                     break;
            case 4 : break;
            
            default: printf("没有此选项,请按任意键返回重新选择!");
                     getch();
                     system("cls");
                     break;
        }
    }while(in!=4);
    system("cls");
    printf("\n\n\n\n\n\n\n\n\t\t\t");
    printf("谢    使          !");
    start=time(NULL);
    end=time(NULL);
    while(end-start<1.5)
        end=time(NULL);
    return 0;
}

  雨水冲不进窗来,在玻璃上痛哭。但它至少奋斗过。
2008-02-09 20:08
hangeng
Rank: 2
等 级:论坛游民
帖 子:424
专家分:39
注 册:2007-7-23
收藏
得分:0 
/************************子系统*******************************/
void submain(struct allstudentinfo *p_student)
{
    int  in;
   
    do
    {
        system("cls");
        in=submeun();                                                    //子菜单显示
        switch(in)
        {
            case 1 : inputinfo(p_student);                               //输入个人信息
                     break;
            case 2 : modinfo(p_student);                                 //修改个人信息
                     break;
            case 3 : aboutinfo(p_student);                               //查询个人信息
                     break;
            case 4 : allabout(p_student);                                //查询所有信息
                     break;
            case 5 : delinfo(p_student);                                 //删除个人信息
                     break;
            case 6 : break;
            
            default: printf("没有此选项。请您重新输入(1-5)");
                     getch();
                     system("cls");
                     break;
        }
    }while(in!=6);
    system("cls");
    return ;
}

/************************密码验证*****************************/
void password()
{
    char *pass=NULL;                                        //初始化指针
    int  count;
    time_t start,end;                                       //时间函数
   
    pass=(char *)malloc(255*sizeof(char));                  //分配内存
    while(1)
    {
        count=0;
        printf("\n\n\n\n\n\t\t         学生信息管理系统Ver1.0测试版     \n");
        printf("\n\t\t               用户名:TIANYA           \n");
        printf("\n\t\t                 码:");
        while((count>=0)&&(pass[count++]=getch())!=13)    //密码输入
        {
            if(pass[0]=='\b')
            {
                count=0;
                continue;
            }
            else if(pass[count-1]=='\b')
            {
                printf("%c%c%c",'\b','\0','\b');
                count-=2;
            }
            else
            putchar('*');
        }
        pass[--count]='\0';
        if(!strcmp(pass,PASSWORD))                          //开始验证
        {
            system("cls");
            printf("\n\n\n\n\n\n\n\n\n\t\t\t");
            printf(" 欢 迎 登 陆 学 生 信 息 管 理 系 统 !");
            start=time(NULL);
            end=time(NULL);
            while(end-start<1)                              //延时1秒执行以下程序
            {
                end=time(NULL);
            }
            system("cls");
            free(pass);                                     //释放储存密码的内存
            return ;
        }
        free(pass);                                         //释放密码错误的那块内存
        pass=(char *)malloc(255*sizeof(char));              //重新分配储存密码内存
        system("cls");
        printf("\a\n\n\n\n\n\n\n\n\t\t\t\t密 码 错 误 !");
        getch();
        system("cls");
    }
}

/***********************系统主菜单************************/
int showmeun()
{
    int  in;
    char ch;
   
    printf("\n\n\n\n");
    printf("\t ╭────────────────────────────╮\n");
    printf("\t ∣           学生个人信息管理系统v1.0测试版               ∣\n");
    printf("\t |————————————————————————————|\n");
    printf("\t | \t    1.  学生个人信息管理            |\n");
    printf("\t |                            |\n");
    printf("\t | \t    2. 学生个人成绩管理            |\n");
    printf("\t |                            |\n");
    printf("\t | \t    3. 关于本系统帮助             |\n");
    printf("\t |                            |\n");
    printf("\t | \t    4. 退 出 系 统             |\n");
    printf("\t |                            |\n");  
    printf("\t | \t    5  版权                  |\n");      
    printf("\t  ╰────────────────────────────╯\n");
    printf("\t   请您正确选择:");
    while(scanf("%d",&in)!=1)
    {
        while((ch=getchar())!='\n')
            putchar(ch);
            return in;
    }
    fflush(stdin);
    return in;
}

  雨水冲不进窗来,在玻璃上痛哭。但它至少奋斗过。
2008-02-09 20:09
hangeng
Rank: 2
等 级:论坛游民
帖 子:424
专家分:39
注 册:2007-7-23
收藏
得分:0 
/***************************************************************/
//   个人信息管理系统目前只支持学生的个人资料登记
//   不支持成绩的录入,如须录入学生的个人成绩,请
//   使用“学生成绩管理系统,*必须要先在本系统登记
//   之后才能正常使用成绩管理系统,否则可能会发生
//   错误的提示
/***********************个人信息子菜单*************************/
int submeun()
{
    int  in;
    char ch;
   
    system("cls");
    printf("\n\n\n");
    printf("\t\t ————————————————————————\n");
    printf("\t\t|      学生个人信息管理系统       |\n");
    printf("\t\t|———————————————————————|\n");
    printf("\t\t|       1.录入个人信息         |\n");
    printf("\t\t|                       |\n");
    printf("\t\t|       2.修改个人信息         |\n");
    printf("\t\t|                       |\n");
    printf("\t\t|       3.查询个人信息         |\n");
    printf("\t\t|                       |\n");
    printf("\t\t|       4.浏览所有信息         |\n");
    printf("\t\t|                       |\n");
    printf("\t\t|       5.删除个人信息         |\n");
    printf("\t\t|                       |\n");
    printf("\t\t|       6.退出系统           |\n");
    printf("\t\t ————————————————————————\n");
    printf("\t\t 请您正确选择:");
    while(scanf("%d",&in)!=1)
    {
        while((ch=getchar())!='\n')
            putchar(ch);
            return 0;
    }
    fflush(stdin);
    return in;
}

/***************************修改个人信息子菜单************************/
void modinfo(struct allstudentinfo *p_student)
{
    int  in;
    char ch;
   
    do
    {
        system("cls");
        printf("\n\n\n");
        printf("\t\t ————————————————————————\n");
        printf("\t\t|        个人信息修改管理       |\n");
        printf("\t\t|———————————————————————|\n");
        printf("\t\t|       1.修改用户姓名         |\n");
        printf("\t\t|                       |\n");
        printf("\t\t|       2.修改用户性别         |\n");
        printf("\t\t|                       |\n");
        printf("\t\t|       3.修改出生日期         |\n");
        printf("\t\t|                       |\n");
        printf("\t\t|       4.修改家庭住址         |\n");
        printf("\t\t|                       |\n");
        printf("\t\t|       5.修改联系电话         |\n");
        printf("\t\t|                       |\n");
        printf("\t\t|       6.修改邮证编码         |\n");
        printf("\t\t|                       |\n");
        printf("\t\t|       7.修改所在院校         |\n");
        printf("\t\t|                       |\n");
        printf("\t\t|       8.退出系统           |\n");
        printf("\t\t ————————————————————————\n");
        printf("\t\t 请您正确选择:");
        while(scanf("%d",&in)!=1)
        {
            while((ch=getchar())!='\n')
                putchar(ch);
            printf(" 没有此选项,请重新选择!");
            getch();
            system("cls");
            return ;
        }
        fflush(stdin);
        switch(in)
        {
            case 1 : mofname(p_student);
                     break;
            case 2 : mofsex(p_student);
                     break;
            case 3 : mofbirth(p_student);
                     break;
            case 4 : mofadddr(p_student);
                     break;
            case 5 : mofpoto(p_student);
                     break;
            case 6 : mofdak(p_student);
                     break;
            case 7 : mofschool(p_student);
                     break;
            case 8 : return ;
              
            default: printf("没有此选项,请重新选择!");
                     break;
        }
    }while(1);
}   



/*************************个人信息录入*************************/
void inputinfo(struct allstudentinfo *p_student)
{
    int  count;
    char ch;
   
    system("cls");
    if((infofile=fopen(filename,"a+b"))==NULL)
    {
        printf("不能打开文件,请确认磁盘已满或c:\\学生个人信息登记.dat文件没有损坏");
        getch();
        exit(1);
    }
    rewind(infofile);                                                   //定位文件头开始读取
    for(count=0;fread(&p_student[count].student,sizeof(struct studentinfo),1,infofile)==1;count++)
        continue;
    printf("\n\n                    个人信息登记表\n");
    printf("\n请正确填写以下信息(系统目前不能支持中文,请用英文或拼音\n");
    printf("---------------------------------------------------------\n\n");
    printf("姓    名:");
    while(count<STUDENTMAX&&gets(p_student[count].student.name)!=NULL   //输入姓名
                          &&p_student[count].student.name[0]!='\0')
    {
        printf("\n性    别:");
        gets(p_student[count].student.sex);                             //输入性别
        printf("\n出生日期:");
        gets(p_student[count].student.birth);                           //输入出生日期
        printf("\n家庭住址:");
        gets(p_student[count].student.adddr);                           //输入家庭地址
        printf("\n联系电话:");
        gets(p_student[count].student.poto);                            //输入电话
        printf("\n邮证编码:");
        gets(p_student[count].student.dak);                             //输入邮证编码
        printf("\n所属院校:");
        gets(p_student[count].student.school);                          //输入所在院校
                                                                        //将信息写入文件
        fwrite(&p_student[count++].student,sizeof(struct studentinfo),1,infofile);
        
        printf("是否录入下一个学生信息(y/n)");
        ch=getch();
        if(ch=='y'||ch=='Y')
        {
            system("cls");
            printf("\n请输入下一个学生的个人信息\n");
            printf("\n姓    名:");
            continue;
        }                                                               //继续输入下一个学生信息
        else
        {
            printf("\n\n个人信息录入结束,返回!");
            fclose(infofile);                                           //关闭文件
            getch();                                                    //返回子菜单
            system("cls");
            return ;
        }
    }
    printf("输入有误,终止个人信息录信,返回!");
    getch();
    system("cls");
    return ;                                                            //返回
}

/***********************查询个人信息****************************/
void aboutinfo(struct allstudentinfo *p_student)
{
    int  i;
    int  count;                                                     //学生计数器
    char ch;
    char *temp=NULL;                                                //临时存储要查询的用户姓名
     
    system("cls");
    if((infofile=fopen(filename,"rb"))==NULL)
    {
        printf("不能打开文件,请确认磁盘已满或文件是否存在");
        getch();
        exit(1);
    }
    rewind(infofile);                                                //指向文件头
    for(count=0;fread(&p_student[count].student,sizeof(struct studentinfo),1,infofile)==1;count++)
    {
        continue;
    }
    fclose(infofile);                                                //关闭文件
    if(!count)
    {
        printf("找不到个人数据,请确认已经成功录入或文件是否存在!");
        getch();
        system("cls");
        return ;
    }
    temp=(char *)malloc(20*sizeof(char));                           //分配内存
    printf("请输入要查询的学生姓名:");
    while(gets(temp)!=NULL&&temp[0]!='\0')
    {
        for(i=0;i<count;i++)
        {
            if(!strcmp(temp,p_student[i].student.name))
            {
                system("cls");
                printf("以下是你要查询%s的个人信息\n",p_student[i].student.name);
                printf("\n                   个人信息查询表\n");
                printf("-----------------------------------------------------------------\n");
                printf("\n姓    名: %s\n",p_student[i].student.name);
                printf("\n性    别: %s\n",p_student[i].student.sex);
                printf("\n出生日期: %s\n",p_student[i].student.birth);
                printf("\n家庭住址: %s\n",p_student[i].student.adddr);
                printf("\n联系电话: %s\n",p_student[i].student.poto);
                printf("\n邮证编码: %s\n",p_student[i].student.dak);
                printf("\n所在院校: %s\n",p_student[i].student.school);
                printf("-----------------------------------------------------------------\n");
                break;
            }
        }
        free(temp);                                                         //释放空间
        printf("\n查询下一个学生的个人信息(y/n)");
        ch=getch();
        if(ch=='y'||ch=='Y')
        {
            system("cls");
            temp=(char *)malloc(20*sizeof(char));                                  //重新分配内存
            printf("请输入要查询的学生姓名:");
            continue;
        }
        else
        {
            printf("\n查询结束,返回!");
            getch();
            system("cls");
            return ;
        }
    }
    free(temp);                                                             //释放已经分配的内存空间
    printf("\n输入有误,请按任意键返回子菜单!");
    getch();
    system("cls");
}

  雨水冲不进窗来,在玻璃上痛哭。但它至少奋斗过。
2008-02-09 20:10
hangeng
Rank: 2
等 级:论坛游民
帖 子:424
专家分:39
注 册:2007-7-23
收藏
得分:0 
/****************************查询所有信息*******************************/
void allabout(struct allstudentinfo *p_student)
{
    int i;
    int count;
   
    system("cls");
    if((infofile=fopen(filename,"rb"))==NULL)
    {
        printf("不能打开文件,请确认文件是否存在或是否损坏!");
        getch();
        exit(1);
    }
    rewind(infofile);                                                      //定位到文件头
    for(count=0;fread(&p_student[count].student,sizeof(struct studentinfo),1,infofile)==1;count++)
    {
        continue;
    }
    fclose(infofile);                                                      //读完后关闭文件
    if(!count)
    {
        printf("不能读取数据,请确定文件是否存在或已经成功录入数据!");
        getch();
        system("cls");
        return ;                                                           //反回重新操作
    }
    printf("\n\t\t\t 学生个人信息查询表\n\n");
    printf("\t 以下是本系统所查询到的所有学生个人信息,如果表中找不到数据\n");
    printf(" 请确认是否已经成功录入本系统!\n");
    printf("----------------------------------------");
    printf("----------------------------------------\n");
    for(i=0;i<count;i++)
    {
        printf("您正在查看第[%d]个学生的个人信息\n",i+1);
        printf("\n姓    名: %s\n",p_student[i].student.name);
        printf("\n性    别: %s\n",p_student[i].student.sex);
        printf("\n出生日期: %s\n",p_student[i].student.birth);
        printf("\n家庭住址: %s\n",p_student[i].student.adddr);
        printf("\n联系电话: %s\n",p_student[i].student.poto);
        printf("\n邮证编码: %s\n",p_student[i].student.dak);
        printf("\n所在院校: %s\n",p_student[i].student.school);
        printf("------------------------------------");
        printf("------------------------------------\n");
        printf("请按任意键继续查看信息........!");
        getch();
        system("cls");  
    }
    printf("\n查询结束...");
    printf("请按任意键返回!");
    getch();
    system("cls");
    return ;
}
         
/****************************删除个人信息*******************************/
void delinfo(struct allstudentinfo *p_student)
{
    int  i;
    int  count;
    char ch;
    char *temp=NULL;                                                        //初始化临时数组
     
    system("cls");                                                          //清屏
    if((infofile=fopen(filename,"rb"))==NULL)
    {
        printf("不能打开文件,请确认磁盘已满或文件是否存在");
        getch();                                                            
        exit(1);
    }
    rewind(infofile);                                                       //指向文件头  
    for(count=0;fread(&p_student[count].student,sizeof(struct studentinfo),1,infofile)==1;count++)
    {
        continue;
    }
    fclose(infofile);                                                       //关闭文件
    if(!count)
    {
        printf("不能读取数据,请确认已经正确录入或数据是否存在");
        getch();
        return ;
    }
    temp=(char *)malloc(20*sizeof(char));                                   //分配内存
    printf("请输入你要删除的学生姓名:");
    while(gets(temp)!=NULL&&temp[0]!='\0')
    {
        for(i=0;i<count;i++)
        {
            if(!strcmp(temp,p_student[i].student.name))
            {
                system("cls");
                printf("\a\n\n\n\n\n\n\t\t 确定要删除%s的个人信息吗?(y/n)",p_student[i].student.name);
                ch=getch();
                if(ch=='n'||ch=='N')
                {
                    free(temp);
                    system("cls");
                    printf("\n\n\n\n\n\n\t\t     该操作已取消.请按任意键返回!");
                    getch();
                    system("cls");
                    return ;
                }
                for(;i<count;i++)
                {
                    p_student[i].student=p_student[i+1].student;
                }
                count--;                                                    //删除一个学生信息
                if((infofile=fopen(filename,"w+b"))==NULL)                  //重新打开文件更新
                {
                    free(temp);
                    printf("不能打开文件,请确认磁盘已满或文件是否存在");
                    getch();
                    exit(1);
                }
                for(i=0;i<count;i++)
                {                                                           //更新文件
                    if(fwrite(&p_student[i].student,sizeof(struct studentinfo),1,infofile)!=1)
                        break;
                }
                free(temp);                                                 //释放内存
                system("cls");                                                
                printf("\n\n\n\n\n\n\t\t        已成功删除该学生的个人信息.....\n");
                printf("\n\t\t确定要删除下一个学生个人信息(y/n)");
                ch=getch();
                if(ch=='n'||ch=='N')
                {
                    fclose(infofile);
                    system("cls");
                    return ;
                }
                else
                {
                    
                    system("cls");
                    temp=(char *)malloc(20*sizeof(char));                   //重新分配内存以删除下一个信息
                    printf("请输入你想要删除的学生姓名:");
                    break;
                }     
            }   
        }
        printf("找不到%s的个人信息.",temp);
        printf("请重新输入(y/n)");
        ch=getch();
        if(ch=='y'||ch=='Y')
        {
            free(temp);
            temp=(char *)malloc(sizeof(char));                              //重新分配
            system("cls");
            printf("请输入你要删除的学生姓名:");
            continue;
        }
        else
        {
            free(temp);
            system("cls");
            return ;
        }
    }
    free(temp);                                                            //释放内存
    printf("输入有误,请按任意键返回子菜单,重新选择");
    getch();
    system("cls");
}

/**********************修改用户姓名***************************/
void mofname(struct allstudentinfo *p_student)
{
    char ch;
    char *temp;
    char *newtemp;                                                      
    int  count;
    int  i;
     
    system("cls");
    count=datfile(p_student);                                             //处理文件                                                  
    if(!count)
    {
        printf("读取数据失败,请确认已成功录入或文件数据是否损害!");
        getch();
        return ;
    }
    newtemp=(char *)malloc(20*sizeof(char));                              //分配内存
    temp=   (char *)malloc(20*sizeof(char));                              //分配内存
    printf("请输入您要修改的学生姓名:");
    while(gets(temp)!=NULL&&temp[0]!='\0')
    {
        for(i=0;i<count;i++)
        {
            if(strcmp(temp,p_student[i].student.name))
            {
                continue;
            }
            else
            {
                printf("请您输入该学生的新姓名:");
                gets(newtemp);
                system("cls");
                printf("\a\n\n\n\n\t\t\t确定要把姓名为%s的学生修改为%s码?(y/n)",temp,newtemp);
                ch=getch();
                if(ch=='y'||ch=='Y')
                {
                    strcpy(p_student[i].student.name,newtemp);            //修改姓名
                    infofile=fopen(filename,"w+b");                       //重新写入文件
                    for(i=0;i<count;i++)
                    {
                        if(fwrite(&p_student[i].student,sizeof(struct studentinfo),1,infofile)==1)
                            continue;
                        else
                        {
                            fclose(infofile);
                            printf("修改失败,返回重新操作.....");
                            getch();
                            free(temp);
                            free(newtemp);
                            system("cls");
                            return ;
                        }
                           
                    }
                    fclose(infofile);
                    system("cls");
                    printf("\n\n\n\n\t\t\t已成功把%s修改为%s返回!",temp,newtemp);
                    getch();
                    free(temp);
                    free(newtemp);
                    system("cls");
                    return ;
                }
            }
        }
        printf("找不到%s的个人信息,返回重新操作!",temp);
        free(temp);
        free(newtemp);
        getch();
        system("cls");
        return ;
    }
    printf("\n\n\n\n\t\t\t输入有误,请返回重新操作!");
    getch();
    free(temp);
    free(newtemp);
    system("cls");
    return ;



}

  雨水冲不进窗来,在玻璃上痛哭。但它至少奋斗过。
2008-02-09 20:10
hangeng
Rank: 2
等 级:论坛游民
帖 子:424
专家分:39
注 册:2007-7-23
收藏
得分:0 
/************************修改个人性别*********************/
void mofsex(struct allstudentinfo *p_student)
{
    char *tempname;                                                     //要修改的学生的名字
    char *tempsex;                                                      //要修改的学生的性别
    char ch;
    int  count;
    int  i;
   
    system("cls");
    count=datfile(p_student);                                                         //处理文件
    if(!count)
    {
        printf("读取数据失败,请确认已成功录入数据或文件是否损坏!");
        getch();
        return ;
    }
   
    tempname=(char *)malloc(10*sizeof(char));                           //分配内存
    tempsex=(char *)malloc(10*sizeof(char));                            //分配内存
    printf("请输入要修改的学生姓名:");
    while(gets(tempname)!=NULL&&tempname[0]!='\0')
    {
        for(i=0;i<count;i++)
        {
            if(strcmp(tempname,p_student[i].student.name))
                continue;
            else
            {
                printf("请输入该学生的新性别:");
                gets(tempsex);
                system("cls");
                printf("\a\n\n\n\n\t\t\t确定要修改该学生的性别吗?(y/n)");
                ch=getch();
                if(ch=='y'||ch=='Y')
                {
                    strcpy(p_student[i].student.sex,tempsex);
                    infofile=fopen(filename,"w+b");
                    for(i=0;i<count;i++)
                    {
                        if(fwrite(&p_student[i].student,sizeof(struct studentinfo),1,infofile)==1)
                            continue;
                        else
                        {
                            fclose(infofile);
                            system("cls");
                            printf("\n\n\n\n\t\t\t修改失败,请返回.....");
                            getch();
                            free(tempname);
                            free(tempsex);
                            system("cls");
                            return ;
                        }
                    }
                    fclose(infofile);
                    system("cls");
                    printf("\n\n\n\n\t\t\t已成功修改%s的性别,返回!",tempname);
                    getch();
                    free(tempname);
                    free(tempsex);
                    system("cls");
                    return ;
                }
                printf("该操作已衩取消,返回.....");
                free(tempname);
                free(tempsex);
                getch();
                system("cls");
                return ;
            }
        }
        printf("找不到%s的个人信息,返回......",tempname);
        free(tempname);
        free(tempsex);
        getch();
        system("cls");
        return ;
    }
    printf("输入有误,请返回重新输入!");
    free(tempname);
    free(tempsex);
    getch();
    system("cls");
    return ;
}

/**************************修改出生日期***************************/
void mofbirth(struct allstudentinfo *p_student)
{
    char *tempname;
    char *tempbirth;
    char ch;
    int  i,count;
   
    system("cls");
    count=datfile(p_student);                                                         //处理文件
    if(!count)
    {
        printf("读取数据失败,请确认已成功录入或数据是否损坏!");
        getch();
        return ;
    }
   
    tempname=(char *)malloc(20*sizeof(char));
    tempbirth=(char *)malloc(20*sizeof(char));                                         //分配内存
    printf("请输入要修改的学生姓名:");
    while(gets(tempname)!=NULL&&tempname[0]!='\0')
    {
        for(i=0;i<count;i++)
        {
            if(strcmp(tempname,p_student[i].student.name))
                continue;
            else
            {
                printf("请重新输入该学生的出生日期:");
                gets(tempbirth);
                system("cls");
                printf("\a\n\n\n\n\t\t\t确定要修改%s的出生日期吗?(y/n)",tempname);
                ch=getch();
                if(ch=='y'||ch=='Y')
                {
                    strcpy(p_student[i].student.birth,tempbirth);
                    infofile=fopen(filename,"w+b");
                    for(i=0;i<count;i++)
                    {
                        if(fwrite(&p_student[i].student,sizeof(struct studentinfo),1,infofile)==1)
                            continue;
                        else
                        {
                            fclose(infofile);
                            free(tempname);
                            free(tempbirth);
                            system("cls");
                            printf("\n\n\n\n\t\t\t修改失败,返回......");
                            getch();
                            system("cls");
                            return ;
                        }
                    }
                    fclose(infofile);
                    system("cls");
                    printf("\n\n\n\n\t\t\t成功修改%s的出生日期,返回!,",tempname);
                    free(tempname);
                    free(tempbirth);
                    getch();
                    system("cls");
                    return ;
                }
                printf("\n\n\n\n\t\t\t该操作已被取消,返回!");
                free(tempname);
                free(tempbirth);
                getch();
                system("cls");
                return ;
            }
        }
        printf("\n\n\n\n\t\t\t找不到%s的个人信息,返回!",tempname);
        free(tempname);
        free(tempbirth);
        getch();
        system("cls");
        return ;
    }
    printf("输入有误,请返回重新选择!");
    free(tempname);
    free(tempbirth);
    getch();
    system("cls");
    return ;
}

/***********************修改家庭住址*********************/
void mofadddr(struct allstudentinfo *p_student)
{
    char *tempname;
    char *tempadddr;
    char ch;
    int  i,count;
   
    system("cls");
    count=datfile(p_student);                                                         //处理文件
    if(!count)
    {
        printf("读取数据失败,请确认已成功录入或数据是否损坏!");
        getch();
        return ;
    }
   
    tempname=(char *)malloc(20*sizeof(char));
    tempadddr=(char *)malloc(20*sizeof(char));                                         //分配内存
    printf("请输入要修改的学生姓名:");
    while(gets(tempname)!=NULL&&tempname[0]!='\0')
    {
        for(i=0;i<count;i++)
        {
            if(strcmp(tempname,p_student[i].student.name))
                continue;
            else
            {
                printf("请重新输入该学生的家庭住址:");
                gets(tempadddr);
                system("cls");
                printf("\a\n\n\n\n\t\t\t确定要修改%s的家庭住址吗?(y/n)",tempname);
                ch=getch();
                if(ch=='y'||ch=='Y')
                {
                    strcpy(p_student[i].student.adddr,tempadddr);
                    infofile=fopen(filename,"w+b");                                  //重新写入数据库
                    for(i=0;i<count;i++)
                    {
                        if(fwrite(&p_student[i].student,sizeof(struct studentinfo),1,infofile)==1)
                            continue;
                        else
                        {
                            fclose(infofile);
                            free(tempname);
                            free(tempadddr);
                            system("cls");
                            printf("\n\n\n\n\t\t\t修改失败,返回......!");
                            getch();
                            system("cls");
                            return ;
                        }
                    }
                    fclose(infofile);
                    system("cls");
                    printf("\n\n\n\n\t\t\t成功修改%s的家庭住址,返回......!,",tempname);
                    free(tempname);
                    free(tempadddr);
                    getch();
                    system("cls");
                    return ;
                }
                printf("\n\n\n\n\t\t\t该操作已被取消,返回.......!");
                free(tempname);
                free(tempadddr);
                getch();
                system("cls");
                return ;
            }
        }
        printf("\n\n\n\n\t\t\t找不到%s的个人信息,返回.......!",tempname);
        free(tempname);
        free(tempadddr);
        getch();
        system("cls");
        return ;
    }
    printf("输入有误,请返回重新选择.......!");
    free(tempname);
    free(tempadddr);
    getch();
    system("cls");
    return ;
}
/*****************************修改联系电话********************************/
void mofpoto(struct allstudentinfo *p_student)
{
    char *tempname;
    char *temppoto;
    char ch;
    int  i,count;
   
    system("cls");
    count=datfile(p_student);                                                         //处理文件
    if(!count)
    {
        printf("读取数据失败,请确认已成功录入或数据是否损坏!");
        getch();
        system("cls");
        return ;
    }
   
    tempname=(char *)malloc(20*sizeof(char));
    temppoto=(char *)malloc(20*sizeof(char));                                         //分配内存
    printf("请输入要修改的学生姓名:");
    while(gets(tempname)!=NULL&&tempname[0]!='\0')
    {
        for(i=0;i<count;i++)
        {
            if(strcmp(tempname,p_student[i].student.name))
                continue;
            else
            {
                printf("请重新输入该学生的联系电话:");
                gets(temppoto);
                system("cls");
                printf("\a\n\n\n\n\t\t\t确定要修改%s的联系电话吗?(y/n)",tempname);
                ch=getch();
                if(ch=='y'||ch=='Y')
                {
                    strcpy(p_student[i].student.poto,temppoto);
                    infofile=fopen(filename,"w+b");
                    for(i=0;i<count;i++)
                    {
                        if(fwrite(&p_student[i].student,sizeof(struct studentinfo),1,infofile)==1)
                            continue;
                        else
                        {
                            fclose(infofile);
                            free(tempname);
                            free(temppoto);
                            system("cls");
                            printf("\n\n\n\n\t\t\t修改失败,返回.......!");
                            getch();
                            system("cls");
                            return ;
                        }
                    }
                    fclose(infofile);
                    system("cls");
                    printf("\n\n\n\n\t\t\t成功修改%s的联系电话,返回.......!,",tempname);
                    free(tempname);
                    free(temppoto);
                    getch();
                    system("cls");
                    return ;
                }
                printf("\n\n\n\n\t\t\t该操作已被取消,返回.......!");
                free(tempname);
                free(temppoto);
                getch();
                system("cls");
                return ;
            }
        }
        printf("\n\n\n\n\t\t\t找不到%s的个人信息,返回.......!",tempname);
        free(tempname);
        free(temppoto);
        getch();
        system("cls");
        return ;
    }
    printf("输入有误,请返回重新选择.......!");
    free(tempname);
    free(temppoto);
    getch();
    system("cls");
    return ;
}
/**************************修改邮证编码*************************/
void mofdak(struct allstudentinfo *p_student)
{
    char *tempname;
    char *tempdak;
    char ch;
    int  i,count;
   
    system("cls");
    count=datfile(p_student);                                                         //处理文件
    if(!count)
    {
        printf("读取数据失败,请确认已成功录入或数据是否损坏!");
        getch();
        system("cls");
        return ;
    }
   
    tempname=(char *)malloc(20*sizeof(char));
    tempdak =(char *)malloc(20*sizeof(char));                                         //分配内存
    printf("请输入要修改的学生姓名:");
    while(gets(tempname)!=NULL&&tempname[0]!='\0')
    {
        for(i=0;i<count;i++)
        {
            if(strcmp(tempname,p_student[i].student.name))
                continue;
            else
            {
                printf("请重新输入该学生的邮证编码:");
                gets(tempdak);
                system("cls");
                printf("\a\n\n\n\n\t\t\t确定要修改%s的邮证编码吗?(y/n)",tempname);
                ch=getch();
                if(ch=='y'||ch=='Y')
                {
                    strcpy(p_student[i].student.dak,tempdak);
                    infofile=fopen(filename,"w+b");
                    for(i=0;i<count;i++)
                    {
                        if(fwrite(&p_student[i].student,sizeof(struct studentinfo),1,infofile)==1)
                            continue;
                        else
                        {
                            fclose(infofile);
                            free(tempname);
                            free(tempdak);
                            system("cls");
                            printf("\n\n\n\n\t\t\t修改失败,返回.......!");
                            getch();
                            system("cls");
                            return ;
                        }
                    }
                    fclose(infofile);
                    system("cls");
                    printf("\n\n\n\n\t\t\t成功修改%s的邮证编码,返回.......!",tempname);
                    free(tempname);
                    free(tempdak);
                    getch();
                    system("cls");
                    return ;
                }
                printf("\n\n\n\n\t\t\t该操作已取消,返回.......!");
                free(tempname);
                free(tempdak);
                getch();
                system("cls");
                return ;
            }
        }
        printf("\n\n\n\n\t\t\t找不到%s的个人信息,返回.......!",tempname);
        free(tempname);
        free(tempdak);
        getch();
        system("cls");
        return ;
    }
    printf("输入有误,请返回重新选择.......!");
    free(tempname);
    free(tempdak);
    getch();
    system("cls");
    return ;
}
/*************************修改所在院校******************************/
void mofschool(struct allstudentinfo *p_student)
{
    char *tempname;
    char *tempschool;
    char ch;
    int  i,count;
   
    system("cls");
    count=datfile(p_student);                                                            //文件处理
    if(!count)
    {
        printf("读取数据失败,请确认已成功录入或数据是否损坏!");
        getch();
        system("cls");
        return ;
    }
   
    tempname=(char *)malloc(20*sizeof(char));
    tempschool=(char *)malloc(20*sizeof(char));                                         //分配内存
    printf("请输入要修改的学生姓名:");
    while(gets(tempname)!=NULL&&tempname[0]!='\0')
    {
        for(i=0;i<count;i++)
        {
            if(strcmp(tempname,p_student[i].student.name))
                continue;
            else
            {
                printf("请重新输入该学生的所在院校:");
                gets(tempschool);
                system("cls");
                printf("\a\n\n\n\n\t\t\t确定要修改%s的所在院校吗?(y/n)",tempname);
                ch=getch();
                if(ch=='y'||ch=='Y')
                {
                    strcpy(p_student[i].student.school,tempschool);
                    infofile=fopen(filename,"w+b");
                    for(i=0;i<count;i++)
                    {
                        if(fwrite(&p_student[i].student,sizeof(struct studentinfo),1,infofile)==1)
                            continue;
                        else
                        {
                            fclose(infofile);
                            free(tempname);
                            free(tempschool);
                            system("cls");
                            printf("\n\n\n\n\t\t\t修改失败,返回.......!");
                            getch();
                            system("cls");
                            return ;
                        }
                    }
                    fclose(infofile);
                    system("cls");
                    printf("\n\n\n\n\t\t\t成功修改%s的所在院校,返回.......!",tempname);
                    free(tempname);
                    free(tempschool);
                    getch();
                    system("cls");
                    return ;
                }
                printf("\n\n\n\n\t\t\t该操作已取消,返回.......!");
                free(tempname);
                free(tempschool);
                getch();
                system("cls");
                return ;
            }
        }
        printf("\n\n\n\n\t\t\t找不到%s的个人信息,返回.......!",tempname);
        free(tempname);
        free(tempschool);
        getch();
        system("cls");
        return ;
    }
    printf("输入有误,请返回重新选择.......!");
    free(tempname);
    free(tempschool);
    getch();
    system("cls");
    return ;
}

/**************************修改个人信息的主要操作文件**************************/
int datfile(struct allstudentinfo *p_student)
{
    int  count;
   
    system("cls");
    if((infofile=fopen(filename,"rb"))==NULL)
    {
        printf("不能找开文件,请确认磁盘已满或文件是否存在!");
        getch();
        exit(1);
    }
    rewind(infofile);                                                //指向文件头读取数据                                                   
    for(count=0;fread(&p_student[count].student,sizeof(struct studentinfo),1,infofile)==1;count++)
    {
        continue;
    }
    fclose(infofile);
   
    return count;                                                     //返回读到的结构块数
}




/***************************学生个人成绩管理***********************************/
//       此子系统目前只支持学生的个人成绩的录入,修改,删除,查询等功能
//       如没有在个人信息管理系统中登记个人信息的,可能会造成无法查询
//       访问等错误的提示,请尽量在个人信息管理系统中成功登记了关于学生
//       个人的相关信息之后再使用本系统。
/******************************************************************************/
void sorcmeun(struct allstudentinfo *p_student)
{
    int  in;
    char ch;
   
    do
    {
        system("cls");
        printf("\n\n\n\n");
        printf("\t\t  —————————————————————\n");
        printf("\t\t |           学生个人成绩管理             |\n");
        printf("\t\t |————————————————————|\n");
        printf("\t\t |     1.  录入学生个人成绩      |\n");
        printf("\t\t |                    |\n");
        printf("\t\t |    2. 修改学生个人成绩      |\n");
        printf("\t\t |                    |\n");
        printf("\t\t |    3. 查询学生个人成绩      |\n");
        printf("\t\t |                    |\n");
        printf("\t\t |    4. 浏览所有学生的成绩     |\n");
        printf("\t\t |                    |\n");
        printf("\t\t |    5. 删除学生成绩        |\n");
        printf("\t\t |                    |\n");
        printf("\t\t |    6. 退出成绩管理系统      |\n");
        printf("\t\t |————————————————————|\n");
        printf("\t\t  请您正确选择: ");
        if(!(scanf("%d",&in)==1))
        {
            while((ch=getchar())!='\n')
                putchar(ch);
            printf(" 没有此选项,请正确选择!");
            getch();
            continue;
        }
        fflush(stdin);
        switch(in)
        {
            case 1 : inputsorc(p_student);                                  //录入成绩
                     break;
            case 2 : mofsorc  (p_student);                                  //修改成绩
                     break;
            case 3 : seasorc  (p_student);                                  //查询个人成绩
                     break;
            case 4 : seaallsorc(p_student);                                 //浏览所有学生成绩
                     break;
            case 5 : delsorc  (p_student);                                  //删除学生成绩
                     break;
            case 6 : return ;                                               //返回
            
            default: printf("没有此选项,请正确选择!");
                     break;
        }
    }while(1);
}

/************************个人成绩录入*************************/
void inputsorc(struct allstudentinfo *p_student)
{
    int  i,count,countinfo;
    char *tempname,ch;
   
    system("cls");
    if((sorcfile=fopen(filename1,"a+b"))==NULL)                              //打开或新建成绩数据文件
    {
        printf("不能找开文件,请确认磁盘已满或文件是否存在");
        getch();
        exit(1);
    }
    rewind(sorcfile);                                                       //定位文件头
    for(count=0;fread(&p_student[count].student1,sizeof(struct studentsorc),1,sorcfile)==1;count++)
    {
        continue;
    }
    tempname=(char *)malloc(20*sizeof(char));                               //分配内存
    printf("请输入第%d学生的姓名:",count+1);
    while(count<STUDENTMAX&&gets(tempname)!=NULL&&tempname[0]!='\0')
    {
        strcpy(p_student[count].student1.name,tempname);      
        printf("请输入该学生的学号:");
        scanf("%d",&p_student[count].student1.ID);                         //输入学号
        fflush(stdin);                                                     //刷新绶冲
        printf("请输入该学生的6科成绩\n");
        printf("——————————————————————————————\n");
        printf("\n语文: ");
        scanf("%f",&p_student[count].student1.sorc[0]);
        fflush(stdin);
        printf("\n数学: ");
        scanf("%f",&p_student[count].student1.sorc[1]);
        fflush(stdin);
        printf("\n英语: ");
        scanf("%f",&p_student[count].student1.sorc[2]);
        fflush(stdin);
        printf("\n化学: ");
        scanf("%f",&p_student[count].student1.sorc[3]);
        fflush(stdin);
        printf("\n物理: ");
        scanf("%f",&p_student[count].student1.sorc[4]);
        fflush(stdin);
        printf("\n计算机应用与基础: ");
        scanf("%f",&p_student[count].student1.sorc[5]);
        fflush(stdin);
        printf("——————————————————————————————\n");
        fwrite(&p_student[count++].student1,sizeof(struct studentsorc),1,sorcfile);
                                                                          //写入文件
        printf("确定要继续输入下一个学生的成绩吗(y/n)");
        ch=getch();
        if(ch=='y'||ch=='Y')
        {
            system("cls");
            free(tempname);                                               //释放内存重新分配
            tempname=(char *)malloc(20*sizeof(char));
            printf("请输入第%d个学生的姓名:",count+1);
            continue;
        }
        else
        {
            system("cls");
            free(tempname);
            fclose(sorcfile);
            return ;
        }
    }
    printf("输入有误请返回重新选择操作.......!");
    free(tempname);
    fclose(sorcfile);
    getch();
    system("cls");
    return ;
}

/************************修改学生成绩****************************/
void mofsorc(struct allstudentinfo *p_student)
{
    int i,j,k,count;
    float sorc;
    char ch;
    char *tempname;
   
    count=sorcdatfile(p_student);
    if(!count)
    {
        printf("读取数据失败,请确认已成功录入或文件是否损害");
        getch();
        system("cls");
        return ;
    }
    tempname=(char *)malloc(20*sizeof(char));                            //分配内存
    printf("请输入要修改成绩的学生姓名:");
    while(gets(tempname)!=NULL&&tempname[0]!='\0')
    {
        for(i=0;i<count;i++)
        {
            if(strcmp(tempname,p_student[i].student1.name))
            {
                continue;   
            }
            else
            {
                printf("请选择要修改的科目成绩:1.语文 2.英语 3.数学 4.化学 5.物理 6.计算机应用与基础\n");
                scanf("%d",&j);
                fflush(stdin);
                if(j==1)
                {
                    printf("请重新输入%s的语文成绩: ",tempname);
                    scanf("%f",&sorc);
                    p_student[i].student1.sorc[0]=sorc;
                    fflush(stdin);
                    sorcfile=fopen(filename1,"w+b");                    //把修改后的重新写入文件
                    for(k=0;k<count;k++)
                    {
                        if(fwrite(&p_student[k].student1,sizeof(struct studentsorc),1,sorcfile)!=1)
                        {
                            free(tempname);
                            fclose(sorcfile);                          //写入失败关闭文件
                            printf("修改失败,返回.......!");
                            getch();
                            system("cls");
                            return ;
                        }
                    }
                    free(tempname);
                    fclose(sorcfile);
                    printf("修改成功,返回!.......");
                    getch();
                    system("cls");
                    return ;
                }
                else if(j==2)
                {
                    printf("请重新输入%s的英语成绩: ",tempname);
                    scanf("%f",&sorc);
                    p_student[i].student1.sorc[2]=sorc;
                    fflush(stdin);
                    sorcfile=fopen(filename1,"w+b");                   //把修改后的重新写入文件
                    for(k=0;k<count;k++)
                    {
                        if(fwrite(&p_student[k].student1,sizeof(struct studentsorc),1,sorcfile)!=1)
                        {
                            free(tempname);
                            fclose(sorcfile);                         //写入失败关闭文件
                            printf("修改失败,返回.......!");
                            getch();
                            system("cls");
                            return ;
                        }
                    }
                    free(tempname);
                    fclose(sorcfile);
                    printf("修改成功,返回.......!");
                    getch();
                    system("cls");
                    return ;
                }
                else if(j==3)
                {
                    printf("请重新输入%s的数学成绩: ",tempname);
                    scanf("%f",&sorc);
                    p_student[i].student1.sorc[1]=sorc;
                    fflush(stdin);
                    sorcfile=fopen(filename1,"w+b");                    //把修改后的重新写入文件
                    for(k=0;k<count;k++)
                    {
                        if(fwrite(&p_student[k].student1,sizeof(struct studentsorc),1,sorcfile)!=1)
                        {
                            free(tempname);
                            fclose(sorcfile);                          //写入失败关闭文件
                            printf("修改失败,返回.......!");
                            getch();
                            system("cls");
                            return ;
                        }
                    }
                    free(tempname);
                    fclose(sorcfile);
                    printf("修改成功,返回.......!");
                    getch();
                    system("cls");
                   return ;
                }
                else if(j==4)
                {
                    printf("请重新输入%s的化学成绩: ",tempname);
                    scanf("%f",&sorc);
                    p_student[i].student1.sorc[4]=sorc;
                    fflush(stdin);
                    sorcfile=fopen(filename1,"w+b");                  //把修改后的重新写入文件
                    for(k=0;k<count;k++)
                    {
                        if(fwrite(&p_student[k].student1,sizeof(struct studentsorc),1,sorcfile)!=1)
                        {
                            free(tempname);
                            fclose(sorcfile);                         //写入失败关闭文件
                            printf("修改失败,返回.......!");
                            getch();
                            system("cls");
                            return ;
                        }
                    }
                    free(tempname);
                    fclose(sorcfile);
                    printf("修改成功,返回.......!");
                    getch();
                    system("cls");
                    return ;
                }
                else if(j==5)
                {
                    printf("请重新输入%s的物理成绩: ",tempname);
                    scanf("%f",&sorc);
                    p_student[i].student1.sorc[4]=sorc;
                    fflush(stdin);
                    sorcfile=fopen(filename1,"w+b");                  //把修改后的重新写入文件
                    for(k=0;k<count;k++)
                    {
                        if(fwrite(&p_student[k].student1,sizeof(struct studentsorc),1,sorcfile)!=1)
                        {
                            free(tempname);
                            fclose(sorcfile);                         //写入失败关闭文件
                            printf("修改失败,返回.......!");
                            getch();
                            system("cls");
                            return ;
                        }
                    }
                    free(tempname);
                    fclose(sorcfile);
                    printf("修改成功,返回.......!");
                    getch();
                    system("cls");
                    return ;
                }
                else if(j==6)
                {
                    printf("请重新输入%s的计算机应用与基础成绩: ",tempname);
                    scanf("%f",&sorc);
                    p_student[i].student1.sorc[5]=sorc;
                    fflush(stdin);
                    sorcfile=fopen(filename1,"w+b");                   //把修改后的重新写入文件
                    for(k=0;k<count;k++)
                    {
                        if(fwrite(&p_student[k].student1,sizeof(struct studentsorc),1,sorcfile)!=1)
                        {
                            free(tempname);
                            fclose(sorcfile);                         //写入失败关闭文件
                            printf("修改失败,返回.......!");
                            getch();
                            system("cls");
                            return ;
                        }
                    }
                    free(tempname);
                    fclose(sorcfile);
                    printf("修改成功,返回.......!");
                    getch();
                    system("cls");
                    return ;
                }
                else
                {
                    printf("没有此科目,返回.......!");
                    free(tempname);
                    getch();
                    system("cls");
                    return ;
                }
            }
        }
        printf("没有找到%s的学习成绩,返回.......!",tempname);
        free(tempname);
        getch();
        system("cls");
        return ;   
    }
    printf("输入有误,返回.......!");
    free(tempname);
    getch();
    system("cls");
    return ;

}
/***************************查询学生个人成绩****************************/
void seasorc(struct allstudentinfo *p_student)
{
    char *tempname;
    int  tempID,stuID;
    int  i,j,count;
    float sum=0.0,aver;
   
    count=sorcdatfile(p_student);
    if(!count)
    {
        printf("读取数据失败,请确认数据是否存在或文件是否损害");
        getch();
        system("cls");
        return ;
    }
    printf("请选择要操作的类形:\n");
    printf("1.按姓名查找      2.按学号查找\n");
    scanf("%d",&tempID);
    fflush(stdin);
    if(tempID==1)                                                             //按姓名查询
    {
        tempname=(char *)malloc(20*sizeof(char));
        printf("请输入该学生的姓名:");
        while(gets(tempname)!=NULL&&tempname[0]!='\0')
        {
            for(i=0;i<count;i++)
            {
                if(strcmp(tempname,p_student[i].student1.name))
                {
                    continue;
                }
                else
                {     
                    for(j=0;j<6;j++)
                    {
                        sum+=p_student[i].student1.sorc[j];                   //计算总分
                    }
                    aver=sum/6.0;                                             //计算平均分
                    printf("%s的学生成绩表\n",tempname);
                    printf("——————————————————————————\n");
                    printf("\n学号:        %d\n",p_student[i].student1.ID);
                    printf("\n姓名: %s\n",p_student[i].student1.name);
                    printf("\n语文: %.2f\n",p_student[i].student1.sorc[0]);
                    printf("\n数学: %.2f\n",p_student[i].student1.sorc[1]);
                    printf("\n英语: %.2f\n",p_student[i].student1.sorc[2]);
                    printf("\n化学: %.2f\n",p_student[i].student1.sorc[3]);
                    printf("\n物理: %.2f\n",p_student[i].student1.sorc[4]);
                    printf("\n计算机应用与基础: %.2f\n",p_student[i].student1.sorc[5]);
                    printf("\n总分: %.2f\n",sum);
                    printf("\n平均分: %.2f\n",aver);
                    printf("——————————————————————————\n");
                    printf("查询完毕,按任意键返回!");
                    free(tempname);
                    getch();
                    system("cls");
                    return ;
                 }  
            }   
            printf("找不到该学生的成绩,返回.......!");
            free(tempname);
            getch();
            system("cls");
            return ;
        }
        printf("输入有误,返回.......!");
        free(tempname);
        getch();
        system("cls");
        return ;
    }
    else if(tempID==2)                                                    //按学号查询
    {
        printf("请输入该学生的ID学号:");
        scanf("%d",&stuID);
        fflush(stdin);
        for(i=0;i<count;i++)
        {
            if(stuID!=p_student[i].student1.ID)
            {
                continue;
            }
            else
            {
                for(j=0;j<6;j++)
                {
                     sum+=p_student[i].student1.sorc[j];                  //计算总分
                }
                aver=sum/6.0;                                             //计算平均分
                printf("学号为%d的学生成绩表\n",stuID);
                printf("——————————————————————————\n");
                printf("\n学号:        %d\n",p_student[i].student1.ID);
                printf("\n姓名: %s\n",p_student[i].student1.name);
                printf("\n语文: %.2f\n",p_student[i].student1.sorc[0]);
                printf("\n数学: %.2f\n",p_student[i].student1.sorc[1]);
                printf("\n英语: %.2f\n",p_student[i].student1.sorc[2]);
                printf("\n化学: %.2f\n",p_student[i].student1.sorc[3]);
                printf("\n物理: %.2f\n",p_student[i].student1.sorc[4]);
                printf("\n计算机应用与基础: %.2f\n",p_student[i].student1.sorc[5]);
                printf("\n总分: %.2f\n",sum);
                printf("\n平均分: %.2f\n",aver);
                printf("——————————————————————————\n");
                printf("查询完毕,按任意键返回.......!");
                getch();
                system("cls");
                return ;
             }
        }
        printf("没有找到该学号的成绩,返回.......!");
        getch();
        system("cls");
        return ;
    }
    printf("没有此选择,返回.......!");
    getch();
    system("cls");
    return ;
}

/******************************浏览所有学生的成绩*********************************/
void seaallsorc(struct allstudentinfo *p_student)
{
    int i,j,count;
    float aver,sum=0.0f;
   
    count=sorcdatfile(p_student);
    if(!count)
    {
        printf("读取数据失败,请确认已成功录入或文件是否损害!");
        getch();
        return ;
    }
    printf("\n\t\t\t学生成绩表\n");
    for(i=0;i<count;i++)
    {
        sum=aver=0.0;                                                       //重新初始化,计算下一次
        for(j=0;j<6;j++)
        {
            sum+=p_student[i].student1.sorc[j];                             //计算总分                  
        }
        aver=sum/6.0;                                                       //计算平均分
        printf("——————————————————————————————————\n");   
        printf("学号:       %d\n",p_student[i].student1.ID);
        printf("姓名:      %s\n",p_student[i].student1.name);
        printf("语文成绩: %.2f\n",p_student[i].student1.sorc[0]);
        printf("数学成绩: %.2f\n",p_student[i].student1.sorc[1]);
        printf("英语成绩: %.2f\n",p_student[i].student1.sorc[2]);
        printf("化学成绩: %.2f\n",p_student[i].student1.sorc[3]);
        printf("物理成绩: %.2f\n",p_student[i].student1.sorc[4]);
        printf("计算机成绩: %.2f\n",p_student[i].student1.sorc[5]);
        printf("总分成绩: %.2f\n",sum);
        printf("平均分成绩: %.2f\n",aver);
        printf("————————————————————————————————\n");
        printf("请按任意键继续浏览.......!");
        getch();
    }
    printf("浏览完毕,请返回.......!");
    getch();
    system("cls");
    return ;
}
/************************删除学生成绩******************************/
void delsorc(struct allstudentinfo *p_student)
{
    int in,stuID;
    int i,count;
    char ch;
    char *tempname;
   
    count=sorcdatfile(p_student);
    if(!count)
    {
        printf("读取数据失败!请确认已成功录入功或文件是否损害!");
        getch();
        system("cls");
        return ;
    }
    printf("请选择你操作的选项: 1. 按姓名查找删除   2. 按学号查找删除");
    scanf("%d",&in);
    fflush(stdin);
    if(in==1)
    {
        tempname=(char *)malloc(20*sizeof(char));
        printf("请输入你要删除的学生姓名: ");
        gets(tempname);
        for(i=0;i<count;i++)
        {
            if(strcmp(tempname,p_student[i].student1.name))
                continue;
            else
            {
                for(;i<count;i++)
                {
                    p_student[i].student1=p_student[i+1].student1;
                }
                --count;                                               //成绩减1
                sorcfile=fopen(filename1,"w+b");
                for(i=0;i<count;i++)
                {
                    if(fwrite(&p_student[i].student1,sizeof(struct studentsorc),1,sorcfile)==1)
                        continue;
                    else
                    {
                        printf("删除失败...!");
                        free(tempname);
                        fclose(sorcfile);
                        getch();
                        system("cls");
                        return ;
                    }
                }
                printf("删除成功...!");
                free(tempname);
                fclose(sorcfile);
                getch();
                system("cls");
                return ;
            }
        }
        printf("找不到该学生,返回...!");
        free(tempname);
        getch();
        system("cls");
        return ;
    }
    else if(in==2)
    {
        printf("请输入你要删除的学生学号: ");
        scanf("%d",&stuID);
        fflush(stdin);
        for(i=0;i<count;i++)
        {
            if(stuID!=p_student[i].student1.ID)
                continue;
            else
            {
                for(;i<count;i++)
                {
                    p_student[i].student1=p_student[i+1].student1;
                }
                --count;                                               //成绩减1
                sorcfile=fopen(filename1,"w+b");
                for(i=0;i<count;i++)
                {
                    if(fwrite(&p_student[i].student1,sizeof(struct studentsorc),1,sorcfile)==1)
                        continue;
                    else
                    {
                        printf("删除失败...!");
                        fclose(sorcfile);
                        getch();
                        system("cls");
                        return ;
                    }
                }
                printf("删除成功...!");
                fclose(sorcfile);
                getch();
                system("cls");
                return ;
            }
        }
        printf("找不到该学生,返回...!");
        getch();
        system("cls");
        return ;
    }
    printf("输入有误,返回...!");
    getch();
    system("cls");
    return ;
}
/**********************成绩数据文件***************************/
int sorcdatfile(struct allstudentinfo *p_student)
{
    int  count;
   
    system("cls");
    if((sorcfile=fopen(filename1,"rb"))==NULL)
    {
        printf("不能找开文件,请确认磁盘已满或文件是否存在!");
        getch();
        exit(1);
    }
    rewind(sorcfile);                                                //指向文件头读取数据                                                   
    for(count=0;fread(&p_student[count].student1,sizeof(struct studentsorc),1,sorcfile)==1;count++)
    {
        continue;
    }
    fclose(sorcfile);
   
    return count;                                                     //返回读到的结构块数
}

  雨水冲不进窗来,在玻璃上痛哭。但它至少奋斗过。
2008-02-09 20:11
hangeng
Rank: 2
等 级:论坛游民
帖 子:424
专家分:39
注 册:2007-7-23
收藏
得分:0 
/*****************************系统帮助信息*******************************/

void systemhelp()
{
    system("cls");
    printf("\n\n\n\t\t\t系统消息\n");
    printf("\t——————————————————————————————\n");
    printf("\t    本系统目前不去持汉字录入,请使用英语,拼音或其它助记方式录入\n");
    printf("\t为了能正常使用本系统,请先使用个人信息管理系统把学生的个人信息录\n");
    printf("\t入做好学籍登记再使用成绩管理系统来记录成绩,如要使用修改和删除功\n");
    printf("\t能请谨慎使用,或先将资料做好备份以免因系统出错造成数据丢失!\n");
    printf("\t——————————————————————————————\n");
    printf("                                             开发者:天涯      \n");
    printf("                                             开发时间:2008-01-23\n");
    getch();
    system("cls");
    return ;
}

  雨水冲不进窗来,在玻璃上痛哭。但它至少奋斗过。
2008-02-09 20:11
快速回复:分享:我用c写的简单学生管理系统
数据加载中...
 
   



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

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