Problem Q: A改错题--体检情况分析
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 187 Solved: 124
[ Submit][ Status][ Web Board]
Description
注:本题只需要提交标记为修改部分之间的代码,请按照C++方式提交。
某学校抽查同学的身体情况,以下是检测到的这些同学的体重和身高,分别输出体重和身高的最大值。
#include <stdio.h>
#include <iostream>
using namespace std;
template <class T>
class DistancePoint
{
public:
static T Maxvalue(T arr[], int n);
};
int main()
{
const int ARRSIZE=10;
int iArr[ARRSIZE];
double dArr[ARRSIZE];
int i;
for(i=0; i<ARRSIZE; i++)
cin>>iArr[i];
cout<<DistancePoint<int>::Maxvalue(iArr,ARRSIZE)<<endl;
for(i=0; i<ARRSIZE; i++)
cin>>dArr[i];
cout<<DistancePoint<double>::Maxvalue(dArr,ARRSIZE)<<endl;
return 0;
}
/*****修改的起始行******/
T DistancePoint<T>::Maxvalue(T arr[], int n)
{
int i;
int maxV = arr[0];
for(i=1; i<n; i++)
if(maxV<arr[i])
maxV= arr[i];
return maxV;
}
/*****修改的终止行*****/
Input
10名同学的体重和身高
Output
体重的最大值和身高的最大值
Sample Input
55 60 56 65 70 45 40 60 50 56
1.65 1.70 1.78 1.91 1.60 1.65 1.82 1.86 1.75 1.78
Sample Output
70
1.91
HINT
#include <stdio.h>
#include <iostream>
using namespace std;
template <class T>
class DistancePoint
{
public:
static T Maxvalue(T arr[], int n);
};
int main()
{
const int ARRSIZE=10;
int iArr[ARRSIZE];
double dArr[ARRSIZE];
int i;
for(i=0; i<ARRSIZE; i++)
cin>>iArr[i];
cout<<DistancePoint<int>::Maxvalue(iArr,ARRSIZE)<<endl;
for(i=0; i<ARRSIZE; i++)
cin>>dArr[i];
cout<<DistancePoint<double>::Maxvalue(dArr,ARRSIZE)<<endl;
return 0;
}
template <class T>
T DistancePoint<T>::Maxvalue(T arr[], int n)
{
int i;
double maxV = arr[0];
for(i=1; i<n; i++)
if(maxV<arr[i])
maxV= arr[i];
return maxV;
}