fillArray problem

For some reason I keep getting the error that my fillArray was not being declared in the scope that I declared it in. Can anyone help by looking at my code and telling me what I did wrong?

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
#include <iostream>
using namespace std;
void fillarray(int a[], int size, int& num_used);
//Precondition:The declared size of array a is given by parameter size.
//Postcondition:Array a will contain a number of non-negative integers entered by the user.

void displayArray(int a[], int num_used);
//Precondition:Array a should exist
//Postcondition:Those num_integers in array a are displayed on screen in a single line in the order that they are stored in array a.

void find_max_min(int a[], int num_used, int& max_index, int& min_index);
//Precondition:The first parameter a is an array of integers, and the second parameter num_used represents the actual number of positions in a that are used to store valid integers.
//Postcondition:The third parameter max_index should contain the index position where the largest element appears.

int num_pass_grades(const int a[], int num_used);

int main()
{
        const int ARRAY_SIZE = 20;
        int a[ARRAY_SIZE];
        int num = 0;
        int x = -1, y = -1;


        fillArray(a, ARRAY_SIZE, num);
        cout <<"Now display the array that has just been entered:\n";
        displayArray(a, num);

        find_max_min(a, num, x, y);
        cout <<"\nNow display the max value in array a:\n";
        cout <<a[x]<< " first appears at index "<<x << endl;
        cout <<"\nNow display the min value in array a:\n";
        cout <<a[y]<< " first appears at index "<<y << endl;

        cout << "\nThere are " << num_pass_grades(a, num) << " scores >=60.\n";

return 0;
}          
Last edited on
fillArray is not fillarray.
When I changed it I got a completely different 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
#include <iostream>
using namespace std;
 
void fillArray(int a[], int size, int& num_used);
//Precondition:The declared size of array a is given by parameter size.
//Postcondition:Array a will contain a number of non-negative integers entered by the user.
 
void displayArray(int a[], int num_used);
//Precondition:Array a should exist
//Postcondition:Those num_integers in array a are displayed on screen in a single line in the order that they are stored in array a.
 
void find_max_min(int a[], int num_used, int& max_index, int& min_index);
//Precondition:The first parameter a is an array of integers, and the second parameter num_used represents the actual number of positions in a that are used to store valid integers.
//Postcondition:The third parameter max_index should contain the index position where the largest element appears.
 
int num_pass_grades(const int a[], int num_used);
 
int main()
{
        const int ARRAY_SIZE = 20;
        int a[ARRAY_SIZE];
        int num = 0;
        int x = -1, y = -1;
 
 
        fillArray(a, ARRAY_SIZE, num);
        cout <<"Now display the array that has just been entered:\n";
        displayArray(a, num);
 
        find_max_min(a, num, x, y);
        cout <<"\nNow display the max value in array a:\n";
        cout <<a[x]<< " first appears at index "<<x << endl;
        cout <<"\nNow display the min value in array a:\n";
        cout <<a[y]<< " first appears at index "<<y << endl;
 
        cout << "\nThere are " << num_pass_grades(a, num) << " scores >=60.\n";

return0; 
}

I got these problems:
/home/54yP4Q/ccQv3jDy.o: In function `main':
prog.cpp:(.text.startup+0x33): undefined reference to `fillArray(int*, int, int&)'
prog.cpp:(.text.startup+0x4f): undefined reference to `displayArray(int*, int)'
prog.cpp:(.text.startup+0x63): undefined reference to `find_max_min(int*, int, int&, int&)'
prog.cpp:(.text.startup+0xf2): undefined reference to `num_pass_grades(int const*, int)'
collect2: error: ld returned 1 exit status
Where are the implementations of those four functions?
the goal of the program is to use fillArray to get no more than 20 non negative integers (student test scores) and store them in an array and use display array to display it on screen. find_min_max is used to find the max value in the array and the min value in the array.
I got these problems:
/home/54yP4Q/ccQv3jDy.o: In function `main':
prog.cpp:(.text.startup+0x33): undefined reference to `fillArray(int*, int, int&)'
prog.cpp:(.text.startup+0x4f): undefined reference to `displayArray(int*, int)'
prog.cpp:(.text.startup+0x63): undefined reference to `find_max_min(int*, int, int&, int&)'
prog.cpp:(.text.startup+0xf2): undefined reference to `num_pass_grades(int const*, int)'
collect2: error: ld returned 1 exit status


You need to implement the above functions to get rid of this error.
now I am only getting these:
Lab10.cpp:(.text+0x6d): undefined reference to `find_max_min(int*, int, int&, int&)'
Lab10.cpp:(.text+0x114): undefined reference to `num_pass_grades(int const*, int)'
here's my code:
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 fillArray(int a[], int size, int& num_used);
//Precondition:The declared size of array a is given by parameter size.
//Postcondition:Array a will contain a number of non-negative integers entered by the user.

void displayArray(int a[], int num_used);
//Precondition:Array a should exist
//Postcondition:Those num_integers in array a are displayed on screen in a single line in the order that they are stored in array a.

void find_max_min(int a[], int num_used, int& max_index, int& min_index);
//Precondition:The first parameter a is an array of integers, and the second parameter num_used represents the actual number of positions in a that are used to store valid integers.
//Postcondition:The third parameter max_index should contain the index position where the largest element appears.


int main()
{       
        const int ARRAY_SIZE = 20;
        int a[ARRAY_SIZE];
       int num = 0;
        int x = -1, y = -1;
        int num_pass_grades(const int a[], int num_used);

        fillArray(a, ARRAY_SIZE, num);
        cout <<"Now display the array that has just been entered:\n";
        displayArray(a, num);

        find_max_min(a, num, x, y);
        cout << "\nNow display the max value in array a:\n";
        cout << a[x]<< " first appears at index "<< x << endl;
        cout << "\nNow display the min value in array a:\n";
        cout << a[y]<< " first appears at index "<< y << endl;

        cout << "\nThere are " << num_pass_grades(a, num) << " scores >=60.\n";

return 0;

}

void fillArray(int a[], int size, int& num_used)
{
        cout << "Please enter up to" << size  << "non-negative integers.\n";

        for (num_used; num_used < size; num_used++)
        {
                cin >> a[num_used];
        }
}

void displayArray (int a[], int num_used)
{

        int i = 0;

        for (i; i < num_used; i++)
        {
                cout << a[i] << "";
        }

        cout << endl;
}
/*
void find_max_min (int a[], int num_used, int& max_index, int& min_index)
{
        int i = 0;

        for (i; i < num_used; i++)
        {
                if(isupper(a[]))
                {
                        num_used[i] = max_index[i];
                }
                else
                {
                        num_used[i] = min_index[i];
                }
        }
}
still figuring this one out, not sure on this
*/

I've honestly never had this kind of problem so it's pretty frustrating
With this line from main

find_max_min(a, num, x, y);

you call a function you haven't implemented yet.So the error tells you that it can't find an implementation of the function you are calling.Same with the line

cout << "\nThere are " << num_pass_grades(a, num) << " scores >=60.\n";

To fix this,you need to implement those functions.If you are unsure of how exactly to implement them at this point,you can leave their body empty or comment out anything inside the function's body that you are unsure of.
even if I were to do that I'm really unsure of how to implement them, I'm pretty stumped..
Topic archived. No new replies allowed.