| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 534 人关注过本帖
标题:这个程序哪里错了?求指点迷津!
只看楼主 加入收藏
冯jungle
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2012-12-16
结帖率:87.5%
收藏
已结贴  问题点数:40 回复次数:6 
这个程序哪里错了?求指点迷津!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "math.h"
#define LEN sizeof(struct student)
图片附件: 游客没有浏览图片的权限,请 登录注册
第二次上机作业.rar (1.93 KB)


struct student
{
    int num;
    char name[20];
    float score;
    struct student *next;
} *head;

typedef struct student St;

St* Input(St *head,St *st);
St* Start();
St* Inputp(St *head,St *w);
St* Delete(St* st);
St* Deletep(St* q1,int number);
St* DeleteCom(St* head,St* q2);
void Save(char fname, St* p);
void Output(St* st);
void Tongji(St* head);



St* Start()                //3õê¼»ˉá′±í
{
    head=NULL;
    return head;
};

St* Inputp(St *head,St *w)            //ìí¼óᬽóμã
{
    St *p1;
   
    if(head=NULL)
        head=w;
    else
    {
        p1=head;
        while(p1->next != NULL)
            p1=p1->next;
        p1->next = w;
    }
    printf("ìí¼ó3é1|!\n");
   
    return head;
};


St* Input(St *st)                    //ìí¼óѧéúDÅÏ¢
{
    St *p;

    p=(St*)malloc(sizeof(LEN));

    printf("êäèëѧéúѧoÅ:\t");
    scanf("%d",&p->num );
    printf("DÕÃû:\t");
    scanf("%s",p->name);
    printf("3鼨:\t");
    scanf("%f",&p->score );

    p->next = NULL;
    st=Inputp(st,p);
    //Save("CJ.txt",st);        //±£′æѧéúDÅÏ¢£¬CJ.txtÎa±£′æμÄÎļtÃû×Ö
    return st;
};


void Output(St* st)                //êä3öѧéúDÅÏ¢
{
    St *x;
    x=(St*)malloc(sizeof(LEN));

    x=st;
    if(x=NULL)
        printf("ÎTDÅÏ¢!!\n");
    else
    {
        while(x->next != NULL)
        printf("ѧoÅ:\t%dDÕÃû\t&s3鼨\t%f",x->num,x->name,x->score);
        x=x->next;
    }

};

St* Delete(St* head)                //é¾3yѧéúDÅÏ¢
{
    St *q1,*q2;
    int number;
    q1=(St*)malloc(sizeof(LEN));
    q2=(St*)malloc(sizeof(LEN));

    q1=head;

    printf("êäèëÄúòaé¾3yѧéúμÄѧoÅ:");
    scanf("%d",&number);

    if(q1==NULL)
        printf("ÎTDÅÏ¢!\n");
    else
    {
        q2=Deletep(head,number);                     //μ÷óÃDeletepoˉêyÕòμ½numberËùÔúμĽúμã
        if(q2==NULL)
            printf("′íÎó!!!\n");
        else
            head=DeleteCom(head,q2);                //μ÷óÃDeleteComoˉêyíê3éé¾3y q2êÇòaé¾3yμĽúμã
        printf("é¾3yíê3é!!\n");
    }
    return head;
};
        
struct student* Deletep(St* head,int number)            //Õòòaé¾3yѧéúμÄμØÖ·
{    //extern number;
    St *p;
    p=head;
    while(p->next != NULL && p->num != number)
            p=p->next ;
   
    return p;
};

St* DeleteCom(St* head,St* q2)
{    //extern *q2;
    St *m1,*m2,*temp;
    m1=(St*)malloc(sizeof(LEN));
    m2=(St*)malloc(sizeof(LEN));
    temp=(St*)malloc(sizeof(LEN));

    if(head==q2)
    {
        if(head->next != NULL)
            head=head->next ;
        else
            head=NULL;
    }
    else
    {
        m1=head;
        while(m1!=NULL)
            m2=m1->next;
        if(m2==q2 && q2->next != NULL)
        {
            m2->next = m1->next;
            free(m2);
        }
        else if( m2 == q2 && q2->next == NULL)
        {
            m1->next =NULL;
            free(q2);
        }
        m1=m1->next ;
    }
    return head;
};

void Tongji(St* head)
{
    int a=0,b=0,c=0,d=0,e=0;
    St *y;
    y=(St*)malloc(sizeof(LEN));
    y=head;

    if(y==NULL)
        printf("\t\tÎTDÅÏ¢!\n");
    else
        while(y->next != NULL)
        {
            if(y->score >=90)
                a++;
            if(y->score >= 80 && y->score <90)
                b++;
            if(y->score >= 70 && y->score <80)
                c++;
            if(y->score >= 60 && y->score <70)
                d++;
            if(y->score < 60)
                e++;
            y=y->next ;
        }
        free(y);
        printf("\tóÅ%dèË\tá¼%dèË\tÖD%dèË\t¼°¸ñ%dèË\t2»¼°¸ñ%dèË\n",a,b,c,d,e);
};

