iterating and merging two arrays.

Not homework. I am doing exercises out of "C++ Programming: From Problem Analysis to Program Design"

I think I may be over thinking part of this problem.

Section of the problem I am going over says

d. Write the definition of the function copyGamma that sets the elements of the first row of inStock to gamma and the remaining rows of inStock to three times the previous row of inStock. Make sure that you prevent the function from modifying the elements of gamma....


looking for help > direction for solving this part of the problem.
Attempting to solve this with out vector objects (that's the next chapter)
Thanks in advance.

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
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>

using namespace std;

void setArrayZero(int len, int array[]);

void inputArray(int len, int array[]);

void doubleArray(int len1, int alpha[], int beta[]);

void copyGamma(int len, int array1[],int array2[], int len2);

int main(int argc, const char * argv[])
{
    int inStock[10][4];
    int alpha[20];
    int beta[20];
    int gamma[4] = {11,13,15,17};
    int delta[] = {3,5,2,6,10,9,7,11,1,8};

    
    setArrayZero(4, gamma);
    for (int i = 0; i < 4; i++) {
        cout << "set array zero " << i << "... "<< gamma[i] << endl; 
    }
    inputArray(20, alpha);
    for (int i = 0; i < 4; i++) {
        cout << "input array " << i << "... " << alpha[i] << endl;
    }

    doubleArray(20 , alpha, beta);
    for (int i = 0; i < 20; i++) {
        cout << "double Array  " << i << "... " << beta[i] << endl;
    }

    copyGamma(4, gamma, inStock, 10);
    for (int i = 0; i < 10; i++) {
        cout << "gama copy " << i << "... " << inStock[(int)i] << endl;
    }

    return 0;
}
//d. Write the definition of the function copyGamma that sets the elements of the first row of inStock to gamma and the remaining rows of inStock to three times the previous row of inStock. Make sure that you prevent the function from modifying the elements of gamma.
void copyGamma(int len, int array1[], int array2[], int len2){
    int temp = 0;
    for (int i = 0; i < len; i++) {
        array1[i] = array2[i];
    for (int k = i; k < len2; k++) {
        temp = array1[--k];
        array2[k] = temp * 2; 
        }
    }
}


//Write the definition of the function setZero that initializes any one- dimensional array of type int to 0.
void setArrayZero(int len, int array[]){

    for (int i = 0; i < len; i++) {
        array[i] = 0;
    }
}

//b. Write the definition of the function inputArray that prompts the user to input 20 numbers and stores the numbers into alpha.
void inputArray(int len, int array[]){
    int input;
    for (int i = 0; i < len; i++) {
        input = 0; 
        cout << "Please enter number " << i+1 << " out of 20" << endl;
        cin >> input;
        cout << endl;
        array[i] = input;
    }
}
//c. Write the definition of the function doubleArray that initializes the ele- ments of beta to two times the corresponding elements in alpha. Make sure that you prevent the function from modifying the elements of alpha.
void doubleArray(int len1, int alpha[], int beta[]){
    for (int i = 0; i < len1; i++) {
        beta[i] = alpha[i] * 2;
    }

}
> Not homework
$ dict homework
Studies or other preparatory work done prior to some activity; 
-- usually used of preparations for activities of significance 
or consequence for the performer



> Make sure that you prevent the function from modifying the elements of gamma
void copyGamma(int len, int array1[],int array2[], int len2);
¿what's gamma?


> copyGamma that sets the elements of the first row of inStock to gamma
> and the remaining rows of inStock to three times the previous row of inStock
Talking about unintuitive...
array2[k] = temp * 2; that's two times


By the way, ¿how does your title relate?
Topic archived. No new replies allowed.