Functions

7.3 - Function parameters


Functions can have parameters, which are the values you can pass to the function. For example, the function print has a parameter called text which is a string:

void print(std::string text)
{
    std::cout << text << std::endl;
}

In C++, you can have more than one function with the same name, as long as they have different parameter sets. So for example you can have another function called print which accepts an integer instead of a string. The appropriate function will then be called based on the argument.

Your task is to create functions called reverse, one which accept a string and one which accept an integer. The functions should return a string, never an integer, of the reversed input.

Sample input code

#include <iostream>

int main()
{
    std::cout << reverse("duwang") << std::endl;
    std::cout << reverse(420) << std::endl;
}

Sample output

gnawud
024
#include <string> // Create your functions here!