| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1024 人关注过本帖
标题:我大作业运行不了
取消只看楼主 加入收藏
Rhyme_119
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2018-1-12
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
我大作业运行不了
[local]1[/local]
//课程设计:题目学生信息管理程序

/*
基本要求:
1.要求实现学生信息的查找、添加、删除、修改、浏览、保存、从文件读取、查看奖学金信息8个功能,每个功能模块均能实现随时从模块中退出,而且可以选择不同的方式实现所需功能,从而完成一个学生管理系统所需功能。
2.要使用结构体来实现对学生信息的存储。
3.可使用链表或数组来实现对学生信息的查找、添加、删除、修改、浏览等操作。
4.使用文件完成数据的存储与读取,要求每次运行某个功能模块时将数据读入结构体中,并给用户提供保存选项,可以将结构体中的数据保存在文件中。
5.系统制作完成后应实现类似下图所示界面。
*/

//步骤一:现学生信息的查找、添加、删除、修改、浏览、保存、查看奖学金信息:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
//结构体
struct Score{
    float math;
    float english;
    float algebra;
    float c_language;
    float total;
};
struct Student{
    long num;
    char name[80];
    char sex;
    struct Score score;
    char scholarship;
    struct Student *next;
}lyj;
typedef Student s;
#define size sizeof(s)
int main();
//查找函数
void seek(FILE*fp){
    int n;
    s *buffer;
    buffer=(s*)malloc(1000);
    n=fread(buffer,size,50,fp);
    free(buffer);
    buffer=(s*)malloc(size*n);//
    fread(buffer,size,n,fp);
    s*head=buffer;
    int t;
    printf("*******************************************************n");
    printf("tt请选择查找方式:ntt1、按学号;ntt2、按姓名;ntt3、按成绩;ntt4、返回上级。n");
    printf("*******************************************************n请选择:n");
    scanf("%d",&t);
    switch(t){
    case 1:{
        long n;
        struct Student *p=head;
        printf("please input the student number:");
        scanf("%ld",&n);
        while(p!=NULL&&p->num!=n)p=p->next;
        if(p!=NULL)
        printf("student num:%ld;nname:%s;nsex:%c;nscore:nmath:%f,nenglish:%f,nalgebra:%f,nc_language:%f,ntotal:%f;n",
            p->num,p->name,p->sex,p->score.math,p->score.english,p->score.algebra,p->score.c_language,p->score.total);
        //type 'Score' does not have an overloaded member 'operator ->'
        printf("there is all;");
           }break;
    case 2:{
        char a[40];
        struct Student *p=head;
        printf("please input the student's name:");
        gets(a);
        while(p!=NULL){//考虑到同名,做不同处理;
            if(strcmp(p->name,a)==0)printf("student num:%ld;nname:%s;nsex:%c;nscore:nmath:%f,nenglish:%f,nalgebra:%f,nc_language:%f,ntotal:%f;n",
            p->num,p->name,p->sex,p->score.math,p->score.english,p->score.algebra,p->score.c_language,p->score.total);
            p=p->next;
        }
        printf("there is all;");
           }break;
    case 3:{
        int n1,n2;
        struct Student *p=head;
        printf("please input the tatle score tanges:(like '10 to 20''成绩 to 成绩')");
        //printf("please input the tatle score tanges:like "10 to 20""成绩 to 成绩"");
        scanf("%d to %d",&n1,&n2);
        while(p!=NULL){
            if(p->score.total>=n1&&p->score.total<=n2)printf("student num:%ld;nname:%s;nsex:%c;nscore:nmath:%f,nenglish:%f,nalgebra:%f,nc_language:%f,ntotal:%f;n",
            p->num,p->name,p->sex,p->score.math,p->score.english,p->score.algebra,p->score.c_language,p->score.total);
            p=p->next;
        }
           }break;
        case 4:main();break;// error C2065: 'main' : undeclared identifier

        printf("there is all;");
        default:printf("it's a illeagle input,please input again.");seek(fp);//again

           }
    free(buffer);fclose(fp);
}
//添加
void add(FILE*fp){//fp=fopen(,"w+a+r")
    int n;
    s*buffer;
    buffer=(s*)malloc(1000);
    n=fread(buffer,size,50,fp);
    free(buffer);
    buffer=(s*)malloc(size*n);//
    fread(buffer,size,n,fp);
    s*wei=buffer;while(wei->next!=NULL)wei=wei->next;
    s*p;
    while(getchar()!='N'){
    wei->next=p=(s*)malloc(size);p->next=NULL;//

//input

    printf("please input the imformation witch you want to add in the fill.nStudent num:");
    scanf("%s",&p->name);
    printf("sex:");fflush(stdin);
    scanf("%c",&p->sex);
    printf("num:");
    scanf("%ld",&p->num);
    s *tem1=buffer,*tem2=p;
    while(tem1!=NULL){
        if(tem1->num==tem2->num){
            printf("学号已经存在,请重新输入;");
            scanf("%d",&tem2->num);
            tem1=buffer,tem2=p;   
        }
            tem1=tem1->next;

   
    }
    printf("score.algebra:");
    scanf("%f",&p->score.algebra);
    printf("score.c_language:");
    scanf("%f",&p->score.c_language);
    printf("score.english:");
    scanf("%f",&p->score.english);
    printf("score.math:");
    scanf("%f",&p->score.math);
   
    p->score.total=p->score.algebra+p->score.c_language+p->score.english+p->score.math;
    if(p->score.total>=360)p->scholarship='Y';
    else p->scholarship='N';
    //
    n++;
    s *totbuf=(s*)malloc(size*n);
    s *b=totbuf,*a=buffer;
    while(a!=NULL){
//word+excel
strcmp(b->name,a->name);
b->sex=    a->sex;
b->num=    a->num;
b->score.algebra=    a->score.algebra;
b->score.c_language=    a->score.c_language;
b->score.english=    a->score.english;
b->score.math=    a->score.math;
b->score.total=    a->score.total;
b->scholarship=    a->scholarship;
    }
 
a=p;
strcmp(b->name,a->name);
b->sex=    a->sex;
b->num=    a->num;
b->score.algebra=    a->score.algebra;
b->score.c_language=    a->score.c_language;
b->score.english=    a->score.english;
b->score.math=    a->score.math;
b->score.total=    a->score.total;
b->scholarship=    a->scholarship;
//word+excel
free(buffer);
buffer=totbuf;
b=p;p=p->next;
free(b);
   
//    printf("Would you want to continue to add?Y/Nn");

}

    if(fwrite(buffer,size,50,fp))puts("Save success!");//保存并检查。
   
    free(buffer);
    fclose(fp);
    getchar();main();
}

