Write an overloaded function that displays a character or a one-dimensional array. Provide an explanation for the output.

Demonstrate the function for all data options.

This is what I have.

What is the problem then?

#include <iostream> #include <ctime> #include <cstdlib> #include <conio.h> using namespace std; int show(int n) { srand(time(0)); int* m = new int[n]; for (int i=0; i<n; i++) { m[i] = rand()%10; cout << m[i] << " "; } cout << endl; return 0; } int main() { int n; cout << " Input size of the matrix: " << n << endl; cout << show(n) << endl; _getch(); } 

Help me please.

Closed due to the fact that off-topic participants cheops , aleksandr barakin , Streletz , Vartlok , zRrr 20 May '16 at 16:00 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - aleksandr barakin, Vartlok, zRrr
If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    The meaning of congestion is that functions can have different signatures with the same name, i.e. the compiler chooses what to call, based on a set of arguments.

    In your version of this, for example, functions

     void show(char c) { cout << "Symbol: " << c << endl; } void show(int* a, int n) { cout << "Array: "; for(int i = 0; i < n; ++i) cout << a[i] << ((i == n-1) ? "" : ", "); cout << endl; } 

    Well, when and what to call and what to transfer - I think, okay?

    • Clear. And how would the main function be? - nick
    • Enter an array, output using show, then the same with the symbol. Or with a hard-coded array and symbol - Harry