Array

Pages: 12
Hello I have a problem with this task:

Function 1 by iteration: input (n, a)
There are elements of the array of keyboard are read.
2 by means of iteration function: output (n, a)
It is formatted to display the elements of the array on the screen.
3 function using iteration: copy (a, start number, a, b, target)
Universal function for copying arrays
There is a section of the array a (number of elements, first starting with the index) in the
Array b is copied from the target index. Example: a: 1 4 6 8 2 9 b: 1 0 2 3 4 5 6
                  Result of copy (a, 1.3, b, 2) b: 1 0 4 6 8 5 6
Note: For space, the calling function is responsible.
4 function recursively: mix (m, a, n, b, c)
It, the elements of two ascending sorted array a (m elements) and b (n elements)
are mixed together and stored in an array c in ascending order.
Example: a 1 b 4 5 6 9 2 4 11 result in c 11. 1 2 4 4 5 6 9
This should be programmed as follows recursively.
If a contains no elements: copy by copy b to c, and you're done.
If b has no elements: a means to copy c copy and you're done.
Otherwise the maximum of all elements of a and b is to be determined.
This is a [m-1], or b [n-1], as both are arrays sorted.
Is the maximum of a [m-1], then
    Copy a [m-1] at the end of c and mix the remaining m-1 elements of a and n elements of b
    after c. This is done by the (recursive) calling mix (m-1, a, n, b, c)
B is the maximum of [n-1], then copy analog b [n-1], etc.
Example of an intermediate step, wherein the three elements have been copied 6 9 11 to c:
11th a 1 4 5 6 9 2 4 11 b and in c ----- 6 9
The maximum of the remaining elements of a and b is a [2] = 5 It is copied to c
                 a 1 4 5 6 2 4 11 9 11 b result in c. ---- 5 6 9
Then is only the remainder of a: 1 to 4 and the remainder of b: 2 4 in the first 4 elements of c
mix using a recursive call.



My Programm is looking so:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <iomanip>
#include "fkt_PROTO.h"

using namespace std;


int main()
{
    char auswahl;
    int anzahl;
    const int index=20;
    double inputRAY[index];

    cout << "Hi  \n"
        << " dummy text.\n"
        << "A. Array length.\n"
        << "B.  Array Enter.\n"
        << "C. Print out.\n"
        << "D. Copy.\n"
        << "E. Mix .\n";
    cin >> option;

    switch (option)
    {
    case 'a':
    case 'A':
        cout << "Length of Array?\n";
        cin >> anzahl;

    case 'B':
    case 'b':
        input(inputRAY,index,anzahl);
        cout << "Enter\n\n";
        cin.get();
        break;

    case 'C':
    case 'c':
        cout << "Print out Array? ...\n";
        output(inputRAY, anzahl);
        cout << "Happy ??\n";

    }

    return (0);
}


#include <iostream>
#include <iomanip>

using namespace std;

int output(double inputRAY[],int anzahl)
{
    for (int zaehler=0; zaehler<anzahl; zaehler++)
    {
    cout << "What is in this point " << zaehler << endl
         << "in Array" << zaehler+1 << ". is this:" <<endl
         << inputRAY[zaehler];
    }

    return (0);
}

double input(double array[], int, int);
double output(double array[], int);



I have an error for input and output .

Can somebody help me?
Last edited on
Hello guys I think I have solved some problems but I have still one error in my programm but I dont know what ´s the problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <iomanip>


using namespace std;

double input(double array[], int, int);
double output(double array[], int);
int main()
{
    char auswahl;
    int anzahl;
    const int index=20;
    double inputRAY[index];

    cout << "Praktikum 9 was geht ab\n"
        << "ich steh auf dummy texte.\n"
        << "A. Arraygroesse festlegen(folgt B).\n"
        << "B. Was geht ab Array eingabe.\n"
        << "C. Gib ma was aus.\n"
        << "D. Kopier mal digga.\n"
        << "E. Misch mal digga.\n";
    cin >> auswahl;

    switch (auswahl)
    {
    case 'a':
    case 'A':
        cout << "Wie groß soll dein Array sein?\n";
        cin >> anzahl;

    case 'B':
    case 'b':
        input(inputRAY,index,anzahl);
        cout << "eingabe abgeschlossen\n\n";
        cin.get();
        break;

    case 'C':
    case 'c':
        cout << "Dein Array soll ausgegeben werden? ...\n";
        output(inputRAY, anzahl);
        cout << "Zufrieden ??\n";

    }

    return (0);
}