//删除
void del(FILE*fp){
    int n;
    s *buffer;
    buffer=(s*)malloc(1000);
    n=fread(buffer,size,50,fp);
    free(buffer);
    buffer=(s*)malloc(size*n);//

    printf("*******************************************************n");
    printf("tt请输入所删除信息对应的学号n");
    printf("*******************************************************n请选择:n");
    long t;
    scanf("%ld",&t);
    s *a=buffer,*b=buffer;
    if(a->num!=t){
        a=a->next;
    while(a->next!=NULL){
        if(a->num==t)break;
        a=a->next;
        b=b->next;
    }
    }
    if(a==NULL)printf("该学号不存在。n");
    else{
        b->next=a->next;
        free(a);
    }
    n--;
    s *totbuf=(s*)malloc(size*n);

while(a!=NULL){
//word+excel
strcmp(b->name,a->name);
b->sex=    a->sex;
b->num=    a->num;
b->score.algebra=    a->score.algebra;
b->score.c_language=    a->score.c_language;
b->score.english=    a->score.english;
b->score.math=    a->score.math;
b->score.total=    a->score.total;
b->scholarship=    a->scholarship;
    }
 
//word+excel


    if(fwrite(totbuf,size,50,fp))puts("Save success!");//保存并检查。


fclose(fp);
free(buffer);
free(totbuf);
getchar();main();
}

