Using the pseudo code below, write the code that will meet the requirements: Mai
ID: 3624764 • Letter: U
Question
Using the pseudo code below, write the code that will meet the requirements:Main Function
Declare the player name and score arrays, number of players, and average score.
Call the InputData function
Call the DisplayPlayerData function
Call the CalculateAverageScore function and assign the returned value in average score
Call the DisplayBelowAverage function
InputData function
While the number of players is less than the length of the array
Prompt for the player's name
If the user entered Q, break out of the loop
Prompt the user for the player's score
Add 1 to the number of players
End-While
DisplayPlayerData function
Display the name and score of each player
CalculateAverageScore function
Add up the scores and divide by the number of scores to calculate the average score
Display the average score
Return the average score to main
DisplayBelowAverage function
Display the names and scores of all players who scored below the average score
Sample Output from Program:
Enter Player Name (Q to quit): Bob
Enter score for Bob: 3245
Enter Player Name (Q to quit): Sue
Enter score for Sue: 1098
Enter Player Name (Q to quit): Dave
Enter score for Dave: 8219
Enter Player Name (Q to quit): Pat
Enter score for Pat: 3217
Enter Player Name (Q to quit): Q
Name Score
Bob 3245
Sue 1098
Dave 8219
Pat 3217
Average Score: 3944.75
Players who scored below average
Name Score
Bob 3245
Sue 1098
Pat 3217
Press any key to continue . .
Write a program that will input a phrase and convert it to pig latin. Put each word in a separate element of a string array. Remove the first letter from each word and concatenate it to the end of the word followed by "ay".
Using the pseudo code below, write the code that will meet the requirements.
Main function
Display the heading
While the condition is true
Prompt the user for group of words or Enter to quit
Display original words
Call function pigLatinString( )
End while
pigLatinString( ) function
Declare and initialize string variables len, counter, start, begin, word and newString
While condition is true
Call find() and pass a space and start as parameters and return the returned value
to start
if start equals to string::npos
jump outside the loop permanently
call substr() function
display the word
update newString
increment start by one
assign start to begin
End While
Call substr()
Update newString
Return newString
Sample Output from Program:
*** You will be prompted to enter a string of ***
*** words. The string will be converted into ***
*** Pig Latin and the results displayed. ***
*** Enter as many strings as you would like. ***
Enter a group of words or ENTER to quit: DeVry is a wonderful school
Original words: DeVry is a wonderful school
New Words: eVryDay siay aay onderfulway choolsay
Enter a group of words or ENTER to quit: The Cowbows are going to the Superbowl
Original words: The Cowbows are going to the Superbowl
New Words: heTay owbowsCay reaay oinggay otay hetay uperbowlSay
Enter a group of words or ENTER to quit:
Explanation / Answer
please rate-thanks
#include <iostream>
using namespace std;
void inputData(int[],string[],int&);
void displayPlayerData(int[],string[],int);
double calculateAverageScore(int[],int);
void displayBelowAverage(int[],string[],int,double);
int main()
{int score[100];
double average;
string name[100];
int n=0;
inputData(score,name,n);
displayPlayerData(score,name,n);
average=calculateAverageScore(score,n);
displayBelowAverage(score,name,n,average);
system("pause");
return 0;
}
void inputData(int score[],string name[],int& n)
{cout<<"Enter Player Name (Q to quit): ";
cin>>name[n];
while(name[n].compare("Q")!=0)
{cout<<"Enter score for "<<name[n]<<": ";
cin>>score[n];
n++;
cout<<"Enter Player Name (Q to quit): ";
cin>>name[n];
}
}
void displayPlayerData(int score[],string name[],int n)
{int i;
cout<<" Name Score ";
for(i=0;i<n;i++)
cout<<name[i]<<" "<<score[i]<<endl;
}
double calculateAverageScore(int score[],int n)
{double a,sum=0;
int i;
for(i=0;i<n;i++)
sum+=score[i];
a=sum/n;
cout<<" Average Score: "<<a<<endl;
return a;
}
void displayBelowAverage(int score[],string name[],int n,double average)
{int i;
cout<<" Players who scored below average Name Score ";
for(i=0;i<n;i++)
if(score[i]<average)
cout<<name[i]<<" "<<score[i]<<endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.