C++:找出一个整型数组中最大值。

题目概述:
找出一个整型数组中最大值。
编程:
#include< iostream>
using namespace std;
class array_max //声明类
{
public:
void set_value(); //对数组元素设置
void max_value(); //找出数组最大值
void show_value(); //输出最大值
private:
int array[10]; //整型数组
int max; //max用来存放最大值
};
void array_max::set_value()//成员函数定义,向数组元素输入数值
{
int i;
for (i = 0; i < 10; i++)
{
cin >> array[i];
}
}
void array_max::max_value()//成员函数定义,找数组元素中最大值
{
int i;
max = array[0];
for (i = 0; i < 10; i++)
{
if (array[i] > max)
max = array[i];
}
}
void array_max::show_value()//成员函数定义,输出最大值
{
cout << “max=” << max << endl;
}
int main()
{
array_max num; //定义对象num
num.set_value();
num.max_value();
num.show_value();
return 0;
}
上机实践:
在这里插入图片描述

Guess you like

Origin blog.csdn.net/qq_50426849/article/details/120349811