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;
}
相关推荐
黄贵根5 小时前
JavaScript实现教培行业意向登记系统
开发语言·javascript·ecmascript
2401_868534787 小时前
RTOS之RT-Thread & Linux:线程/进程管理与调度核心差异分析
c++·python
zzzll11117 小时前
Claude Code离线安装方案揭秘
开发语言·php
wling03018 小时前
vasp虚频计算-python脚本
开发语言·windows·python·vasp计算
郝学胜-神的一滴8 小时前
Qt 高级编程 040:按钮悬浮弹出滑块弹窗的完整攻略
开发语言·c++·qt·软件工程·用户界面
xrandzj9 小时前
Python面向对象编程入门:类、实例、初始化与封装实践
开发语言·python
DLYSB_10 小时前
API 网关流量洪峰与突发 CC 攻击:我用 Go 写了个“现场物理防御哨兵”,把故障响应压缩到秒级
开发语言·后端·golang·报警灯
雨田言炎12 小时前
四、关于Qt项目需要知道的
开发语言·笔记·qt
程序喵大人13 小时前
【C++进阶】STL算法与函数对象 - 02 sort为什么需要随机访问迭代器
开发语言·c++·算法
SomeB1oody13 小时前
【RustyML入门】2.6. 线性判别分析
开发语言·后端·机器学习·rust·教程