please solve it in c Add a function called search to the Int
please solve it in c++
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 l 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 Civ) (15 Marks 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) (15 Marks) 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.Solution
#include<iostream>
using namespace std;
int search(int);
int array[100], key,i,position;
int size;
int main()
{
cout<<\"Enter The search Size Of Array: \";
cin>>size;
// Taking Input In Array
for(int j=0;j<size;j++)
{
cout<<\"Enter \"<<j<<\" Element: \";
cin>>array[j];
}
//Your Entered Array Is
for(int j=0;j<size;j++)
{
cout<<\"array[ \"<<j<<\" ] = \";
cout<<array[j]<<endl;
}
cout<<\"Enter Key To Search in Array\";
cin>>key;
position=search(key);
cout<<\"key position :\"<<position<<\"\ \";
return 0;
}
int search(int val)
{
for(i=0;i<size;i++)
{
if(key==array[i])
{
break;
}
}
if(i != size)
{
i==-1;
}
return i;
}
example output:
Enter The search Size Of Array: 5
Enter 0 Element: 1
Enter 1 Element: 2
Enter 2 Element: 4
Enter 3 Element: 5
Enter 4 Element: 3
array[ 0 ] = 1
array[ 1 ] = 2
array[ 2 ] = 4
array[ 3 ] = 5
array[ 4 ] = 3
Enter Key To Search in Array3
key position :4
iv)
#include<iostream>
using namespace std;
void reverse(void);
int array[100],reverse_array[100], i;
int size;
int main()
{
cout<<\"Enter The search Size Of Array: \";
cin>>size;
// Taking Input In Array
for(int j=0;j<size;j++)
{
cout<<\"Enter \"<<j<<\" Element: \";
cin>>array[j];
}
//Your Entered Array Is
for(int j=0;j<size;j++)
{
cout<<\"array[ \"<<j<<\" ] = \";
cout<<array[j]<<endl;
}
reverse();
// reverse array
for(int j=0;j<size;j++)
{
cout<<\"reverse_array[ \"<<j<<\" ] = \";
cout<<reverse_array[j]<<endl;
}
return 0;
}
void reverse()
{
for(int j=0;j<size;j++)
{
reverse_array[j]=array[size-1-j];
}
}
example:
Enter The search Size Of Array: 5
Enter 0 Element: 1
Enter 1 Element: 2
Enter 2 Element: 3
Enter 3 Element: 4
Enter 4 Element: 5
array[ 0 ] = 1
array[ 1 ] = 2
array[ 2 ] = 3
array[ 3 ] = 4
array[ 4 ] = 5
reverse_array[ 0 ] = 5
reverse_array[ 1 ] = 4
reverse_array[ 2 ] = 3
reverse_array[ 3 ] = 2
reverse_array[ 4 ] = 1


