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;
}
相关推荐
Lhan.zzZ7 小时前
笔记_2026.4.28_004
c++·ide·笔记·qt
MATLAB代码顾问7 小时前
5大智能算法优化标准测试函数对比(Python实现)
开发语言·python
wuminyu8 小时前
专家视角看Java字节码加载与存储指令机制
java·linux·c语言·jvm·c++
万粉变现经纪人8 小时前
如何解决 pip install llama-cpp-python 报错 未安装 CMake/Ninja 或 CPU 不支持 AVX 问题
开发语言·python·开源·aigc·pip·ai写作·llama
清风明月一壶酒9 小时前
OpenClaw自动处理Word文档全流程
开发语言·c#·word
其实防守也摸鱼9 小时前
CTF密码学综合教学指南--第五章
开发语言·网络·笔记·python·安全·网络安全·密码学
木喃的井盖9 小时前
无锁队列细节
c++·工程
王老师青少年编程9 小时前
csp信奥赛C++高频考点专项训练之字符串 --【字符串基础】:输出亲朋字符串
c++·字符串·csp·高频考点·信奥赛·专项训练·输出亲朋字符串
WBluuue10 小时前
数据结构与算法:莫队(一):普通莫队与带修莫队
c++·算法
小郑加油10 小时前
python学习Day12:pandas安装与实际运用
开发语言·python·学习