C++,day0907

cs 复制代码
#include <iostream>

using namespace std;
struct stu
{
private:
    int num;
private:
    double score[32];

public:
    void setNum()
    {
        cout <<"请输入学生人数:";
        cin >>num;
    }
    void input()
    {
        cout<<"请输入学生的成绩:"<<endl;
        for(int i=0; i<num; i++)
        {
            cout<<"第"<<i+1<<"个学生成绩:";
            cin>>score[i];
        }
    }
    void sort()
    {
        double temp;
        int flag = 0;
        for(int i=1; i<num; i++)
        {
            flag =0;
            for(int j=0; j<num-i; j++)
            {
                if(score[j]<score[j+1])
                {
                    temp = score[j];
                    score[j] = score[j+1];
                    score[j+1] = temp;
                    flag = 1;
                }
            }
            if(0 ==flag)
                break;
        }
    }
    void show()
    {
        for(int i=0; i<num; i++)
        {
            cout <<score[i]<<" ";
        }
        cout <<endl;
    }
};
int main()
{
    stu s;
    s.setNum();

    s.input();

    s.sort();

    s.show();

    return 0;
}
相关推荐
o***Z44844 分钟前
JavaScript在Node.js中的内存管理
开发语言·javascript·node.js
毕设源码-邱学长1 小时前
【开题答辩全过程】以 基于Java企业人事工资管理系统为例,包含答辩的问题和答案
java·开发语言
颜*鸣&空2 小时前
QT程序实现串口通信案例
开发语言·qt
无限进步_2 小时前
C语言动态内存的二维抽象:用malloc实现灵活的多维数组
c语言·开发语言·数据结构·git·算法·github·visual studio
froginwe112 小时前
Maven 仓库概述
开发语言
二川bro3 小时前
Python在AI领域应用全景:2025趋势与案例
开发语言·人工智能·python
CoderYanger3 小时前
优选算法-队列+宽搜(BFS):72.二叉树的最大宽度
java·开发语言·算法·leetcode·职场和发展·宽度优先·1024程序员节
招摇的一半月亮3 小时前
P2242 公路维修问题
数据结构·c++·算法
疏狂难除4 小时前
随便玩玩lldb (二)
开发语言·后端·rust