Getting errors when I run my c++ program. Below I have attached my code and the question My code #include using namespace std; const int CAPACITY=20; void displayArray(int array[], int numElements); void fillArray(int array[],int& numElements); bool removeElement(int array[],int& numberElements,int position); //ToDo: Delcare a function that inserts the element in the given position // insertElement - removes the element of the given index from the given array. bool insertElement(int array[],int& numberElements,int position,int target); //ToDo: Declare a funcxtion that searches for an element in the given array // searchElement - searches for the element in the given array. // @param int array[] is an unordered array of integers // @param int numberOfElements // @param int element // @returns index of element or -1 if not found. int searchElement(int array[],int numberOfElements,int element); 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 NumArray[CAPACITY]; // an int array with a given CAPACITY int NumArrayElems=0; // the array is initially empty, i.e., contains 0 elements    int position,target;    int search;    int element;    // 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 // and the number of elements in NumArrayElems. // Display the contents of the array afterwards    cout<<"Enter a list of up to 20 integers or -1 to end the list"<>target>>position;    insertElement( NumArray, NumArrayElems, position , target);    displayArray(NumArray,NumArrayElems); // 3. ToDo: Read in a value and call your searchElement function. // 4. if the value is found, delete it from the array using your deleteElement function // if the value not found, print "Value not found!" // Display the contents of the array afterwards cout<<"Enter value to delete from the array: ";    cin>>search; int index = searchElement( NumArray, NumArrayElems, search); if(index!=-1){        removeElement( NumArray, NumArrayElems,index);    } else{     cout<<"Value not found!"<>element; insertElement(NumArray,NumArrayElems,NumArrayElems,element); displayArray(NumArray,NumArrayElems); return 0; } //TODO: Implement all functions declared above. //Don't forget to put precondition/postcondition comments under or over the function header. //fillArray: it is used to fill the elements in the array //precondition: array[] and numelements //postcondition: inserts elements into the array void fillArray(int array[],int& numElements){    int ele;    do{        cin>>ele;        if(ele==-1){            break;        }        array[numElements++]=ele;    }while(numElements20){        return false;    }    else{        int i;    numberElements++;    for (i = numberElements; i >= position; i--)    array[i] = array[i - 1];    array[position ] = target;    }    return true;    } //romeveElement: remove an element at particular position //precondition: int array[] and int numberElem and postion //postcondition: return true if element is successfully removed else false. bool removeElement(int array[],int& numberElements,int position){    for(int i=position;i

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Getting errors when I run my c++ program. Below I have attached my code and the question

My code

#include <iostream>
using namespace std;

const int CAPACITY=20;

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


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


bool removeElement(int array[],int& numberElements,int position);


//ToDo: Delcare a function that inserts the element in the given position
// insertElement - removes the element of the given index from the given array.

bool insertElement(int array[],int& numberElements,int position,int target);


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

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 NumArray[CAPACITY]; // an int array with a given CAPACITY
int NumArrayElems=0; // the array is initially empty, i.e., contains 0 elements
   int position,target;
   int search;
   int element;

  
// 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
// and the number of elements in NumArrayElems.
// Display the contents of the array afterwards
   cout<<"Enter a list of up to 20 integers or -1 to end the list"<<endl;
   fillArray(NumArray,NumArrayElems);
   displayArray(NumArray,NumArrayElems);

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

// 3. ToDo: Read in a value and call your searchElement function.
// 4. if the value is found, delete it from the array using your deleteElement function
// if the value not found, print "Value not found!"
// Display the contents of the array afterwards
cout<<"Enter value to delete from the array: ";
   cin>>search;
int index = searchElement( NumArray, NumArrayElems, search);
if(index!=-1){
       removeElement( NumArray, NumArrayElems,index);
   }
else{
    cout<<"Value not found!"<<endl;
}

displayArray(NumArray,NumArrayElems);
  

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

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

//fillArray: it is used to fill the elements in the array
//precondition: array[] and numelements
//postcondition: inserts elements into the array
void fillArray(int array[],int& numElements){
   int ele;
   do{
       cin>>ele;
       if(ele==-1){
           break;
       }
       array[numElements++]=ele;
   }while(numElements<CAPACITY);
  
}

//insertElement - insert elements into the array at a particular postion
// precondition: int array[] is an unordered array of numElems integers postiton and target .
// postcondition: it return true if the element is inserted else false
bool insertElement(int array[],int& numberElements,int position,int target){
   if(position<0 or position>20){
       return false;
   }
   else{
       int i;
   numberElements++;
   for (i = numberElements; i >= position; i--)
   array[i] = array[i - 1];
   array[position ] = target;
   }
   return true;
  
}

//romeveElement: remove an element at particular position
//precondition: int array[] and int numberElem and postion
//postcondition: return true if element is successfully removed else false.
bool removeElement(int array[],int& numberElements,int position){
   for(int i=position;i<numberElements;i++){
       array[i]=array[i+1];
   }
   numberElements--;
   return true;
  
}

//searchElement: serches an element in the array.
//precondition: array[] and numberofElements and element
//postcondition: return the index of the search element
int searchElement(int array[],int numberOfElements,int element){
   for(int i=0;i<numberOfElements;i++){
       if(array[i]==element){
           return i;
       }
   }
   return -1;
}



// postcondition: array is displayed on the console on a single line separated by blanks.
void displayArray(int array[], int numElem)
{
for (int i = 0; i < numElem; i++)
cout << array[i] << " ";
cout << endl;
}

The test results must match exactly as shows below for the 4 tests that failed

A clearer version of the picture can be found here( http://www.mediafire.com/view/ghp6std8nbx0f5f/combine_images.jpg/file)

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Reference Types in Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education