//浏览
void read(FILE*fp){
    s*p;
    int n;
    p=(s*)malloc(1000);
    n=fread(p,size,50,fp);
    free(p);
    p=(s*)malloc(size*n);

    while(p!=NULL){
printf("student num:%ld;nname:%s;nsex:%c;nscore:nmath:%f,nenglish:%f,nalgebra:%f,nc_language:%f,ntotal:%f;n",
            p->num,p->name,p->sex,p->score.math,p->score.english,p->score.algebra,p->score.c_language,p->score.total);
    p=p->next;
    }
    free(p);fclose(fp);getchar();main();
}
//修改学生信息
void change(FILE*fp){
    int n;
    s *buffer;
    buffer=(s*)malloc(1000);
    n=fread(buffer,size,50,fp);
    free(buffer);
    buffer=(s*)malloc(size*n);//

    printf("*******************************************************n");
    printf("tt请输入所修改信息对应的学号n");
    printf("*******************************************************n请选择:n");
    long t;
    scanf("%ld",&t);
    s *a=buffer;
    while(a->next!=NULL){
        if(a->num==t)break;
        a=a->next;
    }
   
    if(a==NULL)printf("该学号不存在。n");
    else{
        ////////////////////
        printf("please input the imformation witch you want to charge.nStudent num:");
        printf("*******************************************************n");
    printf("tt请选择修改内容:ntt1、姓名;ntt2、性别ntt;3、学号;ntt4、成绩;ntt4、取消;n");
    printf("*******************************************************n请选择:n");   
    int t;
    scanf("%d",&t);
    s*p=buffer;    s *tem1=buffer,*tem2=p;
    switch(t){
    case 1:
    printf("name:");
    scanf("%s",&p->name);
    break;
    case 2:
    printf("sex(f/m):");
    fflush(stdin);
    scanf("%c",&p->sex);
    break;
    case 3:
    printf("num:");
    scanf("%ld",&p->num);

    while(tem1!=NULL){
        if(tem1->num==tem2->num){
            printf("学号已经存在,请重新输入;");
            scanf("%ld",&tem2->num);
            tem1=buffer;
            }
            tem1=tem1->next;
        
    }break;
    case 4:
    printf("score.algebra:");
    scanf("%f",&p->score.algebra);
    printf("score.c_language:");
    scanf("%f",&p->score.c_language);
    printf("score.english:");
    scanf("%f",&p->score.english);
    printf("score.math:");
    scanf("%f",&p->score.math);
   
   
    p->score.total=p->score.algebra+p->score.c_language+p->score.english+p->score.math;
    if(p->score.total>=360)p->scholarship='Y';
    else p->scholarship='N';
    break;/////////////////////////////////
    default:break;
    }
   



    }

    if(fwrite(buffer,size,50,fp))puts("Save success!");//保存并检查。


fclose(fp);
free(buffer);
getchar();main();

}
//查看奖学金信息
void scls(FILE*fp){
    int n;
    s *buffer;
    buffer=(s*)malloc(1000);
    n=fread(buffer,size,50,fp);
    free(buffer);
    buffer=(s*)malloc(size*n);//

    printf("*******************************************************n");
    printf("tt请输入查询学号n");
    printf("*******************************************************n请选择:n");
    long t;
    scanf("%ld",&t);
    s*p=buffer;
    while(p!=NULL){
        if(p->num==t){
    printf("奖学金如下情况为:n");
    printf("%c",p->scholarship);
        }
        p=p->next;
    }
    if(p==NULL)printf("查无此人。");
    free(buffer);
    fclose(fp);
    getchar();main();
}

int main(){
    system("cls");
    fflush(stdin);
    FILE *fp;
    printf("*******************************************************n");
    printf("tt   学生信息管理系统ntt1、查询成绩信息;ntt2、添加学生信息;ntt3、删除学生信息;ntt4、浏览全部学生信息;ntt5、修改学生信息;ntt6、查询奖学金,ntt6、退出。n");
    printf("*******************************************************n请选择:n");
    int t;
    scanf("%d",&t);
    switch(t){
    case 1:fp=fopen("FILE_LYJ","rb");
        seek(fp);
        break;
    case 2:fp=fopen("FILE_LYJ","wb");
        add(fp);
        break;
    case 3:fp=fopen("FILE_LYJ","wb");
        del(fp);
        break;
    case 4:fp=fopen("FILE_LYJ","rb");
        read(fp);
        break;
    case 5:fp=fopen("FILE_LYJ","wb");
        change(fp);
        break;
    case 6:fp=fopen("FILE_LYJ","rb");
        scls(fp);
        break;
    default:break;
    }/**/
/*    fp=fopen("FILE_LYJ","wb");//崩溃,前面因为没有加引号,一直不能通过;百度坑我;

    s*p=&lyj;//第一次写入,生成文件;
    scanf("%s",&p->name);
    printf("sex:");fflush(stdin);
    scanf("%c",&p->sex);
    printf("num:");
    scanf("%ld",&p->num);
    printf("score.algebra:");
    scanf("%f",&p->score.algebra);
    printf("score.c_language:");
    scanf("%f",&p->score.c_language);
    printf("score.english:");
    scanf("%f",&p->score.english);
    printf("score.math:");
    scanf("%f",&p->score.math);p->next=NULL;

   
    p->score.total=p->score.algebra+p->score.c_language+p->score.english+p->score.math;
    if(p->score.total>=360)p->scholarship='Y';
    else p->scholarship='N';if(int n=fwrite(&lyj,size,1,fp))printf("%d",n);
    fclose(fp);*/
    return 0;
}
搜索更多相关主题的帖子: Score num buffer printf scanf 
2018-01-12 13:42
Rhyme_119
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2018-1-12
收藏
得分:0 
回复 3楼 Jonny0201
谢了,我重写了。改错太麻烦;
2018-01-14 12:55
Rhyme_119
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2018-1-12
收藏
得分:0 
回复 2楼 吹水佬
谢了,我重写了。改错太麻烦;
2018-01-14 12:55
快速回复:我大作业运行不了
数据加载中...
 
   



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

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