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;
}
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;
}
相关文章推荐
- C++创建二叉树(一)
- C++:友元3(复数的加法)
- C++之路进阶——树链剖分/块状树(树的统计)
- C语言 calloc, malloc, realloc ,alloca以及 free的用法
- Windows 下使用命令行编译C/C++文件
- 定点数的表示
- 用editplus+gcc搭建C语言开发环境
- 中缀表达式
- 关于二维数组的翻转与旋转 低端实现
- 任务接口设计
- 头文件标准格式
- Atitit.java jna 调用c++ dll 的总结
- Atitit.java jna 调用c++ dll 的总结
- Atitit.java jna 调用c++ dll 的总结
- C++学习之const详解篇
- C++ 中 const 使用
- 修练8年C++面向对象程序设计之体会
- 修练8年C++面向对象程序设计之体会
- C++历史段错误
- C语言中有string吗?