输入若干个学生信息(学号 姓名 成绩) 输入学号为0时输入结束 建立一个单向链表 再输入一个成绩值 将成绩大于该值的学生信息输出
1、首先,定义一个数据结构student,包含学生的各信息。
2、定义两个student类型的变量,保存所有学生的成绩信息和临时变量。
3、定义一个自定义函数,输入学生的成绩信息。
4、具体实现学生信息的输入,并计算总分。
5、主函数中,先定义4个整型变量,保存学生的总数,以及控制循环的变量。
6、接着,输入学生总数,保存在变量n中。
7、运行程序查看最后结果。
注意事项:
C++不仅拥有计算机高效运行的实用性特征,同时还致力于提高大规模程序的编程质量与程序设计语言的问题描述能力。
这道题我已在另一地方回答——
http://zhidao.baidu.com/question/255870848.html?sort=6&old=1#answer-1404748948
以下是去掉最后一个条件——“再输入一个成绩值 将成绩大于该值的学生信息输出”。。。的解答!
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct stud_node{
int num;
char name[20];
int score;
struct stud_node *next;
};
void main()
{
struct stud_node *head,*tail, *p;
int num, score;
char name[20];
int size = sizeof(struct stud_node);
head=tail=NULL;
scanf("%d", &num);
while(num != 0){
scanf("%s%d",name,&score);
p=(struct stud_node*)malloc(size);
p->num=num;
strcpy(p->name,name);
p->score=score;
p->next=NULL;
if(head==NULL)
head=p;
else
tail->next=p;
tail=p;
scanf("%d",&num);
}
for(p=head; p!=NULL; p=p->next)
printf("%d %s %d\n", p->num,p->name,p->score);
}
本回答被网友采纳