diff --git a/pretext/Functions/FunctionOverloading.ptx b/pretext/Functions/FunctionOverloading.ptx index a94f135..508ae04 100644 --- a/pretext/Functions/FunctionOverloading.ptx +++ b/pretext/Functions/FunctionOverloading.ptx @@ -141,7 +141,61 @@ main() that are correct and only modifying one character in the best string so far. This is a type of algorithm in the class of ‘hill climbing' algorithms, that is we only keep the result if it is better than the previous one.

- + + + + +

+ Construct a C++ program that overloads a function called myfunct so it works + with either one or two integer parameters. Drag the blocks into the correct order on the right. +

+
+ + + #include <iostream> + using namespace std; + + + + + void myfunct(int n) { + cout << "1 parameter: " << n << endl; + } + + + void myfunct(int n) { + cout << "1 parameter: " << n << endl; + + + + + + void myfunct(int n, int m) { + cout << "2 parameters: " << n << " and " << m << endl; + } + + + void myfunct(int n) { + cout << "2 parameters: " << n << " and " << m << endl; + } + + + + + int main() { + + + + myfunct(4); + myfunct(5, 6); + + + + return 0; + } + + +