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;
}
相关推荐
傻乐u兔17 分钟前
C语音初阶————调试实用技巧2
c语言·开发语言
沛沛老爹25 分钟前
从Web到AI:行业专属Agent Skills生态系统技术演进实战
java·开发语言·前端·vue.js·人工智能·rag·企业转型
程农1 小时前
基于Java的报名系统
java·开发语言
yugi9878381 小时前
基于字典缩放的属性散射中心参数提取MATLAB仿真程序
开发语言·matlab
charlie1145141912 小时前
计算机图形学速通指南笔记(0)
c++·笔记·软件工程·计算机图形学·工程实践
小白学大数据2 小时前
绕过拼多多 App 反抓包机制的综合逆向解决方案
开发语言·爬虫·python·自动化
使者大牙2 小时前
【单点知识】 Python装饰器介绍
开发语言·数据库·python
带土12 小时前
2. C++ private、protected、public
开发语言·c++
我不是8神2 小时前
字节跳动 Eino 框架(Golang+AI)知识点全面总结
开发语言·人工智能·golang
古城小栈2 小时前
Rust复合类型 四大军阀:数、元、切、串
开发语言·后端·rust