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;
}
相关推荐
zhangdaliangmvp7 分钟前
快速排序的学习理解:从基础分治到三路划分优化
c++·学习·算法
code2cat12 分钟前
Java高级篇之JDBC:连接数据库,完成查询、更新与事务
java·开发语言·数据库
cu14317 分钟前
细谈IT6563的具体功能与其应用
c语言·c++·单片机·嵌入式硬件
hzxxxz19 分钟前
PHP引擎两个高危漏洞复盘:计数顺序与旧地址缺陷的机理与处置清单
开发语言·php
马立杰21 分钟前
PHP 未授权 RCE 应急响应:CVE-2026-109618 CVE-2026-109619 排查与加固实战
android·开发语言·php
布莱克60539 分钟前
C++ 内存泄漏全解析:常见场景、成因与规避实践
开发语言·c++·内存泄露
jimy11 小时前
lvalue、xvalue、prvalue(一):三者的分类
开发语言·c++
老王IT1 小时前
C#语言基础语法介绍
开发语言·c#
校园安全大脑平台1 小时前
校园安全平台过等保二级,开发阶段要注意什么
开发语言·安全·php
只睡四小时1 小时前
端侧推理:face-api.js 首屏 92% 是白下载的
开发语言·javascript·人脸识别·ecmascript·tensorflow.js·face-api.js·端侧推理