#include<iostream>
using namespace std;
void Date(int a,int b)
{
double c,d;
c=a+b;
cout<<"两数之和为:c="<<c<<endl;
d=a*b;
cout<<"两数之积为:d="<<d<<endl;
}
void Date(double a,double b)
{
double c,d;
c=a+b;
cout<<"两数之和为:c="<<c<<endl;
d=a*b;
cout<<"两数之积为:d="<<d<<endl;
}
int main()
{
double x,y;
cout<<"请输入两个数:"<<endl;
cin>>x>>y;
Date(x,y);
return 0;
}
#include<iostream>
using namespace std;
template<typename T>
T Date(T a,T b)
{
T c,d;
c=a+b;
d=a*b;
return 0;
}
int main()
{
double x,y,m,n;
cout<<"请输入两个数:"<<endl;
cin>>x>>y;
m=x+y;
n=x*y;
cout<<"两数之和:m="<<m<<endl;
cout<<"两数之积:n="<<n<<endl;
return 0;
}
#include<iostream>
using namespace std;
template<typename T>
class Date_2
{
public:
Date_2(T a,T b);
T Add();
T Mul();
private:
T x,y;
};
template<typename T>
Date_2<T>::Date_2(T a,T b)
{x=a;y=b;}
template<typename T>
T Date_2<T>::Add()
{return x+y;}
template<typename T>
T Date_2<T>::Mul()
{return x*y;}
int main()
{
Date_2<int>Add2_1(3,4);
Date_2<double>Add2_2(1.1,2.0);
Date_2<int>Mul2_1(3,4);
Date_2<double>Mul2_2(1.1,2.0);
cout<<"两个数整数之和:"<<Add2_1.Add()<<endl;
cout<<"两个数双精度之和:"<<Add2_2.Add()<<endl;
cout<<"两个数整数之积:"<<Mul2_1.Mul()<<endl;
cout<<"两个数双精度之和:"<<Mul2_2.Mul()<<endl;
return 0;
}

被折叠的 条评论
为什么被折叠?



