YTU-OJ-Problem Q: A改错题--体检情况分析

Problem Q: A改错题--体检情况分析

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 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; 
} 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值