C语言 用结构体、数组实现简单的成绩管理

1、定义一个长度为5的结构体数组保存4个学生的相关信息,结构体的成员应该包含三个部分,float型的score数组来保存两门成绩及总分,char型的name数组来保存姓名,char型的num数组来保存学号。
2、从键盘输入4个学生的成绩并计算其总分。 就是不会算这个总分
3、将学生的成绩进行从高到低的排序,并显示排序后的结果。

5、 再输入一个学生的成绩,将此成绩按照排序规律插入原学生成绩数组,显示插入后的结果。

那位好心人帮帮忙忙啊!!!

/*
姓名 : 胥立畅
胥立畅的学号 : 90889
胥立畅的英语成绩 : 90
胥立畅的编程成绩 : 87
姓名 : 李海燕
李海燕的学号 : 90890
李海燕的英语成绩 : 90
李海燕的编程成绩 : 78
姓名 学号 英语 编程 总成绩 平均成绩
胥立畅 90889 90.00 87.00 177.00 88.50
李海燕 90890 90.00 78.00 168.00 84.00
排序后:
姓名 学号 英语 编程 总成绩 平均成绩
胥立畅 90889 90.00 87.00 177.00 88.50
李海燕 90890 90.00 78.00 168.00 84.00
姓名 : 汪大海
汪大海的学号 : 90891
汪大海的英语成绩 : 78
汪大海的编程成绩 : 98
插入后:
姓名 学号 英语 编程 总成绩 平均成绩
胥立畅 90889 90.00 87.00 177.00 88.50
汪大海 90891 78.00 98.00 176.00 88.00
李海燕 90890 90.00 78.00 168.00 84.00
Press any key to continue
*/
#include <stdio.h>

struct student {
char name[10];
char num[20];
float score[4];
};

void Show(struct student *stu,int n) {
int i,j;
printf("姓名\t学号\t英语\t编程\t总成绩\t平均成绩\n");
for(i = 0; i < n; ++i) {
printf("%s\t%s\t",stu[i].name,stu[i].num);
for(j = 0; j < 4; ++j) printf("%.2f\t",stu[i].score[j]);
printf("\n");
}
}

void Sort(struct student *stu,int n) {
int i,j,k;
struct student t;
for(i = 0; i < n - 1; ++i) {
k = i;
for(j = i + 1; j < n; ++j) {
if(stu[k].score[2] < stu[j].score[2])
k = j;
}
if(k != i) {
t = stu[i];
stu[i] = stu[k];
stu[k] = t;
}
}
}

struct student Read(void) {
struct student stu;
printf("姓名 : ");
scanf("%s",stu.name);
printf("%s的学号 : ",stu.name);
scanf("%s",stu.num);
printf("%s的英语成绩 : ",stu.name);
scanf("%f",&stu.score[0]);
printf("%s的编程成绩 : ",stu.name);
scanf("%f",&stu.score[1]);
stu.score[2] = stu.score[0] + stu.score[1]; // 总成绩
stu.score[3] = stu.score[2] / 2.0f; // 平均成绩
return stu;
}

void Insert(struct student *stu,struct student astu,int n) {
int i,j;
for(i = 0; i < n; ++i) {
if(stu[i].score[2] < astu.score[2]) {
for(j = n; j > i; --j) stu[j] = stu[j - 1];
stu[i] = astu;
break;
}
}
if(i == n) stu[n] = astu;
}

int main() {
int i,n = 2;
struct student stu[10],tstu;
for(i = 0; i < n; ++i) stu[i] = Read();
Show(stu,n);
Sort(stu,n);
printf("排序后:\n");
Show(stu,n);
tstu = Read();
Insert(stu,tstu,n++);
printf("插入后:\n");
Show(stu,n);
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-04-11
我想把所有代码发给你但网站不允许只有发你邮箱了
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct student
{ int num;
char name[10];
char sex[2];
int age;
char department[10];
int scoreEnglish;
int scoreHistory;
int scoreComputer;
int scoreSoftware;
int scoreClanguage;
int sum;
};
相似回答