求大佬帮写一个结构体按总分排序并输出的C语言程序,急急急!?

作者&投稿:赖唐 (若有异议请与网页底部的电邮联系)
#include <iostream>
using namespace std;

struct student {
int num; // 学号
char name[99]; // 名字
unsigned int yw;
unsigned int sx;
unsigned int yy;
unsigned int cyy;
unsigned int all;
};

// 读取数据
void reads(student arr[], int row) {
for (int i = 0; i < row; i++) {
cout << "学号: " << arr[i].num << "\t";
cout << "名字: " << arr[i].name << "\t";
cout << "语文: " << arr[i].yw << "\t";
cout << "数学: " << arr[i].sx << "\t";
cout << "英语: " << arr[i].yy << "\t";
cout << "编程: " << arr[i].cyy << "\t";
cout << "总分: " << arr[i].all << endl;
}
}

// 排序: 升序
void sorts(student arr[], int row) {
for (int l = 0; l < row - 1; l++) {
for (int i = 0; i < row - l - 1; i++) {
if (arr[i].all > arr[i + 1].all) {
student temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
}
}
}
}

int main() {

student arr[] = {
{105, "张三", 15, 23, 24, 19},
{541, "李四", 21, 54, 43, 65},
{324, "元宝", 45, 64, 65, 60},
{123, "赵二", 65, 33, 48, 65},
{897, "花花", 98, 76, 45, 87},
{314, "老王", 79, 87, 54, 10},
{641, "王五", 13, 65, 76, 98},
{654, "柳儿", 89, 26, 35, 78},
{845, "六石", 79, 75, 56, 12},
{212, "旺财", 56, 52, 76, 32},
{999, "雪芙", 45, 82, 55, 15},
{546, "王炸", 98, 82, 22, 54},
{319, "蘑菇", 35, 34, 43, 26},
};

int row = sizeof(arr)/sizeof(arr[0]);

// 计算总分
for (int i = 0; i < row; i++) {
arr[i].all = arr[i].yw + arr[i].sx + arr[i].yy + arr[i].cyy;
}

cout << "未排序:" << endl;
reads(arr, row);

cout << "\n\n已排序:" << endl;
sorts(arr, row);
reads(arr, row);

system("pause>nul");

return 0;
}

~

求大佬帮写一个结构体按总分排序并输出的C语言程序,急急急!?_百度知 ...
答:cout << "编程: " << arr[i].cyy << "\t";cout << "总分: " << arr[i].all << endl;} } // 排序: 升序 void sorts(student arr[], int row) { for (int l = 0; l < row - 1; l++) { for (int i = 0; i < row - l - 1; i++) { if (arr[i].all...

定义一个结构体类型的结构体数组stud,输入学生三门课成绩,然后按总分成 ...
答:stud[i].sum=stud[i+1].sum;stud[i+1].sum=t;strcpy(m,stud[i].name);strcpy(stud[i].name,stud[i+1].name);strcpy(stud[i+1].name,m);k=stud[i].num;stud[i].num=stud[i+1].num;stud[i+1].num=k;} printf("学号 姓名 总分 名次 \n");for(i=0;i<n;...

一个C语言的题目!关于结构体的!
答:(2)录入学生成绩(姓名、学号、语文、数学成绩,总分自动计算)(3)按总分排名次(4)按姓名查找某学生成绩(5)统计各课程的平均分、及格率、最高分、最低分(6)打印成绩表 */#include<stdio.h>#include<stdlib.h>#include<string.h>#define N 175typedef struct mark//定义成绩结构体{ double yuwen; double shux...

要求用c语言编写,将总分排序(由高到低),并按总分从高到低输出成绩表_百...
答:void sortmean(int num)//按学生平均分由小到大排序 { student temp;int i,j;int maxt,index;for(i=0;i<num-1;i++){ index=i;maxt=stu[i].score[0]+stu[i].score[1]+stu[i].score[2];for(j=i+1;j<num;j++){ if(stu[j].score[0]+stu[j].score[1]+stu[j].score[...

定义一个100位学生的结构体数组,按成绩从高到低进行排序,信息包括学号...
答:define N 100 typedef struct student { int id; //学号 char name[20]; //姓名 int gender; //性别(0代表男生,1代表女生)float score; //成绩 }stu;stu s[N];int main(){ int i;for(i=0;i<N;i++){ printf("请输入第%d个学生的学号:",i+1);scanf("%d",&s[i]...

如何用C语言编写用结构体完成N个学生M名课程的成绩排序?
答:这里是4名学生一门成绩的排序,不过中间还有生日,希望能给你带来点灵感吧!源代码如下:\x0d\x0a#include \x0d\x0astruct student_record \x0d\x0a{\x0d\x0a char name[8];\x0d\x0a struct birth\x0d\x0a {\x0d\x0a int year;\x0d\x0a int month;\x0d\x0a int day;\x0d\x...

用结构体完成N个学生M名课程的成绩排序 用C语言编写
答:students[100];struct student temp;int n=0;printf("请输入学生总数:\n");scanf("%d",&n);for(i=0;i<n;i++){scanf("%d %s %d %d %d",&students[i].stunum,students[i].stuname,&students[i].stuscore1,&students[i].stuscore2,&students[i].stuscore3);}scanf("%d"...

...求其平均值,总分,并排序(从大到小)。要求有分析
答:/*排序函数,参数为结构体数组和记录数*/void sort(ADDRESS t[],int n){ int i,j,flag; ADDRESS temp; /*临时变量做交换数据用*/ for(i=0;i<n;i++) { flag=0; /*设标志判断是否发生过交换*/ for(j=0;j<n-1;j++) if((strcmp(t[j].name,t[j+1].name))>0) /*比较大小*/ { flag...

学生成绩排序结构体排序 输入5个学生信息,并将平均成绩降序输出:_百度...
答:printf("输入第%d个学生的学号,姓名,两科成绩:\n",i+1);scanf("%d %c",&stud[i].num,&stud[i].name[0]);j=0;while(stud[i].name[j]!=' ')scanf("%c",&stud[i].name[++j]);stud[i].name[j]='\0';scanf("%d%d",&stud[i].xk1,&stud[i].xk2);stud[i].zf=...

用C语言编辑一个学生成绩管理系统
答:void sort(struct student *arr); /*函数声明,按总分排序*/ void find(struct student *arr); /*函数声明,查找某位学生信息*/ main(){ char selmenu; /*定义局部变量,用于记录用户选择的功能编号*/ struct student stud[N]; /*定义结构体数组,用于记录学生信息*/ do /*利...