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

to the following program, please help me put the quoted area into a function out

ID: 3622470 • Letter: T

Question

to the following program, please help me put the quoted area into a function outside of main.

Code:
#include
#include
#include
#include

using namespace std;

int storingData(int playerNums[], string playerNames[],int wins[],int losses[]);
int seqSearch (const int list[], int listLenght, int searchItem);
double winningpercentage (double winningper[],int wins[],int losses[],int count);
int indexLargestElement(const double list[], int listSize);
const int NUM_OF_PLAYERS= 100;
ifstream input;
int main()
{

double winningper[NUM_OF_PLAYERS];
int count;
int playerNums[NUM_OF_PLAYERS];
string playerNames[NUM_OF_PLAYERS];
int playerNum=0;
int wins[NUM_OF_PLAYERS];
int losses[NUM_OF_PLAYERS];
int pos;
double winper=0;
int highestplayer=0;
count = storingData(playerNums, playerNames, wins, losses);
winningpercentage(winningper,wins,losses,count);
highestplayer=indexLargestElement(winningper,count);
cout << playerNames[highestplayer]<<" "<
"cout << "Enter a player number: ";
cin >> playerNum;
const int SENTINEL= -1;
while (playerNum !=SENTINEL)
{
// call the search function here
seqSearch (playerNums, count, playerNum);
pos= seqSearch (playerNums, count, playerNum);

// display the player name here
cout << playerNames[pos]<< " "<< wins[pos] << " "<< losses[pos]<<" "<< endl< cout << fixed << setprecision(3) << showpoint;
cout <<"winning percentage: %"<< winningper[pos] < cout << "Enter a player number: ";
cin >> playerNum;
}
}


int storingData(int playerNums[], string playerNames[],int wins[],int losses[])

{
input.open("Player.txt");

int count=0;
while (input.peek() != EOF)
{
input >> playerNums[count] >> playerNames[count]>>wins[count]>>losses [count];
count++;
}

input.close();

return count;
}

int seqSearch (const int list[], int listLenght, int searchItem)
{
int loc;
bool found =false;
loc = 0;
while (loc < listLenght && !found)
if (list[loc] == searchItem)
found = true;
else
loc++;
if (found)
return loc;
else
return -1;
}
double winningpercentage (double winningper[],int wins[],int losses[],int count)
{
int i;
for (i=0;i {
winningper[i]=(static_cast(wins[i])/(static_cast(wins[i])+static_cast(losses[i])));
}
return 0;
}

int indexLargestElement(const double list[], int listSize)
{
int index;
int maxIndex = 0;
for (index=1; index < listSize; index++)
if (list[maxIndex] < list[index])
maxIndex = index;
return maxIndex;
}

Explanation / Answer

Dear,

The code after fixed.

didn't understand the sentence "please help me put the quoted area into a function outside of main."

you need winning percentage without function ????

What is meant by quoted area?

#include<iostream>

#include<string>

#include<iomanip>

#include<fstream>

using namespace std;

int storingData(int playerNums[], string playerNames[],int wins[],int losses[]);

int seqSearch (const int list[], int listLenght, int searchItem);

double winningpercentage (double winningper[],int wins[],int losses[],int count);

int indexLargestElement(const double list[], int listSize);

const int NUM_OF_PLAYERS= 100;

ifstream input;

int main()

{

double winningper[NUM_OF_PLAYERS];

int count;

int playerNums[NUM_OF_PLAYERS];

string playerNames[NUM_OF_PLAYERS];

int playerNum=0;

int wins[NUM_OF_PLAYERS];

int losses[NUM_OF_PLAYERS];

int pos;

double winper=0;

int highestplayer=0;

count = storingData(playerNums, playerNames, wins, losses);

winningpercentage(winningper,wins,losses,count);

highestplayer=indexLargestElement(winningper,count);

cout << playerNames[highestplayer]<<" ";

cout<<"show";

cout << "Enter a player number: ";

cin >> playerNum;

const int SENTINEL= -1;

while (playerNum !=SENTINEL)

{

// call the search function here

seqSearch (playerNums, count, playerNum);

pos= seqSearch (playerNums, count, playerNum);

// display the player name here

cout << playerNames[pos]<< " "<< wins[pos] << " "<< losses[pos]<<" "<< endl;

cout << fixed << setprecision(3) << showpoint;

cout <<"winning percentage: %"<< winningper[pos];

cout << "Enter a player number: ";

cin >> playerNum;

}

}

int storingData(int playerNums[], string playerNames[],int wins[],int losses[])

{

input.open("Player.txt");

int count=0;

while (input.peek() != EOF)

{

input >> playerNums[count] >> playerNames[count]>>wins[count]>>losses [count];

count++;

}

input.close();

return count;

}

int seqSearch (const int list[], int listLenght, int searchItem)

{

int loc;

bool found =false;

loc = 0;

while (loc < listLenght && !found)

if (list[loc] == searchItem)

found = true;

else

loc++;

if (found)

return loc;

else

return -1;

}

double winningpercentage (double winningper[],int wins[],int losses[],int count)

{

int i;

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

{

winningper[i]= 100*(static_cast<double>(wins[i])/(static_cast<double>(wins[i])+static_cast<double>(losses[i])));

}

return winningper[i];

}

int indexLargestElement(const double list[], int listSize)

{

int index;

int maxIndex = 0;

for (index=1; index < listSize; index++)

if (list[maxIndex] < list[index])

maxIndex = index;

return maxIndex;

}