请编写一个函数maxofarray(atype*p,int count),该函数从一个数组中找出其中的最大元素,并且数组中可以存放多种数据类型的元素。
注意:部分源程序己存在文件test42_2.cpp中。
请勿修改主函数main和其他函数中的任何内容,仅在函数maxofarray的花括号中填写若干语句。
文件test42_2.cpp清单如下:
#include<iostream.h>
#include<string.h>
#include<conio.h>
template<class atype>
void maxofarray(atype* p,int count)
{
}
void main ()
{
int len=5;
char *p1;
cout<<"the char type array and it’s length is 5:\n";
cout<<"the array element is a b c d e\n";
p1=new char[len];
for (int i=0;i<len;i++)
p1[i]=’a’+i;
maxofarray(p1,len);
}
【参考答案】
void maxofarray(atype*p,int count) { for (int j=0;j<count-1......