double output(double inputRAY[],int anzahl)
{
    for (int zaehler=0; zaehler<anzahl; zaehler++)
    {
    cout << "Was geht ab digga an der stelle " << zaehler << endl
         << "im Array befindet sich die " << zaehler+1 << ". Zahl nämlich die:" <<endl
         << inputRAY[zaehler]<< endl << endl;
    }
    return (0);
}


The programm is showing me an error at line 34 .

What´s wrong?

And can somebody tell me , how I can do this:

4 function recursively
Last edited on
Hello,

The reason for the error at line 34 is missing definition; you haven't defined input(double array[], int, int).
I have done now this , but it´s still not working:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <iomanip>


using namespace std;

double input(double array[], int, int);
double output(double array[], int);
input(double array[], int, int);
int main()
{
    char auswahl;
    int anzahl;
    const int index=20;
    double inputRAY[index];

    cout << "Praktikum 9 was geht ab\n"
        << "ich steh auf dummy texte.\n"
        << "A. Arraygroesse festlegen(folgt B).\n"
        << "B. Was geht ab Array eingabe.\n"
        << "C. Gib ma was aus.\n"
        << "D. Kopier mal digga.\n"
        << "E. Misch mal digga.\n";
    cin >> auswahl;

    switch (auswahl)
    {
    case 'a':
    case 'A':
        cout << "Wie groß soll dein Array sein?\n";
        cin >> anzahl;

    case 'B':
    case 'b':
        input(inputRAY,index,anzahl);
        cout << "eingabe abgeschlossen\n\n";
        cin.get();
        break;

    case 'C':
    case 'c':
        cout << "Dein Array soll ausgegeben werden? wichser...\n";
        output(inputRAY, anzahl);
        cout << "Zufrieden ??\n";

    }

    return (0);
}







double output(double inputRAY[],int anzahl)
{
    for (int zaehler=0; zaehler<anzahl; zaehler++)
    {
    cout << "Was geht ab digga an der stelle " << zaehler << endl
         << "im Array befindet sich die " << zaehler+1 << ". Zahl nämlich die:" <<endl
         << inputRAY[zaehler]<< endl << endl;
    }
    return (0);
}


Please help me.
Last edited on
TheGrayWolf wrote:
Hello,

The reason for the error at line 34 is missing definition; you haven't defined input(double array[], int, int).


You still haven't defined your input function. You need to define that before you're allowed to call it. Once you write a definition for input, similar to how you defined output, everything should work.

Note: It helps us figure out issues if you include any compiler errors that you're having.
Can you Tell me how I can define the Input?

I have Problems with it.
Last edited on
Well, typically input functions consist of displaying a message to the user to enter some data, and storing it in a variable. You're using an array, and I assume "anzahl" means something along the lines of total number of values to enter in the array. Since that's being passed, the maximum size of the array, and the array itself, you have more than enough. Typicall you start with the for loop that loops from 0 til "anzahl - 1" and allows the user to enter values into the array at each of those locations.

When you're done in the function, the array will retain the information the user put in so that it can be used in other functions, like output. A quick example (in English):
1
2
3
4
5
6
7
double input(double array[], int max, int n) {
   for (int i = 0; i < (n - 1); i ++) {
      std::cout << "Please enter a decimal for value " << i + 1 << ": ";
      std::cin >> array[i];
   }
   return 0; // Not sure why the function is supposed to return a double
}
Hello people I added your idea in my programm but it isnt

still working .


#include <iostream>
#include <iomanip>


using namespace std;

