您的位置:首页 > 编程语言 > C语言/C++

C++:重载函数1(和与连接)

2016-01-15 20:47 253 查看
C++:重载函数1(和与连接)

Time Limit(Common/Java):1000MS/3000MS Memory Limit:65536KByte

Total Submit:413 Accepted:266

Description

定义一个重载函数求二个数的和。将下面的程序填写完整。

#include<iostream>

using namespace std;

.............................

int main()

{

int a,b;

double c,d;

char e[100],f[100];

cin>>a>>b>>c>>d>>e>>f;

cout<<add(a,b)<<endl;

cout<<add(c,d)<<endl;

cout<<add(e,f)<<endl;

return 0;

}

Input

有3组数据,第1组为2个整数,第2组为2个实数,第3组为2个字符串,

Output

第1组、第2组数据中的和,第3组为2个字符串的连接。

Sample Input

56 52

52.45 46.53

ABC KLM

Sample Output

108

98.98

ABCKLM

代码块:

#include<iostream>

#include<string>

using namespace std;

template<typename T>

T add(T x,T y)

{

return x+y;

}

char *add(char *s1,char *s2)

{

return strcat(s1,s2);

}

int main()

{

int a,b;

double c,d;

char e[100],f[100];

cin>>a>>b>>c>>d>>e>>f;

cout<<add(a,b)<<endl;

cout<<add(c,d)<<endl;

cout<<add(e,f)<<endl;

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: