Question

getting an error for the code below when attempting to compile . Not fully sure what...

getting an error for the code below when attempting to compile . Not fully sure what the error means and confused why I am getting the error. I know there are a of other logical errors but im just looking for the solution to this specific one right now.

/tmp/ccq2rdty.o: In function `main':
IntArrayPlay.cpp:(.text+0x42): undefined reference to `fillArray(int*, int&)'
IntArrayPlay.cpp:(.text+0x55): undefined reference to `displayArray(int*, int&)'
IntArrayPlay.cpp:(.text+0x114): undefined reference to `displayArray(int*, int&)'
IntArrayPlay.cpp:(.text+0x15f): undefined reference to `displayArray(int*, int&)'
collect2: error: ld returned 1 exit status

/* Working with arrays and functions
* Author:
* Last modified on:
* Known bug
*/
#include <iostream>

using namespace std;

const int CAPACITY = 20;

// displayArray - display the array on a single line separated by blanks.
void displayArray(int array[], int& numElems);
// @param: int array[] is an unordered array of integers
// @param: int numElems
// [Already implemented]

//ToDo: Declare a function fillArray that fills an int array with values entered
void fillArray(int array[], int& numElems);
// by the user. Stop reading when the user inputs -1 or you reach CAPACITY.
// @param: int array[] is an unordered array of integers when leaving this function
// @param: int& numberElements is the number of Elements in the array after function
// @returns void.

//ToDo: Declare a function that removes (i.e., deletes) the element
void deleteElement(int array[], int& numElems, int& target);
// removeElement - removes the element of the given index from the given array.
// @param: int array[] is an unordered array of integers
// @param: int numberElements
// @param: int position of element to delete
// @returns: true if delete was successful, false otherwise

//ToDo: Delcare a function that inserts the element in the given position
void insertElement(int array[], int& numElems, int& pos, int& target);
// insertElement - removes the element of the given index from the given array.
// @param: int array[] is an unordered array of integers
// @param: int numberElements
// @param: int position to insert into
// @param: int target to insert.
// @returns: true if insert was successful, false otherwise

//ToDo: Declare a function that searches for an element in the given array
bool searchElement(int array[], int& numElems, int searchval);
// searchElement - searches for the element in the given array.
// @param int array[] is an unordered array of integers
// @param int numberOfElements
// @param int target
// @returns index of element or -1 if not found.

int main()
{
// The NumArray can be partially filled, we use variable NumArrayElems to keep track of how many numbers
// have been stored in the array.
int array[CAPACITY];   // an int array with a given CAPACITY
int numElems = 0; // the array is initially empty
int searchval = 0;
int pos = 0;
int target = 0;

// 1. ToDo: Call your fillArray function to read in a sequence of integer values,
// separated by space, and ending with -1. Store the values in the NumArray array
fillArray(array, numElems);
  
// and the number of elements in NumArrayElems.
// Display the contents of the array afterwards
displayArray(array, numElems);


// 2. ToDo: Read in a value and position from the user. Call your insertElement function
cout << "Enter a value and a position to insert: ";
cin >> target >> pos;
  
// to insert the given value into the given position of the array
insertElement(array, numElems, pos, target);
// Display the contents of the array afterwards


// 3. ToDo: Read in a value and call your searchElement function
cout << "Please enter the value you would like to search: ";
cin >> searchval;
  
//searchElement(array, numElems, searchval);
// if the value is found, delete it from the array using your function
if (searchElement(array, numElems, searchval) == true)
deleteElement(array, numElems, pos);
  
else
cout << "Value not found!";
// if the value not found, print "Value not found in array"
  
  
// Display the contents of the array afterwards
displayArray(array, numElems);


// 5. TODO: Read in a value and call your insertElement function to append
cout << "Enter a value to append: ";
cin >> target;
  
insertElement(array, numElems, pos, target);
// a value to the end of the array
// Display the contents of the array afterwards
displayArray(array, numElems);
  
return 0;
}

//TODO: Implement all functions declared above.
//Don't forget to put precondition/postcondition comments under or over the function header.

// displayArray - displays the array
// precondition: int array[] is an unordered array of numElems integers.
// postcondition: array is displayed on the console on a single line separated by blanks.

void fillArray(int array[], double& numElems)
{
cout << "Please enter up to 20 non-negative whole numbers separated by space.\n" << "Mark the end of the input list with a negative number: \n";
int num;
int index;
cin >> num;
  
while (num >= 0 && index < CAPACITY)
{
array[index] = num;
index++;
cin >> num;
numElems = index;
}
}


void displayArray(int array[], int numElems)
{
for (int i = 0; i < numElems; i++)
cout << array[i] << " ";
cout << endl;
}


bool searchElement(int array[], int& numElems, int searchval)
{
bool result = false;
  
cout << "Enter a value to delete from the array: ";
cin >> searchval;
  
for(int i = 0; i < numElems; i++)
{
if (array[i] == searchval)
result = true;
}

return result;
}


void insertElement(int array[], int& numElems, int& pos, int& target)
{
for(int i = pos; i < numElems + 1; i++)
{
array[i+1] = array[i];
array[pos] = target;
}

}


void deleteElement(int array[], int& numElems, int& target)
{
int index = 0;
for(int i = 0; i < numElems; i++)
{
if(array[i] == target)
{
index = i;
for(int j = index; j < numElems; j++)
array[j] = array[j+1];

}
  
}

}

Homework Answers

Answer #1

If you have any doubts, please give me comment...

/* Working with arrays and functions

* Author:

* Last modified on:

* Known bug

*/

#include <iostream>

using namespace std;

const int CAPACITY = 20;

// displayArray - display the array on a single line separated by blanks.

void displayArray(int array[], int numElems);

// @param: int array[] is an unordered array of integers

// @param: int numElems

// [Already implemented]

//ToDo: Declare a function fillArray that fills an int array with values entered

void fillArray(int array[], int &numElems);

// by the user. Stop reading when the user inputs -1 or you reach CAPACITY.

// @param: int array[] is an unordered array of integers when leaving this function

// @param: int& numberElements is the number of Elements in the array after function

// @returns void.

//ToDo: Declare a function that removes (i.e., deletes) the element

void deleteElement(int array[], int &numElems, int target);

// removeElement - removes the element of the given index from the given array.

// @param: int array[] is an unordered array of integers

// @param: int numberElements

// @param: int position of element to delete

// @returns: true if delete was successful, false otherwise

//ToDo: Delcare a function that inserts the element in the given position

void insertElement(int array[], int &numElems, int pos, int target);

// insertElement - removes the element of the given index from the given array.

// @param: int array[] is an unordered array of integers

// @param: int numberElements

// @param: int position to insert into

// @param: int target to insert.

// @returns: true if insert was successful, false otherwise

//ToDo: Declare a function that searches for an element in the given array

bool searchElement(int array[], int numElems, int searchval);

// searchElement - searches for the element in the given array.

// @param int array[] is an unordered array of integers

// @param int numberOfElements

// @param int target

// @returns index of element or -1 if not found.

int main()

{

    // The NumArray can be partially filled, we use variable NumArrayElems to keep track of how many numbers

    // have been stored in the array.

    int array[CAPACITY]; // an int array with a given CAPACITY

    int numElems = 0;    // the array is initially empty

    int searchval = 0;

    int pos = 0;

    int target = 0;

    // 1. ToDo: Call your fillArray function to read in a sequence of integer values,

    // separated by space, and ending with -1. Store the values in the NumArray array

    fillArray(array, numElems);

    // and the number of elements in NumArrayElems.

    // Display the contents of the array afterwards

    displayArray(array, numElems);

    // 2. ToDo: Read in a value and position from the user. Call your insertElement function

    cout << "Enter a value and a position to insert: ";

    cin >> target >> pos;

    // to insert the given value into the given position of the array

    insertElement(array, numElems, pos, target);

    // Display the contents of the array afterwards

    // 3. ToDo: Read in a value and call your searchElement function

    cout << "Please enter the value you would like to search and delete: ";

    cin >> searchval;

    //searchElement(array, numElems, searchval);

    // if the value is found, delete it from the array using your function

    if (searchElement(array, numElems, searchval) == true)

        deleteElement(array, numElems, searchval);

    else

        cout << "Value not found!";

    // if the value not found, print "Value not found in array"

    // Display the contents of the array afterwards

    displayArray(array, numElems);

    // 5. TODO: Read in a value and call your insertElement function to append

    cout << "Enter a value to append: ";

    cin >> target;

    pos = numElems;

    insertElement(array, numElems, pos, target);

    // a value to the end of the array

    // Display the contents of the array afterwards

    displayArray(array, numElems);

    return 0;

}

//TODO: Implement all functions declared above.

//Don't forget to put precondition/postcondition comments under or over the function header.

// displayArray - displays the array

// precondition: int array[] is an unordered array of numElems integers.

// postcondition: array is displayed on the console on a single line separated by blanks.

void fillArray(int array[], int &numElems)

{

    cout << "Please enter up to 20 non-negative whole numbers separated by space.\n"

         << "Mark the end of the input list with a negative number: \n";

    int num;

    int index;

    cin >> num;

    while (num >= 0 && index < CAPACITY)

    {

        array[index] = num;

        index++;

        cin >> num;

        numElems = index;

    }

}

void displayArray(int array[], int numElems)

{

    for (int i = 0; i < numElems; i++)

        cout << array[i] << " ";

    cout << endl;

}

bool searchElement(int array[], int numElems, int searchval)

{

    bool result = false;

    for (int i = 0; i < numElems; i++)

    {

        if (array[i] == searchval)

            result = true;

    }

    return result;

}

void insertElement(int array[], int &numElems, int pos, int target)

{

    for (int i = numElems; i>pos; i--)

    {

        array[i] = array[i-1];

    }

    array[pos] = target;

    numElems++;

}

void deleteElement(int array[], int &numElems, int target)

{

    int index = 0;

    for (int i = 0; i < numElems; i++)

    {

        if (array[i] == target)

        {

            index = i;

            for (int j = index; j < numElems-1; j++)

                array[j] = array[j + 1];

            numElems--;

        }

    }

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
I'm not sure how to fix my code I keep getting an error with rhs.begin. I...
I'm not sure how to fix my code I keep getting an error with rhs.begin. I linked the header file and the test file, THESE TWO CANNOT be changed they have absolutely no errors in them. To clarify I ONLY need help with the copy constructor part. /* ~~~~~~~~~~~~list.cpp~~~~~~~~~~~~~~~*/ #include #include "list.h" using namespace std; Node::Node(string element) { data = element; previous = nullptr; next = nullptr; } List::List() { first = nullptr; last = nullptr; } List::List(const List& rhs)//...
Finish the code wherever it says TODO /**    * Node type for this list. Each...
Finish the code wherever it says TODO /**    * Node type for this list. Each node holds a maximum of nodeSize elements in an    * array. Empty slots are null.    */    private class Node {        /**        * Array of actual data elements.        */        // Unchecked warning unavoidable.        public E[] data = (E[]) new Comparable[nodeSize];        /**        * Link to next node.       ...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any type dynamic arrays (replace string by the template in all instances below). • The class should have: – A private member variable called dynamicArray that references a dynamic array of type string. – A private member variable called size that holds the number of entries in the array. – A default constructor that sets the dynamic array to NULL and sets size to 0....
Complete the java code as per the comments public class Sorting {    ///////////////////////////////////////////////    //...
Complete the java code as per the comments public class Sorting {    ///////////////////////////////////////////////    // STEP 1 -- Make sorting methods generic    ///////////////////////////////////////////////       /**    * Re-orders the contents given array using the insertion sort algorithm.    *    * @param data The array to be sorted.    */    //TODO: Make me generic to work on any kind of Comparable data!    public static void insertionSort(int[] data)    {        int insert; // temporary...
The working code: //import java.util.Hashtable; public class HashingExample1 {    private int[] hashTable = new int[10];...
The working code: //import java.util.Hashtable; public class HashingExample1 {    private int[] hashTable = new int[10];       public int hash(int ele){        return ele % this.hashTable.length;    }    public boolean insert(int ele){        int pos = hash(ele);        System.out.println("Hashing key " + pos);        if(this.hashTable[pos] == 0)            this.hashTable[pos] = ele;        else{            for(int i = pos + 1; i < this.hashTable.length; i++){                if(this.hashTable[i]...
C++, I am not able to get this program to function correctly, ie not launching at...
C++, I am not able to get this program to function correctly, ie not launching at all #include <iostream> #include <stdio.h> int insert(int num, int location) { int parentnode; while (location > 0) { parentnode =(location - 1)/2; if (num <= array[parentnode]) { array[location] = num; return; } array[location] = array[parentnode]; location = parentnode; } array[0] = num; } int array[100], n; using namespace std; main() { int choice, num; n = 0; while(1) { printf("1.Insert the element \n"); printf("2.Delete...
IN C++ PLEASE!!! What needs to be done is in the code itself where it is...
IN C++ PLEASE!!! What needs to be done is in the code itself where it is written TO DO List! #include<iostream> using namespace std; template<typename T> class DoubleList{​​​​​     class Node{​​​​​     public: T value; Node* next; Node* prev;         Node(T value = T(), Node* next = nullptr, Node* prev = nullptr){​​​​​             this->value = value;             this->next = next;             this->next = next;         }​​​​​     }​​​​​;     int size;     Node* head;     Node* tail; public:     DoubleList(){​​​​​         size = 0;         head = nullptr;     }​​​​​     int length(){​​​​​         return size;     }​​​​​...
Please use this template. In this exercise you are to use a vector to store integers...
Please use this template. In this exercise you are to use a vector to store integers entered by the user. Once you have filled the vector, ask the user for a value to search for. If found, remove the value from the vector, keeping all other values in the same relative order, and then display the remaining values. #include <iostream> #include <vector> #include <climits> using namespace std; //Fills vector with user input until user enters 0 (does not include 0...
my code has several functions; delete and backward functions are not working, rewrite the code for...
my code has several functions; delete and backward functions are not working, rewrite the code for both functions and check them in the main: #include<iostream> #include<cassert> using namespace std; struct nodeType {    int info;    nodeType *link; }; class linkedList { public:    void initializeList();    bool isEmptyList();    void print();    int length();    void destroyList();    void insertFirst(int newItem);    void insertLast(int newItem);    int front();    linkedList();    void copyList(const linkedList otherList);    void insertNewValue(int value);...
I need to get the Min and Max value of an array when a user inputs...
I need to get the Min and Max value of an array when a user inputs values into the array. problem is, my Max value is right but my min value is ALWAYS 0. how do i fix this? any help please!!! _________________________________________________________________________________________________ import java.util.Scanner; public class ArrayMenu{ static int count; static Scanner kb = new Scanner(System.in);             public static void main(){ int item=0; int[] numArray=new int[100]; count=0;       while (item !=8){ menu(); item = kb.nextInt();...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT