C codeDont need heading or int mainjust use the following fu
C++ code.Dont need heading or int main,just use the following function header for each question. 4 short questions,please answer them all for me!
Write a C++ function that removes all products in the array of structs with price that matches with given argument \'target .Each time an element is removed, the array should be shifted to fill the gap. The function should return the size of the array after removing the matches. struct Product string pname; int price Use the following function header: int Shift Array(Product arro,int size,int target)Solution
1)
int ShiftArray(Product arr[], int size, int target)
{
Product temp;
for(int i=0;i<size;i++)
{
int j=0;
if(arr[i].price==target)
{
for(j=i;j<size-1;j++)
arr[j]=arr[j-1];
i--;
size--;
}
}
return size;
}
2)
string commonRepeatingElement(Product arr[],int length)
{
int currCount=0;
int maxCount=0;
string mostOccProduct=arr[0].pname;
for(int i=0;i<length;i++)
{
currCount=0;
for(int j=0;j<length;j++)
{
if(arr[i].pname==arr[j].pname)
currCount++;
}
if(currCount > maxCount)
{
maxCount=currCount;
mostOccProduct=arr[i].pname;
}
}
return mostOccProduct;
}
4)
int secondLargest(int arr[],int size)
{
int first,second,i;
first=a[0],second=a[1];
for(int i=1;i<n;i++)
{
if(a[i]>first)
{
second=first;
first=a[i];
}
else if(a[i]>second && a[i]!=first)
second=a[i];
else if(first==second)
second=a[i];
}
return second;
}

