// 重载函数举例说明; 用一个sumofsquare函数,辨别是两个整数相加还是两个实数相加。就是先输入两个整数然后输出他们的和,然后再输入
// 再输入两个实数,然后输出他们的和;
#include<iostream>
//#include<iomanip>
using namespace std;
int sumofsquare(int x,int y)
{
return (x+y);
}
double sumofsquare(double x,double y)
{
return x+y;
}
int main()
{
int a,b;
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"a+b="<<sumofsquare(a,b)<<endl;
double c,d;
cout<<"c=";
cin>>c;
cout<<"d=";
cin>>d;
cout<<"c+d="<<sumofsquare(c,d)<<endl;
return 0;
}
// 再输入两个实数,然后输出他们的和;
#include<iostream>
//#include<iomanip>
using namespace std;
int sumofsquare(int x,int y)
{
return (x+y);
}
double sumofsquare(double x,double y)
{
return x+y;
}
int main()
{
int a,b;
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"a+b="<<sumofsquare(a,b)<<endl;
double c,d;
cout<<"c=";
cin>>c;
cout<<"d=";
cin>>d;
cout<<"c+d="<<sumofsquare(c,d)<<endl;
return 0;
}