//声明一个数组类
数据成员包括数组,数组中元素个数,成员函数包括构造函数,
求数组最大值函数,输出数组最大值函数,输出数组所有元素的函数等等
主函数中验证数组用的各函数的功能。
//声明一个数组类,数据成员包括数组,数组中元素个数,成员函数包括构造函数,
//求数组最大值函数,输出数组最大值函数,输出数组所有元素的函数等等
//主函数中验证数组用的各函数的功能。
#include<iostream>
using namespace std;
class Array_max
{
private:
int count;
int max;
int array[100];
public:
Array_max()
{
count = 0;
for (int i = 0 ; i<count; i++)
{
array[i] = 0;
}
}
void set_value();
void max_value();
void show_value();
};
void Array_max::set_value()
{
cout<<"输入数组个数:";
cin>>count;
cout<<"输入数组元素:";
for (int i = 0; i < count; i++)
{
cin>>array[i];
}
}
void Array_max::max_value()
{
max = array[0];
for (int i = 0; i<count; i++)
{
if (array[i]>max)
{
max = array[i];
}
}
}
void Array_max::show_value()
{
cout<<"max = "<<max;
}
int main()
{
cout<<endl;
Array_max arrmax;
arrmax.set_value();
arrmax.max_value();
arrmax.show_value();
}