void Save(char *fname, St* p)
{
    FILE *fp;
    St *pst=NULL;
   
    fp=fopen(fname,"w+");
    if((fopen(fname,"w+"))==NULL)
        printf("\t′íÎó!\n");
    exit(0);
    pst=(St*)malloc(sizeof(LEN));
   
    fprintf(fp,"\t\t\têy¾Y½á113鼨\t\t\t\n");
    fprintf(fp,"\tѧoÅ\tDÕÃû\t3鼨\n");
    pst=p;
    while(fp != NULL)
    {
        fwrite(pst,sizeof(St),1,fp);
        pst=pst->next ;
    }
    fclose(fp);
};

void main()
{
    St *st;
    st=Start();
   
    printf("\t\t\têy¾Y½á113鼨1üàíÏμí3\t\t\t\n");
    int choice;
    while(choice != 6)
    {
        printf("\n\t\t\t1--êäèëѧéú3鼨\n\t\t\t2--êä3öѧéú3鼨\n\t\t\t3--é¾3yÄ3ѧéú3鼨\n\t\t\t4--í3¼Æѧéú3鼨\n\t\t\t5--±£′æѧéúDÅÏ¢\n\t\t\t6--íË3öÏμí3\n");
        printf("êäèëÄúòa½øDDμÄ2ù×÷:\t\t(1,2,3,4,5)\n");
        
        scanf("%d",&choice);
        switch(choice)
        {
        case 1:st = Input(st);break;
        case 2:Output(st);break;
        case 3:st=Delete(st);break;
        case 4:Tongji(st);break;
        case 5:Save("CJ.txt",st);break;
        }
    }
    printf("\n»¶ó-Ôù′Îê1óÃ!\n");

};
搜索更多相关主题的帖子: include number 
2013-10-27 09:27
tlliqi
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:204
帖 子:15453
专家分:65956
注 册:2006-4-27
收藏
得分:8 
//±£′&aelig;&Ntilde;§éúD&Aring;&Iuml;¢£&not;CJ.txt&Icirc;a±£′&aelig;μ&Auml;&Icirc;&Auml;&frac14;t&Atilde;&ucirc;×&Ouml;
这是什么语?
2013-10-27 14:21
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
收藏
得分:8 
指针飞了吧

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2013-10-27 16:24
逆风而前
Rank: 7Rank: 7Rank: 7
来 自:福建
等 级:黑侠
威 望:7
帖 子:193
专家分:567
注 册:2013-2-14
收藏
得分:8 
图片附件: 游客没有浏览图片的权限,请 登录注册
2013-11-01 21:01
逆风而前
Rank: 7Rank: 7Rank: 7
来 自:福建
等 级:黑侠
威 望:7
帖 子:193
专家分:567
注 册:2013-2-14
收藏
得分:0 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "math.h"
#define LEN sizeof(struct student)

struct student
{
    int num;
    char name[20];
    float score;
    struct student *next;
} *head;

typedef struct student St;

St* Input(St *head,St *st);
St* Start();
St* Inputp(St *head,St *w);
St* Delete(St* st);
St* Deletep(St* q1,int number);
St* DeleteCom(St* head,St* q2);
void Save(char fname, St* p);
void Output(St* st);
void Tongji(St* head);



St* Start()                //初始化链表
{
    head=NULL;
    return head;
};

St* Inputp(St *head,St *w)            //添加连接点
{
    St *p1;
   
    if(head==NULL)
        head=w;
    else
    {
        p1=head;
        while(p1->next != NULL)
            p1=p1->next;
        p1->next = w;
    }
    printf("添加成功!\n");
   
    return head;
};


St* Input(St *st)                    //添加学生信息
{
    St *p;
    printf("**标志1**\n");
    p=(St*)malloc(sizeof(student));

    printf("输入学生学号:\t");
    scanf("%d",&p->num );
    printf("姓名:\t");
    scanf("%s",p->name);
    printf("成绩:\t");
    scanf("%f",&p->score );

    p->next=NULL;
    st=Inputp(st,p);
    //Save("CJ.txt",st);        //保存学生信息,CJ.txt为保存的文件名字
    return st;
};


void Output(St* st)                //输出学生信息
{
    St *x;
    x=(St*)malloc(sizeof(student));

    x=st;
    if(x==NULL)
        printf("无信息!!\n");
    else
    {
        while(x!= NULL)
        {
            printf("学号:%d\t姓名:%s\t成绩:%f\n",x->num,x->name,x->score);
            x=x->next;
        }
    }

};

