编写一个使用数组类模板Array对数组进行排序、求最大值和求元素和的程序,并采用相关数据进行测试。

#include"iostream"
#include"algorithm"
#include"string.h"
using namespace std;
template
class Array
{
	private:
		int length;
		ElemType *a;
	public:
		Array(){
			cout << "元素个数为:" << endl ;
			cin >> length ;
			a=new ElemType[length];
			cout << "请输入元素" << endl ;
			for(int i=0;i> a[i];
		}
		void Asort()
		{
			sort(a,a+length);
			cout << "sort finish" << endl ;
		}
		ElemType max(){
			return a[length-1];
		}
		ElemType sum(){
			int i=0;
			ElemType sum=0;
			while(iarray;
	array.Asort();
	cout << "the max=" << array.max() << endl ;
	cout << "the sum=" << array.sum() << endl ;
}

你可能感兴趣的:(C++)