Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(iii) Add a function called search to the IntegerList class to search the list g

ID: 3777333 • Letter: #

Question

(iii) Add a function called search to the IntegerList class to search the list given a value. The search function signature should be as follow, int search(int val) This search function will return the position of val in the list. Remember The first node in the list is at position 0, the second node is at position 1 and so on. If val is not found in the list, the search function should return -1. Write a test program to test that the implementation your new function works properly.

(iv) Add a function called reverse to the IntegerList class to reverse the list. Write a test program to test that the implementation your reverse function works properly.

(v) Add a member function to the IntegerList class to remove a node by position. The new remove function signature should be as follow, void removeByPosition(int pos) where pos denotes the position in the list where the value should be removed. A pos value of 0 means the first node of the list will be removed. A pos value of 1 means the second node in the list will be removed. A pos value of equal to or greater than the length of the list means nothing is removed. Write a test program to test that the implementation your remove function works properly

Hello Dear, I need a big help to complete this assignment. Please help me out to complete this. Please provide me a solution step by step what is in the assignment. It needs to complete in C++ language. its due in two days. please need to complete this according to the order. Can someone help me please. I will bd so grateful to you. Thank You so much.

Explanation / Answer

class IntegerList
{
//declaring 2 arrays,b is for storing the reverse array
public:
static int a[5];//making a as static so that it can be initialised outside the class
int b[5];
//function to search the element passed in the array
int search(int val)
{
int i,pos=-1;
for(i=0;i<5;i++)
{
if(a[i]==val) //comparing the array elements with the value to be searched
pos=i;
}
return pos; //returning the position of element
}

//function to reverse the array elements
void reverse()
{
int i=0,j;
for(i=5-1,j=0;i>=0;i--,j++)
{
b[i]=a[j]; //storing the reverse array in b[]
}
}

//method to romove the array element at position "pos"
void removeByPos(int pos)
{
int i;
for(i=0;i<5;i++)
{
if(i==pos)
{
a[i]=a[i+1];
a[i+1]=a[i+2];
}
}
}
};

int IntegerList::a[]={2,4,3,90,22}; //initialising the array

#include<iostream>
using namespace std;

int main()
{
//declaring object of the class
IntegerList x;

int n,pos,pos1;
cout<<"enter the element to be searched";
cin>>n;
pos=x.search(n); //calling search funtion
if(pos==-1)
cout<<endl<<"element not found in array";
else
cout<<endl<<"the element "<<n<<" is at position "<<pos;
x.reverse(); //calling reverse funtion
cout<<" array after reverse is";
for(int i=0;i<5;i++)
{
cout<<" "<<x.b[i];
}

cout<<endl<<"enter the element to be removed";
cin>>pos1;

cout<<"array after del is";
x.removeByPos(pos1); //calling removeByPos function
for(int i=0;i<5-1;i++) //running the loop upto 5-1 times because after deletion the sixze of array reduces by 1
{
cout<<" "<<x.a[i];
}

}