St* Delete(St* head)                //删除学生信息
{
    St *q1,*q2;
    int number;
    q1=(St*)malloc(sizeof(student));
    q2=(St*)malloc(sizeof(student));

    q1=head;

    printf("输入您要删除学生的学号:");
    scanf("%d",&number);

    if(q1==NULL)
        printf("无信息!\n");
    else
    {
        q2=Deletep(head,number);                     //调用Deletep函数找到number所在的节点
        if(q2==NULL)
            printf("错误!!!\n");
        else
            head=DeleteCom(head,q2);                //调用DeleteCom函数完成删除 q2是要删除的节点
        printf("删除完成!!\n");
    }
    return head;
};
        
struct student* Deletep(St* head,int number)            //找要删除学生的地址
{    //extern number;
    St *p;
    p=head;
    while((p!= NULL)&& (p->num!=number))
            p=p->next ;
   
    return p;
};

St* DeleteCom(St* head,St* q2)
{    //extern *q2;
    St *m1,*m2,*temp;
    m1=(St*)malloc(sizeof(student));
    m2=(St*)malloc(sizeof(student));
    temp=(St*)malloc(sizeof(student));

    if(head==q2)
    {
        if(head->next != NULL)
            head=head->next ;
        else
            head=NULL;
    }
    else
    {
       m1=head;
        while(m1!=NULL)
        {
        if(m1==q2 && q2->next != NULL)
        {
            m2->next = m1->next;
            free(m1);
            break;
        }
        else if( m1 == q2 && q2->next == NULL)
        {
            m2->next =NULL;
            free(q2);
            break;
        }
        m2=m1;
        m1=m1->next ;
        }

    }
    return head;
};

void Tongji(St* head)
{
    int a=0,b=0,c=0,d=0,e=0;
    St *y;
    y=(St*)malloc(sizeof(student));
    y=head;

    if(y==NULL)
        printf("\t\t无信息!\n");
    else
        while(y!= NULL)
        {
            if(y->score >=90)
                a++;
            if(y->score >= 80 && y->score <90)
                b++;
            if(y->score >= 70 && y->score <80)
                c++;
            if(y->score >= 60 && y->score <70)
                d++;
            if(y->score < 60)
                e++;
            y=y->next ;
        }
        free(y);
        printf("\t优%d人\t良%d人\t中%d人\t及格%d人\t不及格%d人\n",a,b,c,d,e);
};

void Save(char *fname, St* p)
{
    FILE *fp;
    St *pst=NULL;
   
    fp=fopen(fname,"w+");
    if((fopen(fname,"w+"))==NULL)
        printf("\t错误!\n");
    exit(0);
    pst=(St*)malloc(sizeof(student));
   
    fprintf(fp,"\t\t\t数据结构成绩\t\t\t\n");
    fprintf(fp,"\t学号\t姓名\t成绩\n");
    pst=p;
    while(fp != NULL)
    {
        fwrite(pst,sizeof(St),1,fp);
        pst=pst->next ;
    }
    fclose(fp);
};

void main()
{
    St *st;
    st=Start();
   
    printf("\t\t\t数据结构成绩管理系统\t\t\t\n");
    int choice;
    while(choice != 6)
    {
        printf("\n\t\t\t1--输入学生成绩\n");
        printf("\t\t\t2--输出学生成绩\n");
        printf("\t\t\t3--删除某学生成绩\n");
        printf("\t\t\t4--统计学生成绩\n");
        printf("\t\t\t5--保存学生信息\n");
        printf("\t\t\t6--退出系统\n");
        printf("输入您要进行的操作:\t\t(1,2,3,4,5)\n");
        
        scanf("%d",&choice);
        switch(choice)
        {
        case 1:st = Input(st);break;
        case 2:Output(st);break;
        case 3:st=Delete(st);break;
        case 4:Tongji(st);break;
        case 5:Save("CJ.txt",st);break;
        }
        getchar();
    }
    printf("\n欢迎再次使用!\n");

};




[ 本帖最后由 逆风而前 于 2013-11-1 21:06 编辑 ]
2013-11-01 21:04
haiboself
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:193
专家分:196
注 册:2013-10-23
收藏
得分:8 
好复杂!!!
2013-11-01 21:05
ljx小子
Rank: 8Rank: 8
来 自:星星
等 级:蝙蝠侠
威 望:2
帖 子:222
专家分:916
注 册:2013-10-7
收藏
得分:8 
回复 5楼 逆风而前
  perfect

。。。。。。。。。。。
2013-11-01 22:50
快速回复:这个程序哪里错了?求指点迷津!
数据加载中...
 
   



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

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