一道简单的数据结构题?

huore 2002-03-15 01:46:20
本人刚开始学习C数据结构,遇到一个小问题,请帮忙。
/*用单链表遍一个学生成绩系统。具有查询成绩,修改成绩,删除成绩,添加 成绩全班平均*/
#include <stdlib.h>

struct list
{int index;
int number;

int chinese,english,math;
struct list *next;
};
typedef struct list node;
typedef node *link;
int inquire(link head,int index)
{link pointer;
pointer=head;
while(pointer!=NULL)
{printf("Student scores\n");
printf("%d ",index);
printf(" School Number:%d\n",pointer->number);
printf(" Chinese score:%d\n",pointer->chinese);
printf(" English score:%d\n",pointer->english);
printf(" Math score:%d\n",pointer->math);
pointer=pointer->next;
}

}

int modify(link head)
{link pointer;
pointer=head;
int chinese0,english0,math0;
int index0;
scanf("%d",index0);
while(pointer!=NULL)
{if(pointer->index==index0)

{printf("========================================");
printf("=1.Modify Number =");
prinrf("=2.Modify Name =");
prinrf("=3.Modify Chineae score =");
prinrf("=4.Modify English score =");
prinrf("=5.Modify Math score =");
printf("========================================");
printf("Please input your choose");
int select;
scanf("%d",select);
switch(select)
{case 1: printf(" School Number:\n",number0);
int number0;
scanf("%d",number0);
pointer->number=number0;
break;
case 2:
break;
case 3: printf(" Chinese score:\n",chinese0);
int chinese0;
scanf("%d",chinese0);
pointer->chinese=chinese0;
break;
case 4: printf(" English score:\n",english0);
int english;
scanf("%d",english);
pointer->english=english0;
break;
case 5: printf(" Math score:\n",math0);
int math0;
scanf("%d",math0);
pointer->math=math0;
break;
}
pointer=pointer->next;
}
}


delet(link head)
{link pointer;
link back;
pointer=head;
int index1;
printf("Please input the student index you want to delete\n");
scanf("%d",index1);

while(pointer!=NULL)
{if(head.>next=index1)
{head=pointer->next;
free(pointer);
break; }

back=pointer;
pointer=pointer->next;
if(pointer->index=index1)
{back->next=pointer->next;
free(pointer);
}
}
return head;

}


link add(link head)
{ link pointer;
pointer=head;
link new0;

int index2=0;
int number1;
int chinese1,english1,math1;
new0=(link)malloc(sizeof(node));
while(pointer!=NULL)
{pointer=pointer->next;
index2++}
new0->index=index2;
printf("Please Input the data\n");
printf("School Number\n");
scanf("%d",number1);
new0->number1;
printf("Chinese\n");
scanf("%d",chinese1)
new0->chinese=chinese1;
printf("English\n");
scanf("%d",english1);
new0->english=english1;
printf("Math");
scanf("%d",math1);
new0->math=math1;
pointer->next=new0->next;
pointer->next=new0;

}


link average(head)
{ link pointer;
pointer=head;
int sum,i,ave;
i=0;
sum=0;
while(pointer!=NULL)
{sum=pointer.>chinese+pointer.>english+pointer.>math+sum;
pointer=pointer->next;
i++;
}
ave=sum/i;
printf("Score average Is:%d",ave);

}


void main()
{
link head;
head=(link)malloc(sizeof(node));
int selection;

while(1)
{printf("========================================");
printf("=Simple Student Score Management System=");
prinrf("=1.inquire student score =");
prinrf("=2.modify student score =");
prinrf("=3.delete student score =");
prinrf("=4.add student score =");
prinrf("=5.student average score =");
prinrf("=6.quit =");
printf("========================================");
printf("Please input your choose");
scanf("%d",selection);
switch(selection)
{case 1:inquire(head);
break;
case 2:modify(head);
break;
case 3:delet(head);
break;
case 4:add(head);
break;
case 5:average(head);
break;
case 6:
exit(1);
break;
}
}

}
...全文
49 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
huore 2002-03-17
  • 打赏
  • 举报
回复
不好意思我看错了,改好了。
再次谢谢A_code(A频道)
给你加分。
huore 2002-03-17
  • 打赏
  • 举报
回复
感谢A_code(A频道)
可是还是不对啊,你有26个错误,6个警告
yangguang0 2002-03-16
  • 打赏
  • 举报
回复
很不错
Alexeyomux 2002-03-16
  • 打赏
  • 举报
回复
能不能写出错误提示和你对错误的看法?或许这样更好。
A_code 2002-03-16
  • 打赏
  • 举报
回复
程序编得不错嘛!只不过错误实在让我不敢恭维,"竟然有十多个错误",这可不是十几个的问题,编译一下你就会发现十几个只是第一个函数(modify)的错误而已.还有你把printf写成prinrf,我看了半天才看出来(我也很差劲的),以后可要小心点了.
我已经调试好的程序是:

include <stdlib.h>

struct list
{int index;
int number;

int chinese,english,math;
struct list* next;
};
typedef struct list node;
typedef node* link;
int inquire(link head,int index)
{link pointer=NULL;
pointer=head;
while(pointer!=NULL)
{printf("Student scores\n");
printf("%d ",index);
printf(" School Number:%d\n",pointer->number);
printf(" Chinese score:%d\n",pointer->chinese);
printf(" English score:%d\n",pointer->english);
printf(" Math score:%d\n",pointer->math);
pointer=pointer->next;
}

}

int modify(link head)
{link pointer=head;
int chinese0,english0,math0;
int index0,number0;
int select0;
scanf("%d",&index0);
while(pointer!=NULL)
{if (pointer->index==index0)
{
printf("========================================");
printf("=1.Modify Number =");
printf("=2.Modify Name =");
printf("=3.Modify Chineae score =");
printf("=4.Modify English score =");
printf("=5.Modify Math score =");
printf("========================================");
printf("Please input your choose:");
scanf("%d",&select0);
switch(select0)
{
case 1: printf(" School Number:\n");
scanf("%d",&number0);
pointer->number=number0;
break;
case 2:
break;
case 3: printf(" Chinese score:\n");

scanf("%d",&chinese0);
pointer->chinese=chinese0;
break;
case 4: printf(" English score:\n");

scanf("%d",&english0);
pointer->english=english0;
break;
case 5: printf(" Math score:\n");

scanf("%d",&math0);
pointer->math=math0;
break;
}
}
pointer=pointer->next;
}

}

delet(link head)
{link pointer=head;
link back;
int index1;
printf("Please input the student index you want to delete\n");
scanf("%d",&index1);
while(pointer!=NULL)
{ if(head->index==index1)
{
head=pointer->next;
free(pointer);
break;
}
back=pointer;
pointer=pointer->next;
if(pointer->index==index1)
{
back->next=pointer->next;
free(pointer);
}
}
return 0;

}


link add(link head)
{ link pointer=head;
link new0;

int index2=0;
int number1;
int chinese1,english1,math1;
new0=(link)malloc(sizeof(node));
while(pointer!=NULL)
{
pointer=pointer->next;
index2++;
}
new0->index=index2;
printf("Please Input the data\n");
printf("School Number\n");
scanf("%d",&number1);
new0->number=number1;
printf("Chinese\n");
scanf("%d",&chinese1);
new0->chinese=chinese1;
printf("English\n");
scanf("%d",&english1);
new0->english=english1;
printf("Math");
scanf("%d",&math1);
new0->math=math1;
pointer->next=new0;
new0->next=NULL;

}


link average(link head)
{ link pointer=head;
int sum,i,ave;
i=0;
sum=0;
while(pointer!=NULL)
{ sum=pointer->chinese+pointer->english+pointer->math+sum;
pointer=pointer->next;
i++;
}
ave=sum/i;
printf("Score average Is:%d",ave);

}


void main()
{
link head=(link)malloc(sizeof(node));
int selection;
int index;
while(1)
{printf("==================");
printf("Simple Student Score Management System");
printf("==================\n");
printf("========== 1. inquire student score ===========\n");
printf("========== 2. modify student score =========== \n");
printf("========== 3. delete student score ===========\n");
printf("========== 4. add student score ===========\n");
printf("========== 5. student average score ===========\n");
printf("========== 6. quit ===========\n");
printf("==========================================================================\n");
printf("Please input your choose:");
scanf("%d",&selection);
switch(selection)
{case 1:printf("Please input your inpuire number:");
scanf("%d",&index);
inquire(head,index);
break;
case 2:modify(head);
break;
case 3:delet(head);
break;
case 4:add(head);
break;
case 5:average(head);
break;
case 6:
exit(1);
break;
}
}

}


是在tubro2.0上通过的.我改了一些界面.不过程序的功能好像还有一些不对.
我也在学C语言,以后有问题的话,希望和能和大家多交流.
kongyi 2002-03-15
  • 打赏
  • 举报
回复
关注
kaitty 2002-03-15
  • 打赏
  • 举报
回复
你这不叫程序,我看你最好从小程序做起。
poly30 2002-03-15
  • 打赏
  • 举报
回复
你的错误多数来源自:对指针的不熟悉,在指针的使用之前,必须初始化。

比如:link linkpoint=NULL;

还有,最好把你的错误都列出来。
drason 2002-03-15
  • 打赏
  • 举报
回复
太经典了
luoxiao_std01 2002-03-15
  • 打赏
  • 举报
回复
把你的错误提示写出来!
langhaixin 2002-03-15
  • 打赏
  • 举报
回复
typedef struct list node;
typedef node *link; //这样定义类型不行 还是把这行删了
//或是改成typedef node* link;

int inquire(node ** head,int index) //此处
{node *pointer;
pointer=*head;

int modify(node **head) //这里也时
{node *pointer;
pointer=*head;

delet(node **head) //又是同样的错误
{node *pointer;
node *back;
pointer=*head;

//类似的错误很多
huore 2002-03-15
  • 打赏
  • 举报
回复
竟然有十多个错误,请大家帮忙解决
谢谢
昨日,11.19,最新整理了,第61-80,现在公布上传。 另加上之前公布的第1-60 ,在此做一次汇总上传,以飨各位。 可以这么说,绝大部分的面试,都是这100 道系列的翻版, 此微软等公司数据结构+算法面试100 系列,是极具代表性的经典面试。 而,对你更重要的是,我自个还提供了答案下载,提供思路,呵。 所以,这份资料+答案,在网上是独一无二的。 ------------------------------------ 整理资源,下载地址: 答案系列: 1.[最新答案V0.3 版]微软等数据结构+算法面试100 [第21-40 答案] http://download.csdn.net/source/2832862 2.[答案V0.2 版]精选微软数据结构+算法面试100 [前20 ]--修正 http://download.csdn.net/source/2813890 //此份答案是针对最初的V0.1 版本,进行的校正与修正。 3.[答案V0.1 版]精选微软数据结构+算法面试100 [前25 ] http://download.csdn.net/source/2796735 目系列: 4.[第一部分]精选微软等公司数据结构+算法经典面试100 [1-40 ] http://download.csdn.net/source/2778852 5.[第1 -60 汇总]微软等数据结构+算法面试100 http://download.csdn.net/source/2826690 更多资源,下载地址: http://v_july_v.download.csdn.net/ 若你对以上任何目或任何答案,有任何问,欢迎联系我: My E-mail: zhoulei0907@yahoo.cn ------------- 作者声明: 本人July 对以上公布的所有任何目或资源享有版权。转载以上公布的任何一, 或上传百度文库资源,请注明出处,及作者我本人。 向你的厚道致敬。谢谢。 ---July、2010 年11 月20 日。 ------------------------------------------------------ 各位,若对以上100任何一道,或对已上传的任何一的答案, 有任何问,请把你的思路、想法,回复到此帖子上, 微软等100系列,永久维护地址(2010年11.26日): http://topic.csdn.net/u/20101126/10/b4f12a00-6280-492f-b785-cb6835a63dc9.html
火爆出炉:微软等数据结构+算法面试100首次完整亮相 ---100V0.1版最终完成 作者:July 2010年12月6日 微软等100系列V0.1版终于结束了。 从2010年10月11日当天最初发表前40以来,直至此刻,整理这100,已有近2个月。 2个月,因为要整理这100,很多很多其它的事都被我强迫性的搁置一旁, 如今,要好好专心去做因这100而被耽误的、其它的事了。 这微软等数据结构+算法面试100系列(目+答案),到底现在、或此刻、或未来, 对初学者有多大的意义,在此,我就不给予评说了。 由他们自己来认定。所谓,公道自在人心,我相信这句话。 任何人,对以下任何资料、目、或答案,有任何问,欢迎联系我。 作者邮箱: zhoulei0907@yahoo.cn 作者声明: 转载或引用以下任何资料、或目,请注明作者本人July及出处。 向您的厚道致敬,谢谢。 好了,请享受这完完整整的100吧,这可是首次完整亮相哦。:D。 ............ ............ 答案系列: 5.[最新答案V0.3版]微软等数据结构+算法面试100[第21-40答案] http://download.csdn.net/source/2832862 6.[答案V0.2版]精选微软数据结构+算法面试100[前20]--修正 http://download.csdn.net/source/2813890 //此份答案是针对最初的V0.1版本,进行的校正与修正。 7.[答案V0.1版]精选微软数据结构+算法面试100[前25] http://download.csdn.net/source/2796735 剩下的第41-100答案,正在整理中。预计明年整理公布。 请各位,细心的等待。谢谢。 更多资源,下载地址: http://v_july_v.download.csdn.net/ ================================== 更多详情,请参见本人博客: My Blog: http://blog.csdn.net/v_JULY_v --------------------------------------------------------------------------------------- 各位,若对以上100任何一道,或对已上传的任何一的答案, 有任何问,请把你的思路、想法,回复到此帖子上, 微软等100系列,永久维护地址(2010年11.26日): http://topic.csdn.net/u/20101126/10/b4f12a00-6280-492f-b785-cb6835a63dc9.html
精选微软等数据结构+算法面试100答案修正V0.2版本 -------------------- 此份答案是针对,前期已公布的最初的那份答案的,初步校正与修正。 http://download.csdn.net/source/2796735(V0.1版) 相比第一份V0.1版答案,此份答案V0.2版更加准确,亦修正了不少目的答案。 此份20的答案,思路更加清晰易懂,简介明了。 请享用。July、2010/11/06。 其它资源,下载地址: 1.[最新答案V0.3版]微软等数据结构+算法面试100[第21-40答案] http://download.csdn.net/source/2832862 2.[第1-60汇总]微软等数据结构+算法面试100 http://download.csdn.net/source/2826690 3.[答案V0.2版]精选微软数据结构+算法面试100[前20]--修正 http://download.csdn.net/source/2813890 //此份答案是针对最初的V0.1版本,进行的校正与修正。 4.[答案V0.1版]精选微软数据结构+算法面试100[前25] http://download.csdn.net/source/2796735 5.[第二部分]精选微软等公司结构+算法面试100[前41-60]: http://download.csdn.net/source/2811703 6.[第一部分]精选微软等公司数据结构+算法经典面试100[1-40] http://download.csdn.net/source/2778852 更多资源,下载地址: http://v_july_v.download.csdn.net/ ------------------------------------------------------ 各位,若对以上100任何一道,或对已上传的任何一的答案, 有任何问,请把你的思路、想法,回复到此帖子上, 微软等100系列,永久维护地址(2010年11.26日): http://topic.csdn.net/u/20101126/10/b4f12a00-6280-492f-b785-cb6835a63dc9.html
此为我个人搜集整理的, 精选微软等公司,有关 数据结构和算法的面试100[前40], 此绝对值得你下载收藏。 网友yui评论,真是够多的了,从此,不用再看其它面试.... 一句话,请享用。 其它资源,下载地址: 1.[最新答案V0.3版]微软等数据结构+算法面试100[第21-40答案] http://download.csdn.net/source/2832862 2.[第1-60汇总]微软等数据结构+算法面试100 http://download.csdn.net/source/2826690 3.[答案V0.2版]精选微软数据结构+算法面试100[前20]--修正 http://download.csdn.net/source/2813890 //此份答案是针对最初的V0.1版本,进行的校正与修正。 4.[答案V0.1版]精选微软数据结构+算法面试100[前25] http://download.csdn.net/source/2796735 5.[第二部分]精选微软等公司结构+算法面试100[前41-60]: http://download.csdn.net/source/2811703 6.[第一部分]精选微软等公司数据结构+算法经典面试100[1-40] http://download.csdn.net/source/2778852 更多资源,下载地址: http://v_july_v.download.csdn.net/ //请继续期待,后续内容。 ------------------------------------------------------ 各位,若对以上100任何一道,或对已上传的任何一的答案, 有任何问,请把你的思路、想法,回复到此帖子上, 微软等100系列,永久维护地址(2010年11.26日): http://topic.csdn.net/u/20101126/10/b4f12a00-6280-492f-b785-cb6835a63dc9.html -------July、2010年12月2日。

69,381

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