| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1074 人关注过本帖
标题:求助~学生管理系统
只看楼主 加入收藏
zdoublehang
Rank: 1
等 级:新手上路
帖 子:90
专家分:3
注 册:2010-5-27
结帖率:90.91%
收藏
已结贴  问题点数:20 回复次数:14 
求助~学生管理系统
求助啊 ~~~ 还有两个问题....
恳请斧正!!!!!!!!!!!!

第一   数据输出时 最后一个数据输出两次  
第二   修改记录的 那块 有问题   

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <process.h>
struct person
{
    char name[15];
    char st_num[15];
    char sex[5];
    char born_ym[15];
    char major[15];
    char class_num[15];
    char address[20];
    char hostelnum[15];
};

FILE *fp;

void creat();//创建一个文件用来存放数据
void output();/*输出数据*/
void _1search();//查找某一特定学生
void _2search();
void modify();
void append();//添加一个学生

void main()
{
    char code_source[20]="nokia";
    char code[20];
    printf("\n\n\n\n");
    printf("\t\t\t学生管理系统Loading...\n\n\n\n\n\n");
    printf("\t\t\t   输入密码进入:");
    scanf("%s",code);
    if(!strcmp("code",code_source))
        {
    int m;
  
    creat();   
    while(1)
    {
                printf("\n\n\n");
                printf("\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                printf("\n\n\n\n");
                printf(" \t\t\t|-----------------------------|\n");
        printf("\n\t\t\t\\\t数据添加, 请按1      \/");
         printf("\n\t\t\t\\\t姓名查找,请按2      \/");
        printf("\n\t\t\t\\\t学号查找,请按3      \/");
        printf("\n\t\t\t\\\t数据修改,请按4      \/");
        printf("\n\t\t\t\\\t数据输出,请按5      \/");
        printf("\n\t\t\t\\\t程序退出,请按0      \/\n");
                printf(" \t\t\t|-----------------------------|\n");
        scanf("%d",&m);
        if(m>=0&&m<=5)
        {
            switch(m)
            {
            case 1: append();
                    break;
            case 2: _1search();
                    break;
                        case 3: _2search();
                    break;
                        case 4: modify();
                    break;
            case 5: output();
                    break;
            case 0: exit(0);
            }
            
         printf("\n\n操作完毕,请再次选择!");
         }
        else
            printf("\n\n选择错误,请再次选择!");
    }
        }
}


void creat()
{

    if((fp=fopen("student.txt","a"))==NULL)
    {
        printf("\n不能建立学生信息管理系统!");
        exit(0);
    }
        printf(" |****************************************************************************|\n");
    printf("\t\t\t\t学生管理系统\n\n\n\n\t\t\t欢迎使用,请您选择操作    O(∩_∩)O~\n");
        printf(" |****************************************************************************|\n");
    fclose(fp);
}

void output()
{
struct person one;
if((fp=fopen("student.txt","r"))==NULL)
    {
        printf("\n未打开学生信息管理系统!");
        exit(0);
    }

        printf("\n\n%20s\n","学生信息管理系统");
        printf("\n");
    printf("\n");
    printf("\n\n姓名      学号      性别      出生年月     专业      班级      家庭地址      宿舍电话\n");
while(!feof(fp))
   {
      fscanf(fp,"%s%s%s%s%s%s%s%s",one.name,one.st_num,one.sex,one.born_ym,one.major,one.class_num,one.address,one.hostelnum);
      printf("%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s\n",one.name,one.st_num,one.sex,one.born_ym,one.major,one.class_num,one.address,one.hostelnum);
   }
   fclose(fp);
}

void append()
{
    struct person one;

    if((fp=fopen("student.txt","a"))==NULL)
    {
        printf("\n不能建立学生信息管理系统!");
        exit(0);
    }
    printf("\n请输入姓名、学号、性别、出生年月、专业、班级、家庭地址、宿舍电话(以0结束)\n");
    scanf("%s",one.name);
    while(strcmp(one.name,"0"))
    {
        scanf("%s%s%s%s%s%s%s",one.st_num,one.sex,one.born_ym,one.major,one.class_num,one.address,one.hostelnum);
        fprintf(fp,"%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s\n",one.name,one.st_num,one.sex,one.born_ym,one.major,one.class_num,one.address,one.hostelnum);
        scanf("%s",one.name);
    }
    fclose(fp);
    system("cls");
   
}

void _1search()
{  
    int k=0;
    char namekey[15];
    struct person one;

    printf("\n请输入姓名:");
    scanf("%s",namekey);

    if((fp=fopen("student.txt","rb"))==NULL)
    {  
        printf("\n不能建立学生信息管理系统");
        exit(0);
    }
    rewind(fp);
    while(!feof(fp))
    {  
        fscanf(fp,"%s%s%s%s%s%s%s%s",one.name,one.st_num,one.sex,one.born_ym,one.major,one.class_num,one.address,one.hostelnum);
        if(!strcmp(namekey,one.name))
        {
            printf("\n\n已查到,记录为:");
            printf("\n\n姓名      学号      性别      出生年月     专业      班级      家庭地址      宿舍电话\n");
            printf("%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s\n",one.name,one.st_num,one.sex,one.born_ym,one.major,one.class_num,one.address,one.hostelnum);
            k=1;// 查找到得标志量
        }
    }
    if(!k)  
        printf("\n\n对不起,管理系统中没有此人的记录。");
    fclose(fp);
}
/*定义按学号查询学生学籍管理系统的函数*/
void _2search()
{  
    int k=0;
    char numkey[15];
    struct person one;

    printf("\n请输入学号:");
    scanf("%s",numkey);

    if((fp=fopen("student.txt","rb"))==NULL)
    {  
        printf("\n不能建立学生信息管理系统");
        exit(0);
    }
    rewind(fp);
    while(!feof(fp))
    {  
        fscanf(fp,"%s%s%s%s%s%s%s%s",one.name,one.st_num,one.sex,one.born_ym,one.major,one.class_num,one.address,one.hostelnum);
        if(!strcmp(numkey,one.st_num))
        {
            printf("\n\n已查到,记录为:");
            printf("\n\n姓名      学号      性别      出生年月     专业      班级      家庭地址      宿舍电话\n");
            printf("%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10s\n",one.name,one.st_num,one.sex,one.born_ym,one.major,one.class_num,one.address,one.hostelnum);
            k=1;// 查找到得标志量
        }
    }
    if(!k)  
        printf("\n\n对不起,管理系统中没有此人的记录。");
    fclose(fp);
}
void modify()
{
    int k=0;
    int m=0;
    long offset;
    char numkey[15];
    struct person one ;
    printf("\n请输入要修改学生的学号:");
    scanf("%s",numkey);

    if((fp=fopen("student.txt","r+"))==NULL)
    {
        printf("\n不能建立学生信息管理系统");
        exit(0);
    }
    rewind(fp);
    while(!feof(fp))
    {    offset=ftell(fp);
        fscanf(fp,"%s%s%s%s%s%s%s%s",one.name,one.st_num,one.sex,one.born_ym,one.major,one.class_num,one.address,one.hostelnum);
        if(!strcmp(numkey,one.st_num))
        {
            printf("\n\n已查到,记录为:");
            printf("\n\n姓名      学号      性别      出生年月     专业      班级      家庭地址      宿舍电话\n");
            printf("%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10sn",one.name,one.st_num,one.sex,one.born_ym,one.major,one.class_num,one.address,one.hostelnum);
            k=1;
        }
    }

    if(k)
    {
aaaqqq源代码.rar (1.91 KB)


            printf("\n请输入新学生记录:\n");
            scanf("%s%s%s%s%s%s%s",one.st_num,one.sex,one.born_ym,one.major,one.class_num,one.address,one.hostelnum);
            fseek(fp,offset,SEEK_SET);
            fprintf(fp,"%-10s%-10s%-10s%-10s%-10s%-10s%-10s%-10sn",one.name,one.st_num,one.sex,one.born_ym,one.major,one.class_num,one.address,one.hostelnum);
    }
    else
        printf("\n对不起,没有记录。");
    fclose(fp);
    system("cls");
}
搜索更多相关主题的帖子: 管理 学生 系统 
2010-06-03 14:29
xjy080
Rank: 2
等 级:论坛游民
帖 子:55
专家分:78
注 册:2008-9-15
收藏
得分:10 
可以具体的说下吗
2010-06-03 15:20
zdoublehang
Rank: 1
等 级:新手上路
帖 子:90
专家分:3
注 册:2010-5-27
收藏
得分:0 
回复 楼主 zdoublehang
就是  输入几个人的数据之后   5输出,最后一个人的数据显示两次


4修改 上也有问题
2010-06-03 18:38
mymirror
Rank: 2
等 级:论坛游民
帖 子:9
专家分:10
注 册:2010-5-28
收藏
得分:10 
看了一下 先下了再仔细看下
2010-06-03 19:03
zdoublehang
Rank: 1
等 级:新手上路
帖 子:90
专家分:3
注 册:2010-5-27
收藏
得分:0 
回复 4楼 mymirror
帮帮忙啊~~~~~~~~~~                           我不太懂了
2010-06-03 21:16
zdoublehang
Rank: 1
等 级:新手上路
帖 子:90
专家分:3
注 册:2010-5-27
收藏
得分:0 
求助啊~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2010-06-04 22:19
zdoublehang
Rank: 1
等 级:新手上路
帖 子:90
专家分:3
注 册:2010-5-27
收藏
得分:0 
~~~~(>_<)~~~~
2010-06-04 22:51
zdoublehang
Rank: 1
等 级:新手上路
帖 子:90
专家分:3
注 册:2010-5-27
收藏
得分:0 
2010-06-04 22:55
zdoublehang
Rank: 1
等 级:新手上路
帖 子:90
专家分:3
注 册:2010-5-27
收藏
得分:0 
回复 2楼 xjy080
~~~~(>_<)~~~~
2010-06-04 23:04
zdoublehang
Rank: 1
等 级:新手上路
帖 子:90
专家分:3
注 册:2010-5-27
收藏
得分:0 
.0.0.0.0.0.0.0.0.0.0.0.
2010-06-05 12:30
快速回复:求助~学生管理系统
数据加载中...
 
   



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

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