6.22 比较大小 oj 洗刷刷 1
来源:互联网 发布:linux mint 18安装 编辑:程序博客网 时间:2024/05/02 05:05
题目描述
声明一个类模板,利用它分别实现两个整数、浮点数和字符的比较,求出大数和小数。说明:在类模板外定义各成员函数。
输入
输入两个整数、两个浮点数和两个字符
输出
从大到小输出两个整数、两个浮点数和两个字符
样例输入
3 7
45.78 93.6
a A
样例输出
7 3
93.60 45.78
a A
#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;
声明一个类模板,利用它分别实现两个整数、浮点数和字符的比较,求出大数和小数。说明:在类模板外定义各成员函数。
输入
输入两个整数、两个浮点数和两个字符
输出
从大到小输出两个整数、两个浮点数和两个字符
样例输入
3 7
45.78 93.6
a A
样例输出
7 3
93.60 45.78
a A
#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;
}
0 0
- 6.22 比较大小 oj 洗刷刷 1
- 6,22 商品销售 洗刷刷 oj 1
- 6.28 洗刷刷 oj 继承 private protocted
- 6.27 洗刷刷 1 oj 运算符重载 复数之和 (3+4i)+(5-10i)
- 6.27 洗刷刷 oj 运算符的重载 2+
- 6.27 洗刷刷 oj 运算符重载 矩阵之和
- oj比较大小
- 洗刷刷,呜呜,刷刷
- OJ比较大小-类模板
- OJ 比较大小 类模版
- OJ比较大小-类模板
- 6.27 洗刷刷 oj 一个复数与一个double数 运算符重载
- 6.27 洗刷刷 oj Teacher(教师)类和一个Student(学生)类 运算符重载
- 洗刷刷OO三A
- 17周 oj 比较大小 类模板
- △【OJ】---Q---比较大小-类模板
- YTU-OJ- 比较大小-类模板
- OJ——比较大小-类模板
- 文本相似度算法(余弦定理)
- extern "c"
- PATBasic——1011. A+B和C (15)
- monoid之含义
- 堆排序
- 6.22 比较大小 oj 洗刷刷 1
- linux命令df
- Android数据存储
- html小知识
- Linux SPI总线和设备驱动架构之三:SPI控制器驱动
- 30分钟让你懂得正则表达式
- c++操作符重载
- Leetcode#12 Integer to Roman
- IO流之文件读写操作