声明一个类模板,利用它分别实现两个整数、浮点数和字符的比较,求出大数和小数。请用构造函数进行初始化。

声明一个类模板,利用它分别实现两个整数、浮点数和字符的比较,求出大数和小数。请用构造函数进行初始化。,第1张

CG系统作业题

以c++程序编写

#include
using namespace std;
template
class Compare
{public:
Compare(numtype a,numtype b)
{x=a;
y=b;}
numtype max()
{return (x>y)?x:y;}
numtype min()
{return (x private:
numtype x,y;
};
int main(){
int i,j;
double q,w;
char s,d;

cout<<"Please enter two integers:"< cin>>i>>j;
Compare cmp1(i,j);
cout<<"the max is : "< cout<<"the min is : "<

cout<<"Please enter two floating point numbers:"< cin>>q>>w;
Compare cmp2(q,w);
cout<<"the max is : "< cout<<"the min is : "<

cout<<"Please enter two characters:"< cin>>s>>d;
Compare cmp3(s,d);
cout<<"the max is : "< cout<<"the min is : "<


return 0;

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/673430.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-04-19
下一篇2022-04-19

发表评论

登录后才能评论

评论列表(0条)

    保存