【问题描述】
编写一个函数模版,能够处理整数、实数、串类对象的大小比较,返回两个值中的最小者。为了能够处理字符数组存储的字符串的大小比较,则需要使用函数重载的形式。为了能够处理串类对象的大小比较,则需要对串类实现关系运算符’>‘或’<'的重载。
主函数如下,请勿修改:
int main(){
int x,y;
double a,b;
char c1[20],c2[20],c3[20],c4[20];
cin>>x>>y;
cout<<Min(x,y)<<endl;
cin>>a>>b;
cout<<Min(a,b)<<endl;
cin>>c1>>c2;
cout<<Min(c1,c2)<<endl;
cin>>c3>>c4;
String s1(c3),s2(c4);
cout<<Min(s1,s2)<<endl;
return 0;
}
#include <iostream>
#include <string,h>
using namespace std;
class String
{
public:
String(const char *p);
String();
String(const String &s);
friend bool operator < (const String &s1, const String &s2);//为什么要用bool类型呢?可以这样理解:大于号和小于号判断的都是“是否A比B大或A比B小,返回的结果自然是true or false”
friend ostream& operator &l