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;
}
相关推荐
天雪浪子7 小时前
Python入门教程之逻辑运算符
开发语言·python
骄傲的心别枯萎7 小时前
RV1126 NO.16:通过多线程同时获取H264和H265码流
linux·c++·音视频·rv1126
落羽的落羽7 小时前
【C++】特别的程序错误处理方式——异常机制
开发语言·c++
空山新雨(大队长)8 小时前
C 语言第一课:hello word c
c++·c·exe
春蕾夏荷_7282977258 小时前
c++ 第三方库与个人封装库
c++·三方库
通达的K8 小时前
Java实战项目演示代码及流的使用
java·开发语言·windows
牵牛老人8 小时前
Qt C++ 复杂界面处理:巧用覆盖层突破复杂界面处理难题之一
数据库·c++·qt
云:鸢8 小时前
C语言链表设计及应用
c语言·开发语言·数据结构·链表
离越词9 小时前
C++day8作业
开发语言·c++·windows