Pointer array

My program for class right now is asking me to create an array using pointers? I this is the first time we're learning pointers, and the only available material to study is through a few online links given by the professor. I'm confused about the set up of the program that we're given and asked to finish.

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
#include <iostream>
#include <string>
using namespace std;

// Prototypes
int create_array(int);
void enter_data();
double find_average();
double show_array(int,  int);

// main begins
int main()
{
        int *dyn_array;
        int students;
        float avrg;
        //int dyn_array;
        do
        {
                cout << "How many students will you enter? ";
                cin >> students;
        }while ( students <= 0 );
        dyn_array = create_array( students );
                //this function creates a dynamic array
                //and returns its pointer
/*      enter_data( dyn_array, students );
                //use 'pointer' notation in this function to
                //access array elements
                //accept only numbers 0-100 for movie seen
        avrg = find_average( dyn_array, students );
                //use 'pointer' notation in this function to
                //access array elements
*/

        cout << "The array is:" << endl << endl;
//      show_array( dyn_array, students);

        cout << endl;
//      cout << "The average is " << avrg << ".\n";

//      delete [] dyn_array;
        return 0;
}

/////////////////////////////////////////////
// create_array function
int create_array(int f_students) {
        int num_movies[f_students];

        for (int i = 1; i <= f_students; i++) {
                cout << "Enter number of movie(s) for student #" << i << ": " << endl;
                cin >> num_movies[i];
        }

}

/////////////////////////////////////////////
// enter_data function
void enter_data() {

}

/////////////////////////////////////////////
// find_average function
double find_average() {

}
/////////////////////////////////////////////
// show_array function
double show_array() {

}


I'm trying to figure out how to create this pointer array, since the declared pointer variable at the top of the main is *dyn_array, and then a little bit down the program is the call for the function create_array(students), this is being assigned to dyn_array again, but without the * being placed there. Is this a mistake?
I talked to some classmates, I think what I put inside the create_array() should go in enter_data(). I'm not sure still how to create the dynamic array and retrieve a pointer.
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
#include <iostream>
#include <string>
using namespace std;

// Prototypes
int *create_array(int);
void enter_data(int, int);
double find_average();
double show_array(int,  int);

// main begins
int main()
{
        int *dyn_array;
        int students;
        float avrg;
        do
        {
                cout << "How many students will you enter? ";
                cin >> students;
        }while ( students <= 0 );

        dyn_array = create_array( students );
                //this function creates a dynamic array
                //and returns its pointer
        enter_data( dyn_array, students );
/*              //use 'pointer' notation in this function to
                //access array elements
                //accept only numbers 0-100 for movie seen
        avrg = find_average( dyn_array, students );
                //use 'pointer' notation in this function to
                //access array elements
*/
        cout << "The array is:" << endl << endl;
//      show_array( dyn_array, students);

        cout << endl;
//      cout << "The average is " << avrg << ".\n";

//      delete [] dyn_array;
        return 0;
}

/////////////////////////////////////////////
// create_array function that creates a dynamic array
// and returns its pointer
int create_array(int f_students) {
        int *ptr = new int[f_students];
        return ptr;
}

/////////////////////////////////////////////
// enter_data function uses 'pointer' notation to access
// array elements access only number 0-100 for movies seen
void *enter_data(int *f_dyn_array, int f_students) {
        for (int i = 1; i <= f_students; i++) {
                cout << "Enter number of movie(s) for student #" << i 
                        << ": " << endl;
                //cin >> *f_dyn_array[i];
        }
}

/////////////////////////////////////////////
// find_average function
double find_average() {

}

/////////////////////////////////////////////
// show_array function
double show_array() {

}


Right now I'm unsure about how to create a new data entry function. Should it be a pointer function too?
Topic archived. No new replies allowed.