结构体数组按总分排序(使用结构体数组,将下列学生的数据按分数(由小到大)排序后显示到屏幕上)

:暂无数据 2026-09-01 00:30:02 :0

结构体数组按总分排序(使用结构体数组,将下列学生的数据按分数(由小到大)排序后显示到屏幕上)

各位老铁们,大家好,今天由我来为大家分享结构体数组按总分排序,以及使用结构体数组,将下列学生的数据按分数(由小到大)排序后显示到屏幕上的相关问题知识,希望对大家有所帮助。如果可以帮助到大家,还望关注收藏下本站,您的支持是我们最大的动力,谢谢大家了哈,下面我们开始吧!

本文目录

使用结构体数组,将下列学生的数据按分数(由小到大)排序后显示到屏幕上

#include《stdio.h》
#include《stdlib.h》
struct a{
char name;
char no;
int grade;
};
void sort(struct a );
main()
{
struct a b={{“a“,“001“,56},{“b“,“002“,34},{“c“,“003“,23}};
int i;
sort(b);
for(i=0;i《=2;i++)
printf(“%s,%s,%d\n“,b[i].name,b[i].no,b[i].grade);

system(“pause“);
return 0;
}
void sort(struct a m)
{
int i,pass;
struct a temp;
for(pass=1;pass《=2;pass++)
for(i=0;i《=1;i++)
if(m[i].grade》m[i+1].grade)
{
temp=m[i];
m[i]=m[i+1];
m[i+1]=temp;
}
}
信息没有读入,直接赋的值
把分给我吧,我缺分
以后一问题共同交流,我也刚学

C语言考试试题:定义一个100位学生的结构体数组,按成绩从高到低进行排序

我现写的一个,简洁明了,应该是符合你的口味的,测试完全通过
#include 《stdio.h》
#define N 100
typedef struct student
{
int id; //学号
char name; //姓名
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].id);
printf(“请输入第%d个学生的姓名:“,i+1);
scanf(“%s“,&s[i].name);
printf(“请输入第%d个学生的性别:“,i+1);
scanf(“%d“,&s[i].gender);
printf(“请输入第%d个学生的成绩:“,i+1);
scanf(“%f“,&s[i].score);
}
stu ss[N];
stu* p=ss;
for(i=0;i《N;i++)
ss[i]=s[i];
for(i=0;i《N-1;i++)
{
for(int j=i+1;j《N;j++)
{
if(ss[i].score《ss[j].score)
{
stu temp=*(p+i);
*(p+i)=*(p+j);
*(p+j)=temp;
}
}
}
printf(“所有学生的信息按成绩由高到低排名如下:\n“);
printf(“学号\t姓名\t性别\t成绩\n“);
for(i=0;i《N;i++)
{
printf(“%d\t%s\t%d\t%.1f\n“,(p+i)-》id,(p+i)-》name,(p+i)-》gender,(p+i)-》score);
}
return 0;
}

C语言用结构体存放学生成绩{姓名、英语、数学、C语言},按总分排名输出

定义结构体数组

typedef struct
{
    char name;
    int score;
    int total;
}STU;

以最多100个学生为例

#define N 100
STU s;

输入学生成绩。 这个可以灵活一些,

固定学生数, 或者输入学生数,或者以空学生名结束都可以

输入同时,计算总分,存到total里面。


随便什么排序方式,按照total的值,进行从大到小排序。

顺序输出。 

定义一个结构体数组,存放指定数目个学生的学号,姓名,语文,数学课的成绩及总分

弄过类似的

稍改如下:

参考:

#include《iostream》

using namespace std;

struct student

{

int number;

char name;

float score;

float total;

};

void Total(student s,int n)

{

 int  i;

 for( i=0;i《n;i++)

s[i].total=(s[i].score+s[i].score+s[i].score);

}

void smax(student s,int n)

