YTU 2437: C++ 习题 比较大小-类模板
来源:互联网 发布:b车黄金剃刀数据 编辑:程序博客网 时间:2024/06/13 08:48
2437: C++ 习题 比较大小-类模板
时间限制: 1 Sec 内存限制: 128 MB提交: 1144 解决: 805
题目描述
声明一个类模板,利用它分别实现两个整数、浮点数和字符的比较,求出大数和小数。说明:在类模板外定义各成员函数。
输入
输入两个整数、两个浮点数和两个字符
输出
从大到小输出两个整数、两个浮点数和两个字符
样例输入
3 745.78 93.6a A
样例输出
7 393.60 45.78a A
提示
前置代码及类型定义已给定如下,提交时不需要包含,会自动添加到程序前部
/* C++代码 */
#include <iostream>
#include <iomanip>
using namespace std;
template<class numtype>
class Compare
{
public:
Compare(numtype a,numtype b);
numtype max();
numtype min();
private:
numtype x,y;
};
主函数已给定如下,提交时不需要包含,会自动添加到程序尾部
/* C++代码 */
int main()
{
int i1,i2;
cin>>i1>>i2;
Compare<int> cmp1(i1,i2);
cout<<cmp1.max()<<" "<<cmp1.min()<<endl;
float f1,f2;
cin>>f1>>f2;
Compare<float> cmp2(f1,f2);
cout<<setiosflags(ios::fixed);
cout<<setprecision(2);
cout<<cmp2.max()<<" "<<cmp2.min()<<endl;
char c1,c2;
cin>>c1>>c2;
Compare<char> cmp3(c1,c2);
cout<<cmp3.max()<<" "<<cmp3.min()<<endl;
return 0;
}
迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……
#include <iostream>#include <iomanip>using namespace std;template<class numtype>class Compare{public: Compare(numtype a,numtype b); numtype max(); numtype min();private: numtype x,y;};template<class numtype>Compare<numtype>::Compare (numtype a,numtype b){ x=a; y=b;}template<class numtype>numtype Compare <numtype> ::max(){ return (x>y)?x:y;}template<class numtype>numtype Compare <numtype> ::min(){ return (x<y)?x:y;}int main(){ int i1,i2; cin>>i1>>i2; Compare<int> cmp1(i1,i2); cout<<cmp1.max()<<" "<<cmp1.min()<<endl; float f1,f2; cin>>f1>>f2; Compare<float> cmp2(f1,f2); cout<<setiosflags(ios::fixed); cout<<setprecision(2); cout<<cmp2.max()<<" "<<cmp2.min()<<endl; char c1,c2; cin>>c1>>c2; Compare<char> cmp3(c1,c2); cout<<cmp3.max()<<" "<<cmp3.min()<<endl; return 0;}
#include <iostream>#include <iomanip>using namespace std;template<class numtype>class Compare{public: Compare(numtype a,numtype b); numtype max(); numtype min();private: numtype x,y;};template<class numtype>Compare<numtype>::Compare (numtype a,numtype b){ x=a; y=b;}template<class numtype>numtype Compare <numtype> ::max(){ return (x>y)?x:y;}template<class numtype>numtype Compare <numtype> ::min(){ return (x<y)?x:y;}int main(){ int i1,i2; cin>>i1>>i2; Compare<int> cmp1(i1,i2); cout<<cmp1.max()<<" "<<cmp1.min()<<endl; float f1,f2; cin>>f1>>f2; Compare<float> cmp2(f1,f2); cout<<setiosflags(ios::fixed); cout<<setprecision(2); cout<<cmp2.max()<<" "<<cmp2.min()<<endl; char c1,c2; cin>>c1>>c2; Compare<char> cmp3(c1,c2); cout<<cmp3.max()<<" "<<cmp3.min()<<endl; return 0;}
- YTU 2437: C++ 习题 比较大小-类模板
- [YTU]_2437 (C++ 习题 比较大小-类模板)
- YTU-OJ- 比较大小-类模板
- C++ 习题 比较大小-类模板
- C++ 习题 比较大小-类模板
- YTU 2424: C语言习题 字符串比较
- YTU: C语言习题 字符串比较
- [YTU]_2424 C语言习题 字符串比较
- YTU-OJ-Problem L: 熟悉题型——自由设计(比较大小-类模板)
- YTU 2605: 熟悉题型——自由设计(比较大小-类模板)
- 2437比较大小类模板
- 比较大小-类模板
- 比较大小-类模板
- YTU-OJ-Problem C: C++习题 抽象基类
- 第十五周oj刷题——Problem I: C++ 习题 比较大小-类模板
- ACM~比较大小-类模板
- OJ比较大小-类模板
- ACM--类模板 比较大小
- 容器vs.虚拟机
- 2007年老文:HP总裁孙振耀退休时的信
- CardView 设置 selector
- SICK激光雷达LMS511笔记一
- Linux驱动开发必看详解神秘内核
- YTU 2437: C++ 习题 比较大小-类模板
- 获取安卓应用包名和入口 Activity
- 猫都能学会的Unity3D Shader入门指南(二)
- BZOJ 3679 数字之积 - 数位dp
- bzoj 2147 happiness
- 编译android源码4---ubuntu下载Android源代码
- Android中级篇之百度地图SDK v3.5.0-配置环境及发布[图解AndroidStudio下配置.so文件]
- Git初使用
- [BZOJ2038][2009国家集训队]小Z的袜子(hose)(莫队)