[C++类和对象的简单操作]面向对象程序设计上机练习六(类和对象)

来源:互联网 发布:node.js 实战 第二版 编辑:程序博客网 时间:2024/06/02 05:29

面向对象程序设计上机练习六(类和对象)
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description

用类成员函数完成5个整型数组元素的输入、从小到大排序、排序后数组元素的输出。

Input

输入5个数组元素。

Output

输出5个数组元素从小到大排序后的结果。(最后一个数后面既没有空格也没有换行)

Example Input

8 9 1 5 4

Example Output

1 4 5 8 9

#include<bits/stdc++.h>using namespace std;class node{public:    void Sort();    void Input();    void show()    {        for(int i = 0; i < 5; i++)        {            if(i) printf(" ");            printf("%d", a[i]);        }        printf("\n");    }private:    int a[10];};void node::Sort(){    sort(a, a + 5);}void node::Input(){    for(int i = 0; i < 5; i++)        scanf("%d", &a[i]);}int main(){    node t;    t.Input();    t.Sort();    t.show();}
阅读全文
0 0
原创粉丝点击