{

 int i;

 float max0 = s.score;

 float max1 = s.score;

for( i=1;i《n;i++)

{

if(s[i].score》max0) max0 = s[i].score;

if(s[i].score》max1) max1 = s[i].score;

}

cout《《“语文最高分为:\n“;

for( i=0;i《n;i++)

if(s[i].score == max0)

cout《《s[i].number《《“ \t“《《s[i].name《《“\t“《《s[i].score《《“\t“《《s[i].score《《“\t“《《s[i].total《《endl;

cout《《“数学最高分为:\n“;

for( i=0;i《n;i++)

if(s[i].score == max1)

cout《《s[i].number《《“ \t“《《s[i].name《《“\t“《《s[i].score《《“\t“《《s[i].score《《“\t“《《s[i].total《《endl;

}

void order(student s,int n)

{

int i,j;

for(i=0;i《n-1;i++)

for(j=i+1;j《n;j++)

if(s[i].total》s[j].total)

{

student temper;

temper=s[i];

s[i]=s[j];

s[j]=temper;

}

cout《《“总分最高的为:\n“;

cout《《s[n-1].number《《“ \t“《《s[n-1].name《《“\t“《《s[n-1].score《《“\t“《《s[n-1].score《《“\t“《《s[n-1].total《《endl;

cout《《“the order of the score is:“《《endl;

cout《《“学号“《《“\t“《《“姓名“《《“\t“《《“语文“《《“\t“《《“数学“《《“\t“《《“总成绩“《《endl;

for( i=0;i《n;i++)

cout《《s[i].number《《“ \t“《《s[i].name《《“\t“《《s[i].score《《“\t“《《s[i].score《《“\t“《《s[i].total《《endl;

}

int main()

{

int i;

student s;

cout《《“enter the numer name and the score of course:“《《endl;

for( i=0;i《100;i++)

{

cin》》s[i].number》》s[i].name》》s[i].score》》s[i].score;

if(s[i].number == 0)

break;

}

Total(s,i);//求总分

smax(s,i);//单科最高分

order(s,i);//排序并输出两科最高分

return 0;

}

结构体数组定义的排序

#include “stdafx.h“
#include “stdio.h“
#include 《string.h》
#include 《stdlib.h》
#include 《conio.h》

void bubble_sort(int a,int n);

void bubble_sort(int a,int n)//n为数组a的元素个数
{
int i,j,temp,temp2;
for(j=0;j《n-1;j++)
for(i=0;i《n-1-j;i++)
{
if(a[i]《a[i+1])//数组元素大小按升序排列
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;

temp2=a[i];
a[i]=a[i+1];
a[i+1]=temp2;
}
}
}
int main()
{
int m = {{21,22,23,24},{90,80,98,99}};

int i;

for (i=0;i 《 4;i++)
{
printf(“输入 %d 号学生分数:\n\t\t “,m[i]);
scanf(“%d“,&m[i]);
}

bubble_sort(m,4);
for(i=0;i《4;i++)
{
printf(“%d,%d\n“,m[i],m[i]);
}
system(“PAUSE“);
}

C语言:生成20个学号姓名和5门成绩的结构体数组,不动其数据,用指针数组按平均成绩由高至低排序,咋写

(感觉略有难度)  题目没有要求计算和输出平均值,所以排序可以不求平均值而按五门总分进行,效果与求出平均分是一样的——

代码文本:

#include “stdio.h“

#include 《stdlib.h》

#include 《string.h》

#include “time.h“

#define N 20

struct stu{

int s;

char SN,NAME;

};

