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

I have a functioning code for the program but need the additional extra credit p

ID: 3911037 • Letter: I

Question

I have a functioning code for the program but need the additional extra credit part in C++. I've include images of the code working and the code

//header section

#include <iostream>

using namespace std;

//function prototype

int finMode(int*, int);

//main function

int main()

{

int n, i, j, tmp;

//loading

cout << "Enter the size of an array: ";

cin >> n;

int slices[30];

cout << "Enter " << n << " slices: ";

for (i = 0; i < n; i++)

{

cin >> slices[i];

}

//sorting

for (i = 0; i < n; i++)

{

for (j = i + 1; j < n + 1; j++)

{

if (slices[i] > slices[j])

{

//swaping

tmp = slices[i];

slices[i] = slices[j];

slices[j] = tmp;

}//end of if

}

}

int mode = finMode(slices, n);

cout << "Mod of slices is :" << mode<<" ";

system("pause");

return 0;

}//end of main

//function definition

int finMode(int slices[], int size)

{

int counter, mode = 0;

for (int i = 0; i < size; i++)

{

counter = 1;

//if tow adjacent elements equals

while (slices[i] == slices[i + 1])

{

counter++;

i++;

}

if (counter > mode)

mode = slices[i];//replacing mode

if (counter > 1)

i--;

}

return mode;//returning mode

}//end of main function

Page 701 10.5 Pie a la Mode (5 points) Keep in mind that the definition of "mode" is the value that occurs most often. That is not the same as the preferred value, or Maximum value. Extra Credit for Pie a la Mode (3 points) Also prompt the user for their favorite type of pie, and report back what the name of the most preferred pie was (the maximum value of pieces), in addition to the mean value of pieces eaten of each pie. It is ok to make this part asier by giving your u favorite) on your list.

Explanation / Answer

#include <iostream>

using namespace std;

// Function prototypes

void getData(int [], int);

void selecitonSort(int [], int);

int getmode(int [], int);

int main()

{

const int ppl = 30;

int slices[ppl];

getData(slices, ppl);

selecitonSort(slices, ppl);

for (int i = 0; i < ppl; i++)

{

cout << slices[i] << " ";

}

cout << " Number of pie slices eaten by the most people: "

<< getmode(slices, ppl) << endl;

return 0;

}

//*****************************************************************************

// getData *

//*****************************************************************************

void getData(int array[], int size)

{

cout << "Enter the number of pie slices eaten by each person in a year. ";

for (int i = 0; i < size; i++)

{

cout << "Person " << (i + 1) << ": ";

cin >> array[i];

}

}

//*****************************************************************************

// getmode *

//*****************************************************************************

int getmode(int array[], int size)

{

int count, hold, mode;

count = hold = 0;

for (int index = 0; index < size; index++)

{

count++;

if (array[index] < array[index + 1])

{

if(count > hold)

{

mode = array[index];

hold = count;

}

count = 0;

}

}

return mode;

}

//*****************************************************************************

// selectionSort *

//*****************************************************************************

void selecitonSort(int array[], int size)

{

int minIndex, minValue;

for (int scan = 0; scan < (size - 1); scan++)

{

minIndex = scan;

minValue = array[scan];

for (int i = scan + 1; i < size; i++)

{

if (array[i] < minValue)

{

minValue = array[i];

minIndex = i;

}

}

array[minIndex] = array[scan];

array[scan] = minValue;

}

}