[Basic C++] function overloading -1

[Basic C++] function overloading -1

  • 题目描述
  • 答题区域
  • 提交记录
  • 成绩报告
  • 排名情况
  • 标准答案
  • 相关讨论

出题

邮箱

贺子阳

1499677880@qq.com

评测

截止时间

实时评测

2018-03-27 10:00

空间限制

时间限制

32MB

1000ms


Description

写出3组Plus函数的声明与实现,类型分别为intdoublestring
主函数如下,注意只需要实现Plus函数和包含相关的头文件。

int main() {
int n;
  int a,b;
double c,d;
std::string str1,str2;
std::cin>>n;
while(n--)
{
std::cin>>a >> b ;
std::cin>>c >> d;
std::cin >> str1 >>str2;
std::cout <<myplus(a, b) << endl;
std::cout <<myplus(d, c) << endl;
std::cout <<myplus(str1, str2) << endl;
} 
return 0;
}

Sample Input

1
2 3
2.5 3.5
women day

Sample Output

5
6
womenday

Hint

PS:please add std:: before using the string type

标准答案:

 

  • framework.cpp

1

#include <iostream>

2

#include <string>

3

#include "source.h"

4

using std::endl; std::endl;

5

6

<span style="color:#75715e">// Function prototype</span>

7

<span style="color:#75715e">//int myplus(int a, int b);</span>

8

<span style="color:#75715e">//double myplus(double a, double b);</span>

9

<span style="color:#75715e">//std::string myplus(const std::string& a, const std::string& b);</span>

10

11

int main() { main() {

12

  int n;int n;

13

  int a,b;int a,b;

14

  double c,d;double c,d;

15

  std::string str1,str2;std::string str1,str2;

16

  std::cin>>n;std::cin>>n;

17

  while(n--)while(n--)

18

  {{

19

    std::cin>>a >> b ;  std::cin>>a >> b ;

20

    std::cin>>c >> d;  std::cin>>c >> d;

21

    std::cin >> str1 >>str2;  std::cin >> str1 >>str2;

22

    std::cout <<myplus(a, b) << endl;  std::cout <<myplus(a, b) << endl;

23

    std::cout <<myplus(d, c) << endl;  std::cout <<myplus(d, c) << endl;

24

    std::cout <<myplus(str1, str2) << endl;  std::cout <<myplus(str1, str2) << endl;

25

  } } 

26

  return 0;return 0;

27

}

28

  • source.h

  • framework.cpp

1

<span style="color:#75715e">// Problem#: 17678</span>

2

<span style="color:#75715e">// Submission#: 4634918</span>

3

<span style="color:#75715e">// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License</span>

4

<span style="color:#75715e">// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/</span>

5

<span style="color:#75715e">// All Copyright reserved by Informatic Lab of Sun Yat-sen University</span>

6

#include <iostream>

7

#include <cstring>

8

9

10

int myplus(int a,int b) myplus(int a,int b)

11

{

12

    return a+b;return a+b;

13

}

14

15

double myplus(double c,double d) myplus(double c,double d)

16

{

17

    return c+d;return c+d;

18

}

19

20

std::string myplus( std::string str1, std::string str2) myplus( std::string str1, std::string str2)

21

{

22

    return str1+str2;return str1+str2;

23

}                                 

24

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值