int main(int argc,char *argv){

int i,j,k;

struct stu A[N],*p[N],*q;

srand((unsigned)time(NULL));

for(i=0;i《N;i++){//随机生成学生信息

do{//随机生成8位学号且不重复

itoa(10000+rand()%10000,A[i].SN,10);

strcpy(A[i].SN,A[i].SN+1);

itoa(1000+rand()%1000,A[i].SN+4,10);

for(j=0;j《i;j++)

if(strcmp(A[i].SN,A[j].SN)==0)

break;

}while(j《i);

A[i].NAME=’S’,A[i].NAME=’T’,A[i].NAME=’U’;

A[i].NAME=(i+1)/10+’0’,A[i].NAME=(i+1)%10+’0’;

A[i].NAME=’\0’;

for(j=0;j《5;A[i].s[j++]=rand()%101);//随机生成成绩

}

for(i=0;i《N;p[i]=A+i++);//为指针数组赋值

for(i=0;i《N;i++){

for(k=i,j=k+1;j《N;j++)

if(p[k]-》s+p[k]-》s+p[k]-》s+p[k]-》s+p[k]-》s《

p[j]-》s+p[j]-》s+p[j]-》s+p[j]-》s+p[j]-》s)

k=j;

if(i-k)

q=p[i],p[i]=p[k],p[k]=q;//把平均成绩高的向前交换

printf(“%s\t%s\t“,p[i]-》SN,p[i]-》NAME);//输出学号姓名

for(j=0;j《5;printf(“%4d“,p[i]-》s[j++]));//输出原始成绩

putchar(’\n’);

}

return 0; 

}

一道c#关于结构体数组排序的题目

暂时不忙,就帮你写了下:

    class Program
    {
        static List《Student》 stuList = new List《Student》();
        static void Main(string args)
        {
          
            for (int i = 0; i 《 5; i++)
            {
                Student student=new Student();
                Console.WriteLine(“请输入学生姓名:“);
                student.Name = Console.ReadLine();
                Console.WriteLine(“请输入学生性别:“);
                student.Sex = Console.ReadLine();
                Console.WriteLine(“请输入学生语文成绩:“);
                student.Chinese = Convert.ToSingle(Console.ReadLine());
                Console.WriteLine(“请输入学生数学成绩:“);
                student.Math = Convert.ToSingle(Console.ReadLine());
                Console.WriteLine(“请输入学生英语成绩:“);
                student.EngLish = Convert.ToSingle(Console.ReadLine());
                student.Total = TotalSum(student.Chinese, student.Math, student.EngLish);

                stuList.Add(student);
            }

            Bubble();
            foreach (var item in stuList)
            {
                Console.WriteLine(string.Format(“学生姓名{0},总分为:{1} “, item.Name,item.Total));
            }
 
            Console.ReadLine();
        }

        //计算总分
        static float TotalSum(float chinese, float math, float engLish)
        {
            return chinese + math + engLish;
        }

        /// 《summary》
        /// 对学生总分排序
        /// 《/summary》
        static void Bubble()
        {
            Student temp = new Student();
            for (int i = stuList.Count; i 》 0; i--)
            {
                for (int j = 0; j 《 i - 1; j++)
                {
                    if (stuList[j].Total 《 stuList[j + 1].Total)
                    {
                        temp = stuList[j];
                        stuList[j] = stuList[j + 1];
                        stuList[j + 1] = temp;
                    }
                }
            }
        }

    }

    public class Student
    {
        public string Name { get; set; }

        public string Sex { get; set; }

        public float Chinese { get; set; }

        public float Math { get; set; }

        public float EngLish { get; set; }

        public float Total { get; set; }
    }

定义一个结构体数组,实现下面内容

#include using namespace std; int A,B; struct student { int num; char name; char cou; double sum; double ave; double score; }stu; void nav(int M,int N); void input(student stu,int M,int N); void work(student ...

如果你还想了解更多这方面的信息,记得收藏关注本站。

结构体数组按总分排序(使用结构体数组,将下列学生的数据按分数(由小到大)排序后显示到屏幕上)

本文编辑:admin

更多文章:


turtles歌曲(哪位大神有turtles(乌龟组合)的<谢谢>的歌词中文翻译 感激不尽)

turtles歌曲(哪位大神有turtles(乌龟组合)的<谢谢>的歌词中文翻译 感激不尽)

