C++类实现最大数的输出

/*
Description
输入n个数,找出最大的数并输出。

Input
输入n,并输入n个数。

Output
输出的最大的数,每个输出结果占一行。

Sample Input
10
1 2 3 4 5 6 7 8 9 10
Sample Output
10
*/
#include <iostream>
using namespace std;
class Q
{
public:
//此处声明需要的成员函数
    void set_value();
    double get_Max();
private:
    int n;
    int a[100];
};
//下面定义成员函数
void Q::set_value()
{
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
}
double Q::get_Max()
{
    for(int i=1; i<n; i++)
    {
        if(a[i]>a[0])
        {
            a[0]=a[i];
        }
    }
    return a[0];
}
//用main()函数测试,完成输入输出
int main()
{
    Q b1;
    b1.set_value();
    cout<<b1.get_Max()<<endl;
    return 0;
}




爽!奋斗

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值