Debugging Informatlon for IAP Test3 O COMPILER STACK TRACE None PROGRAM EXECUTION STACK TRACE None INPUT OF THE TEST CASE 89765 4 3 2 1 0 -1 2 11 -2 3 10 4 -1 5 YOUR CODE'S OUTPUT Enter a list of up to 2e integers or -1 to end the list 2 8 9765 4 3 2 1 0 3 Enter value and position to insert: 8 9 7 6 5 4 3 2 1 0 4 Enter value to delete from the array: Value not found! 5 8 97 6 5 4 3 2 1 0 6 Enter value to append: 8 9 7 6 5 4 3 2 1 0 -1 THE CORRECT OUTPUT OF THE TEST CASE Enter a list of up to 20 integers or 2 8 97 6 5 4 3 2 1 0 3 Enter a value and a position to insert: 8 9 7 6 5 4 3 2 1 0 4 Enter a value to delete from the array: Value not found! 5 Enter a value to append: 8 9 7 6 5 4 3 2 1 0 -1 -1 to end the list 6 UNIX DIFF' OF CORRECT OUTPUT AND YOUR OUTPUT 3,6c3,5 < Enter value and position to insert: 8 9 7 6 5 4 3 2 1 0 < Enter value to delete from the array: Value not found! < 8 9 7 6 5 4 3 2 1 0 < Enter value to append: 8 9 7 6 5 4 3 2 1 0 -1 > Enter a value and a position to insert: 8 9 7 6 5 4 3 2 1 e > Enter a value to delete from the array: Value not found! > Enter a value to append: 8 9 7 6 5 4 3 2 1 0 -1 PRETTY DIFF This diff is colored to make it clear what parts of the output are wrong. Green indicates things in the correct output that you are mlssing, indicates things in your output that shouldn't be there. The - character refers to newlines, so the green - character refers a newline you are missing in your output and the red refers to a newline you need to remove from your output. 1 Enter a list of up to 20 integers or -1 to end the liste 2 897 6 5 4 3 2 1 0 d 3 Enter a value and a position to insert: 8 9 7 6 5 4 3 2 1 0 - Enter a value to delete from the array: Value not found! 5 8 976 5 4 3 2 1 0 d 6 Enter a value to append: 8 9 7 6 5 4 3 2 1 0 -1 d 4 7

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 error I am getting. The error seems to be I am missing the numbers 8,9,7,6543210. How can it be fixed?

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;
}

 

Debugging Informatlon for IAP Test3 O
COMPILER STACK TRACE
None
PROGRAM EXECUTION STACK TRACE
None
INPUT OF THE TEST CASE
89765 4 3 2 1 0 -1
2 11 -2
3 10
4
-1
5
YOUR CODE'S OUTPUT
Enter a list of up to 2e integers or -1 to end the list
2 8 9765 4 3 2 1 0
3 Enter value and position to insert: 8 9 7 6 5 4 3 2 1 0
4 Enter value to delete from the array: Value not found!
5 8 97 6 5 4 3 2 1 0
6 Enter value to append: 8 9 7 6 5 4 3 2 1 0 -1
THE CORRECT OUTPUT OF THE TEST CASE
Enter a list of up to 20 integers or
2 8 97 6 5 4 3 2 1 0
3 Enter a value and a position to insert: 8 9 7 6 5 4 3 2 1 0
4 Enter a value to delete from the array: Value not found!
5 Enter a value to append: 8 9 7 6 5 4 3 2 1 0 -1
-1 to end the list
6
UNIX DIFF' OF CORRECT OUTPUT AND YOUR OUTPUT
3,6c3,5
< Enter value and position to insert: 8 9 7 6 5 4 3 2 1 0
< Enter value to delete from the array: Value not found!
< 8 9 7 6 5 4 3 2 1 0
< Enter value to append: 8 9 7 6 5 4 3 2 1 0 -1
> Enter a value and a position to insert: 8 9 7 6 5 4 3 2 1 e
> Enter a value to delete from the array: Value not found!
> Enter a value to append: 8 9 7 6 5 4 3 2 1 0 -1
PRETTY DIFF
This diff is colored to make it clear what parts of the output are wrong. Green indicates things in the correct output that you are mlssing,
indicates things in your output that shouldn't be there.
The - character refers to newlines, so the green - character refers a newline you are missing in your output and the red refers to a newline you
need to remove from your output.
1 Enter a list of up to 20 integers or
-1 to end the liste
2 897 6 5 4 3 2 1 0 d
3 Enter a value and a position to insert: 8 9 7 6 5 4 3 2 1 0 -
Enter a value to delete from the array: Value not found!
5 8 976 5 4 3 2 1 0 d
6 Enter a value to append: 8 9 7 6 5 4 3 2 1 0 -1 d
4
7
Transcribed Image Text:Debugging Informatlon for IAP Test3 O COMPILER STACK TRACE None PROGRAM EXECUTION STACK TRACE None INPUT OF THE TEST CASE 89765 4 3 2 1 0 -1 2 11 -2 3 10 4 -1 5 YOUR CODE'S OUTPUT Enter a list of up to 2e integers or -1 to end the list 2 8 9765 4 3 2 1 0 3 Enter value and position to insert: 8 9 7 6 5 4 3 2 1 0 4 Enter value to delete from the array: Value not found! 5 8 97 6 5 4 3 2 1 0 6 Enter value to append: 8 9 7 6 5 4 3 2 1 0 -1 THE CORRECT OUTPUT OF THE TEST CASE Enter a list of up to 20 integers or 2 8 97 6 5 4 3 2 1 0 3 Enter a value and a position to insert: 8 9 7 6 5 4 3 2 1 0 4 Enter a value to delete from the array: Value not found! 5 Enter a value to append: 8 9 7 6 5 4 3 2 1 0 -1 -1 to end the list 6 UNIX DIFF' OF CORRECT OUTPUT AND YOUR OUTPUT 3,6c3,5 < Enter value and position to insert: 8 9 7 6 5 4 3 2 1 0 < Enter value to delete from the array: Value not found! < 8 9 7 6 5 4 3 2 1 0 < Enter value to append: 8 9 7 6 5 4 3 2 1 0 -1 > Enter a value and a position to insert: 8 9 7 6 5 4 3 2 1 e > Enter a value to delete from the array: Value not found! > Enter a value to append: 8 9 7 6 5 4 3 2 1 0 -1 PRETTY DIFF This diff is colored to make it clear what parts of the output are wrong. Green indicates things in the correct output that you are mlssing, indicates things in your output that shouldn't be there. The - character refers to newlines, so the green - character refers a newline you are missing in your output and the red refers to a newline you need to remove from your output. 1 Enter a list of up to 20 integers or -1 to end the liste 2 897 6 5 4 3 2 1 0 d 3 Enter a value and a position to insert: 8 9 7 6 5 4 3 2 1 0 - Enter a value to delete from the array: Value not found! 5 8 976 5 4 3 2 1 0 d 6 Enter a value to append: 8 9 7 6 5 4 3 2 1 0 -1 d 4 7
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 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