「已注销」 2021-06-08 07:44 采纳率: 100%
浏览 38
已结题

求大佬用简单的c++帮我,求求了

 

  • 写回答

3条回答 默认 最新

  • 关注
    #include "stdio.h"
    #define N 2
    struct student{
    	int stuNo;
    	char stuName[20];
    	float kq;
    	float ktbx;
    	float pszy;
    	float ktbj;
    	float score;
    	float total;
    }stu[N];
    int main(){
    	//输入成绩 
    	for(int i=0;i<N;i++){
    		printf("请输入第%d个同学的学号、姓名、考勤、课堂表现、平时作业、课堂笔记、末考成绩(空格隔开)\n",i+1);
    		scanf("%d %s %f %f %f %f %f",&stu[i].stuNo,stu[i].stuName,&stu[i].kq,&stu[i].ktbx,&stu[i].pszy,&stu[i].ktbj,&stu[i].score);
    		stu[i].total=(stu[i].kq*0.3+stu[i].ktbx*0.3+stu[i].pszy*0.3+stu[i].ktbj*0.1)*0.3+stu[i].score*0.7;
    	}
    	//排序
    	for(int i = 0; i < N - 1; i++) {
            for(int j = 0; j < N - 1 - i; j++) {
            	// 相邻元素两两对比
                if(stu[j].total < stu[j+1].total) {
                	struct student temp;
                	//元素交换
                    temp = stu[j+1];       
                    stu[j+1] = stu[j];
                    stu[j] = temp;
                }
            }
        }
        printf("学号\t姓名\t总分\n");
        for(int i=0;i<N;i++){
        	printf("%d\t%s\t%.2f\n",stu[i].stuNo,stu[i].stuName,stu[i].total);
    	}
    	return 0;
    } 

    代码如上,万望采纳。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 5月15日

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