“turtles歌曲”相关信息最新大全有哪些,这是大家都非常关心的,接下来就一起看看turtles歌曲(哪位大神有turtles(乌龟组合)的的歌词中文翻译 感激不尽)!

2026年10月11日 10:00

java转义字符(java中的转义字符的作用是什么)

java转义字符(java中的转义字符的作用是什么)

其实java转义字符的问题并不复杂,但是又很多的朋友都不太了解java中的转义字符的作用是什么,因此呢,今天小编就来为大家分享java转义字符的一些知识,希望可以帮助到大家,下面我们一起来看看这个问题的分析吧!

2026年10月11日 09:40

金山铁路22号线(请问现在轨道交通22号线金山铁路是个什么情况据说9月28日就开通了啊~~~)

金山铁路22号线(请问现在轨道交通22号线金山铁路是个什么情况据说9月28日就开通了啊~~~)

“金山铁路22号线”相关信息最新大全有哪些,这是大家都非常关心的,接下来就一起看看金山铁路22号线(请问现在轨道交通22号线金山铁路是个什么情况据说9月28日就开通了啊~~~)!

2026年10月11日 09:10

repercussions(都是余波,repercussions和aftermath有什么区别啊)

repercussions(都是余波,repercussions和aftermath有什么区别啊)

今天给各位分享都是余波,repercussions和aftermath有什么区别啊的知识,其中也会对都是余波,repercussions和aftermath有什么区别啊进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

2026年10月11日 09:00

dropdownlist 绑定(DropDownList 绑定所有项 并 显示指定项)

dropdownlist 绑定(DropDownList 绑定所有项 并 显示指定项)

本篇文章给大家谈谈dropdownlist 绑定,以及DropDownList 绑定所有项 并 显示指定项对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

2026年10月11日 08:50

协方差计算公式(协方差的计算公式)

协方差计算公式(协方差的计算公式)

这篇文章给大家聊聊关于协方差计算公式,以及协方差的计算公式对应的知识点,希望对各位有所帮助,不要忘了收藏本站哦。

2026年10月11日 08:10

易语言网页api接口怎么调用(易语言,怎么读取网页json的api)

易语言网页api接口怎么调用(易语言,怎么读取网页json的api)

本篇文章给大家谈谈易语言网页api接口怎么调用,以及易语言,怎么读取网页json的api对应的知识点,文章可能有点长,但是希望大家可以阅读完,增长自己的知识,最重要的是希望对各位有所帮助,可以解决了您的问题,不要忘了收藏本站喔。

2026年10月11日 08:00

majority of(the majority of 和 a majority of的区别以及用法例句)

majority of(the majority of 和 a majority of的区别以及用法例句)

这篇文章给大家聊聊关于majority of,以及the majority of 和 a majority of的区别以及用法例句对应的知识点,希望对各位有所帮助,不要忘了收藏本站哦。

2026年10月11日 07:40

汉字机内码查询表(1个汉字的机内码是几位谢谢)

汉字机内码查询表(1个汉字的机内码是几位谢谢)

大家好,关于汉字机内码查询表很多朋友都还不太明白,不过没关系,因为今天小编就来为大家分享关于1个汉字的机内码是几位谢谢的知识点,相信应该可以解决大家的一些困惑和问题,如果碰巧可以解决您的问题,还望关注下本站哦,希望对各位有所帮助!

2026年10月11日 07:20

promote翻译(英语翻译倡导怎么说)

promote翻译(英语翻译倡导怎么说)

其实promote翻译的问题并不复杂,但是又很多的朋友都不太了解英语翻译倡导怎么说,因此呢,今天小编就来为大家分享promote翻译的一些知识,希望可以帮助到大家,下面我们一起来看看这个问题的分析吧!

2026年10月11日 06:30

最近更新

repercussions(都是余波,repercussions和aftermath有什么区别啊)
2026-10-11 09:00:05 浏览:0
dropdownlist 绑定(DropDownList 绑定所有项 并 显示指定项)
2026-10-11 08:50:04 浏览:0
热门文章

标签列表