用C语言定义一个包含学生成绩(学号,姓名,成绩)的顺序表,读入相应的成绩信息来完成学生成绩表的创建。然后,(1)查找统计不及格的学生人数,(2)删除并用temp实现以学号升序方式逐行输出不及格的学生信息
时间: 2023-04-07 14:05:04 浏览: 82
可以回答这个问题。以下是代码示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_SIZE 100
typedef struct {
int id;
char name[20];
float score;
} Student;
typedef struct {
Student data[MAX_SIZE];
int length;
} SeqList;
void create(SeqList *list) {
printf("请输入学生人数:");
scanf("%d", &list->length);
for (int i = 0; i < list->length; i++) {
printf("请输入第%d个学生的学号、姓名、成绩:", i + 1);
scanf("%d%s%f", &list->data[i].id, list->data[i].name, &list->data[i].score);
}
}
int count_fail(SeqList list) {
int count = 0;
for (int i = 0; i < list.length; i++) {
if (list.data[i].score < 60) {
count++;
}
}
return count;
}
void delete_fail(SeqList *list) {
int i = 0;
while (i < list->length) {
if (list->data[i].score < 60) {
for (int j = i; j < list->length - 1; j++) {
list->data[j] = list->data[j + 1];
}
list->length--;
} else {
i++;
}
}
}
void sort_by_id(SeqList *list) {
for (int i = 0; i < list->length - 1; i++) {
for (int j = 0; j < list->length - 1 - i; j++) {
if (list->data[j].id > list->data[j + 1].id) {
Student temp = list->data[j];
list->data[j] = list->data[j + 1];
list->data[j + 1] = temp;
}
}
}
}
void print(SeqList list) {
printf("学号\t姓名\t成绩\n");
for (int i = 0; i < list.length; i++) {
printf("%d\t%s\t%.1f\n", list.data[i].id, list.data[i].name, list.data[i].score);
}
}
int main() {
SeqList list;
create(&list);
printf("不及格的学生人数:%d\n", count_fail(list));
delete_fail(&list);
sort_by_id(&list);
print(list);
return 0;
}
```
注意:这里的回答并不代表 CSDN 或 ChatGPT 的观点,仅仅是一个 AI 的角色扮演。
阅读全文