double input(double array[], int, int);
double output(double array[], int);
double input(double array[], int max, int n) {
for (int i = 0; i < (n - 1); i ++) {
std::cout << "Please enter a decimal for value " << i + 1 << ": ";
std::cin >> array[i];
int main()
{
char auswahl;
int anzahl;
const int index=20;
double inputRAY[index];

cout << "Praktikum 9 was geht ab\n"
<< "ich steh auf dummy texte.\n"
<< "A. Arraygroesse festlegen(folgt B).\n"
<< "B. Was geht ab Array eingabe.\n"
<< "C. Gib ma was aus.\n"
<< "D. Kopier mal digga.\n"
<< "E. Misch mal digga.\n";
cin >> auswahl;

switch (auswahl)
{
case 'a':
case 'A':
cout << "Wie groß soll dein Array sein?\n";
cin >> anzahl;

case 'B':
case 'b':
input(inputRAY,index,anzahl);
cout << "eingabe abgeschlossen\n\n";
cin.get();
break;

case 'C':
case 'c':
cout << "Dein Array soll ausgegeben werden? wichser...\n";
output(inputRAY, anzahl);
cout << "Zufrieden ??\n";

}

return (0);
}




Or did I do something wrong?
Hello all experts around here. Can somebody perhaps Show me a New Way to solve this task?
Because I think my Way is a Little Tricky

closed account (3qX21hU5)
You are doing fine, your problem is that you don't totally grasp how functions work. I would recommend you read the tutorial on the website it might help a bit http://www.cplusplus.com/doc/tutorial/functions/

Here is a quick example but I recommend reading more into functions.

When you declare a function like you did before when you had your output function right. You need to declare a declaration (If your definition is below main in a single source program) and a definition. Like this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
double output(double array[], int);        // The function declaration

int main()
{
    // Your main code here
}

double output(double inputRAY[],int anzahl)        // The function definition
{
    for (int zaehler=0; zaehler<anzahl; zaehler++)
    {
    cout << "Was geht ab digga an der stelle " << zaehler << endl
         << "im Array befindet sich die " << zaehler+1 << ". Zahl nämlich die:" <<endl
         << inputRAY[zaehler]<< endl << endl;
    }
    return (0);
}


What the definition does it tell the program what the function is suppose to do. Now the reason yours didn't work is because you need to create a definition for the input function, and the previous post you deleted the output definition.
Ok here is my programm .

Can you correct please the programm because I really dont understand what I have to do.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <iomanip>


using namespace std;

double output(double array[], int);
int main()
{
    char auswahl;
    int anzahl;
    const int index=20;
    double inputRAY[index];

    cout << "Praktikum 9 was geht ab\n"
        << "ich steh auf dummy texte.\n"
        << "A. Arraygroesse festlegen(folgt B).\n"
        << "B. Was geht ab Array eingabe.\n"
        << "C. Gib ma was aus.\n"
        << "D. Kopier mal digga.\n"
        << "E. Misch mal digga.\n";
    cin >> auswahl;

    switch (auswahl)
    {
    case 'a':
    case 'A':
        cout << "Wie groß soll dein Array sein?\n";
        cin >> anzahl;

    case 'B':
    case 'b':
        input(inputRAY,index,anzahl);
        cout << "eingabe abgeschlossen\n\n";
        cin.get();
        break;

    case 'C':
    case 'c':
        cout << "Dein Array soll ausgegeben werden? wichser...\n";
        output(inputRAY, anzahl);
        cout << "Zufrieden ??\n";

    }

    return (0);
}







double output(double inputRAY[],int anzahl)
{
    for (int zaehler=0; zaehler<anzahl; zaehler++)
    {
    cout << "Was geht ab digga an der stelle " << zaehler << endl
         << "im Array befindet sich die " << zaehler+1 << ". Zahl nämlich die:" <<endl
         << inputRAY[zaehler]<< endl << endl;
    }
    return (0);
}


And I have also a problem with this task.

4 function recursively: mix (m, a, n, b, c)
It, the elements of two ascending sorted array a (m elements) and b (n elements)
are mixed together and stored in an array c in ascending order.
Example: a 1 b 4 5 6 9 2 4 11 result in c 11. 1 2 4 4 5 6 9
This should be programmed as follows recursively.
If a contains no elements: copy by copy b to c, and you're done.
If b has no elements: a means to copy c copy and you're done.
Otherwise the maximum of all elements of a and b is to be determined.
This is a [m-1], or b [n-1], as both are arrays sorted.
Is the maximum of a [m-1], then
Copy a [m-1] at the end of c and mix the remaining m-1 elements of a and n elements of b
after c. This is done by the (recursive) calling mix (m-1, a, n, b, c)
B is the maximum of [n-1], then copy analog b [n-1], etc.
Example of an intermediate step, wherein the three elements have been copied 6 9 11 to c:
11th a 1 4 5 6 9 2 4 11 b and in c ----- 6 9
The maximum of the remaining elements of a and b is a [2] = 5 It is copied to c
a 1 4 5 6 2 4 11 9 11 b result in c. ---- 5 6 9
Then is only the remainder of a: 1 to 4 and the remainder of b: 2 4 in the first 4 elements of c
mix using a recursive call.

How should I do this?

The 3 Task I did so:
using std::end;
using std::begin;

std::vector<int> a{1,4,6,8,2,9},
b{1,0,2,3,4,5,6};

//
std::copy( begin(a)+1, begin(a)+3+1, begin(a)+2 ); // Das +1 bei Ende, weil [Anfang,Ende)

std::copy( begin(b), end(b), std::ostream_iterator<int>(std::cout, ", "));
Is there a good programmer who can help me with this task?

Because my nervse are at an end.

Please help me.
But now you are again missing the definition for the function input.

Is there a good programmer who can help me with this task?


The people who have been helping you are good programmers, and have given you good advice. Consider their advice more carefully.

I think you need to understand how functions work. Not providing a function definition is like having a cook book with a list of things in the table of contents, but no actual recipe on the relevant page. The table of contents is the declaration of the functions, and the recipe is the function definition. The compiler needs to know what code to execute when the function is called.

HTH
I think you Must ne Tell how I should define the Funktion Input .

I think you Must ne Tell how I should define the Funktion Input .

But Volatile Pulse did that for you. You just need to put it into your code.
#include <iostream>
#include <iomanip>


using namespace std;

double output(double array[], int);
double input(double array[], int max, int n) {
for (int i = 0; i < (n - 1); i ++) {
std::cout << "Please enter a decimal for value " << i + 1 << ": ";
std::cin >> array[i];
}
return 0; // Not sure why the function is supposed to return a double
}

int main()
{
char auswahl;
int anzahl;
const int index=20;
double inputRAY[index];

cout << "Praktikum 9 was geht ab\n"
<< "ich steh auf dummy texte.\n"
<< "A. Arraygroesse festlegen(folgt B).\n"
<< "B. Was geht ab Array eingabe.\n"
<< "C. Gib ma was aus.\n"
<< "D. Kopier mal digga.\n"
<< "E. Misch mal digga.\n";
cin >> auswahl;

switch (auswahl)
{
case 'a':
case 'A':
cout << "Wie groß soll dein Array sein?\n";
cin >> anzahl;

case 'B':
case 'b':
input(inputRAY,index,anzahl);
cout << "eingabe abgeschlossen\n\n";
cin.get();
break;

case 'C':
case 'c':
cout << "Dein Array soll ausgegeben werden? ...\n";
output(inputRAY, anzahl);
cout << "Zufrieden ??\n";

}

return (0);
}







double output(double inputRAY[],int anzahl)
{
for (int zaehler=0; zaehler<anzahl; zaehler++)
{
cout << "Was geht ab digga an der stelle " << zaehler << endl
<< "im Array befindet sich die " << zaehler+1 << ". Zahl nämlich die:" <<endl
<< inputRAY[zaehler]<< endl << endl;
}
return (0);
}
Is it so right?
Last edited on
So does it work now?

You are right I don't see why either function should return anything, unless you want to return some sort of success / fail value, which you can test in main to see if the function worked or not. For now the functions could be void.

Just a small point, move the definition of the input function after main, so it is using the same concept as the output function.
Can you Tell me how I can define the Funktion rekursive?


Please help me.
But why do you want a recursive function.

Recursive functions call themselves, and keep repeatedly executing themselves until a base case (an end condition) is reached.

They are good for calculating mathematical series, such as factorials.

I can't see how they would apply to this situation.
How should I then Mix the Arrays in the 4 function ?
Pages: 12