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;
}
相关推荐
a东方青1 小时前
蓝桥杯 2024 C++国 B最小字符串
c++·职场和发展·蓝桥杯
XiaoyaoCarter3 小时前
每日一道leetcode
c++·算法·leetcode·职场和发展·二分查找·深度优先·前缀树
Blossom.1183 小时前
使用Python实现简单的人工智能聊天机器人
开发语言·人工智能·python·低代码·数据挖掘·机器人·云计算
da-peng-song3 小时前
ArcGIS Desktop使用入门(二)常用工具条——数据框工具(旋转视图)
开发语言·javascript·arcgis
galaxy_strive3 小时前
qtc++ qdebug日志生成
开发语言·c++·qt
TNTLWT3 小时前
Qt功能区:简介与安装
开发语言·qt
Darkwanderor3 小时前
c++STL-list的模拟实现
c++·list
Humbunklung4 小时前
Visual Studio 2022 中添加“高级保存选项”及解决编码问题
前端·c++·webview·visual studio
等等5434 小时前
Java EE初阶——wait 和 notify
java·开发语言
小乌龟不会飞4 小时前
gflags 安装及使用
c++·mfc·gflags 库