#include<iostream>
#include<iomanip>
#include<algorithm>
using namespace std;
template<class T>
class Data
{
private:
T value;
public:
Data():value(0){}
Data(T v):value(v){}
void setValue(T v){ value = v;}
T getValue(){return value;}
bool operator>(Data<T> b){ return value > b.value;} /*使用类模板对象时一定要显示指出模板实参*/
bool operator<(Data<T> b){return value < b.value;}
Data<T> operator+(const Data<T> b)
{
Data<T> c;
c.value = value + b.value;
return c;
}
friend ostream& operator<<(ostream &os, const Data<T> &s); /*若写引用必须用const, 否则不能写引用&*/
{
os << setprecision(2) << fixed << s.value;
return os;
} }; template<class T>
class GetResult
{
public:
static Data<T> getSum(Data<T> *arr, int num)
{
Data<T> sum(0);
for(int i = 0; i < num; i++)
sum.setValue(sum.getValue() + arr[i].getValue());
return sum;
}
static Data<T> getMax(Data<T> *arr, int num)
{
T Max = arr[0].getValue();
for(int i = 1; i < num; i++)
Max = max(Max, arr[i].getValue());
return Data<T>(Max);
}
static Data<T> getMin(Data<T> *arr, int num)
{
T Min;
Min = arr[0].getValue();
for(int i = 1; i < num; i++)
Min = min(Min, arr[i].getValue());
Data<T> m(Min);
return m;
} };
//append.cc
int main()
{
Data<int> iData[1001];
Data<double> dData[1001];
int cases, num;
char ch;
int u;
double v;
Data<int> a(10), b(20);
Data<double> c(3.14), d(-4.1);
cout<<"a + b = "<<(a + b)<<endl;
cout<<"max(a, b) = "<<(a > b ? a : b)<<endl;
cout<<"min(a, b) = "<<(a < b ? a : b)<<endl;
cout<<"c + d = "<<(c + d)<<endl;
cout<<"max(c, d) = "<<(c > d ? c : d)<<endl;
cout<<"min(c, d) = "<<(c < d ? c : d)<<endl;
cin>>cases;
for (int i = 0; i < cases; i++)
{
cin>>ch;
cin>>num;
for (int j = 0; j < num; j++)
{
if (ch == 'i')
{
cin>>u;
iData[j].setValue(u);
}
else if (ch == 'd')
{
cin>>v;
dData[j].setValue(v);
}
}
if (ch == 'i')
{
cout<<GetResult<int>::getMax(iData, num);
cout<<" "<<GetResult<int>::getMin(iData, num);
cout<<" "<<GetResult<int>::getSum(iData, num)<<endl;
}
else if (ch == 'd')
{
cout<<GetResult<double>::getMax(dData, num);
cout<<" "<<GetResult<double>::getMin(dData, num);
cout<<" "<<GetResult<double>::getSum(dData, num)<<endl;
}
}
return 0;
}

最新文章

  1. swift 闭包循环引用
  2. PHP检测移动设备类mobile detection使用实例
  3. linux 查找命令
  4. 【转】发布python的包至pypi服务器
  5. WSGI是一种编程接口,而uwsgi是一种传输协议
  6. 关于一点coding.net与git配合在AndroidStudio/Idea上的使用笔记个的
  7. 移动平台中 meta 标签的使用
  8. Recipes — Bottle 0.13-dev documentation
  9. 简陋的个人Vim使用命令
  10. JAVA 注解和反射
  11. docker 搭建 web 服务环境
  12. Objective-C不能以new开头命名属性
  13. 跨域资源共享CORS
  14. 深度学习之windows安装tensorflow
  15. 【2017-03-28】JS基础、DOM操作
  16. CentOS7时间和日期的同步 (chrony和)
  17. Python 编程快速上手 第十五章 保持时间,计划任务和启动程序
  18. 修改panabit web管理介面端口
  19. MySQL:SQL进阶
  20. Jarvis OJ-Reverse题目Writeup

热门文章

  1. [LeetCode] 151. Reverse Words in a String 翻转字符串中的单词
  2. [LeetCode] 216. Combination Sum III 组合之和 III
  3. 转载:Python Web开发最难懂的WSGI协议,到底包含哪些内容?
  4. linux awk的用法
  5. PHP设计模式 - 享元模式
  6. centos6.5上安装5.7版本的mysql
  7. 12 Cookie、Session和JSP基础
  8. [转帖]SpringBoot集成redisson分布式锁
  9. Robot Framework 读取控制面板安装的程序,判断某个程序是否已经安装
  10. Java开发笔记(一百一十九)AWT布局