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

First ask the diver\'s name, then ask how many judges will be scoring the compet

ID: 3554042 • Letter: F

Question

First ask the diver's name, then ask how many judges will be scoring the competition. Number of

judges must be from 5 thru 8. Next, the diving menu will appear and the user enters 3 dives. User choice for each dive must be A through E, case insensitive.

The statistics displayed are: the type of dive, the user requested number of scores, and the total

for each dive. Two grids displaying the diver's statistics will appear. The first grid contains all

scores and the total sum of the scores. The second grid displays just like the first grid, except, the

highest and lowest scores for each dive have been set to zero (0.0) and the totals have been

redone. Below the grids, a message will appear telling the diver what their highest scored dive

was and the points. The user is then re-prompted to run the program again if they want too.

All user input must be error checked. If a value is out of range, an appropriate error message

must be generated and the user must be prompted again. All user character input is case

insensitive and if the user inputs a decimal number when a whole number is needed (eg. number

of judges) the program automatically rounds down the number.(See the Sample Runs below).



Use appropriate (descriptive) names for the functions. Be sure to use pass-by-value and

pass-by-reference parameters.

You must use at least one one-dimensional array and one two-dimensional array.

Number of judges must be between 5 and 8 inclusive.

Number of dives scored must always be three.

You must have a function to initialize all arrays.

You must have at function that calculates the dive scores and stores them in the 2-D array.

You must have a function that zeroes out the highest and lowest scores in the 2-D array.

The first grid must say "Before" high and low scores removed and

the second grid must say "After" high and low scores removed.

Blank lines, spaces, and formatting are important in the output generated by your program.

Follow the sample runs.

All user input must be error checked (in a separate function).


No Classes or structures can be used.


PSEUDOCODE:


Below are some suggestions which may help you. You are not obliged to use them. You may

use your own identifier names. Just be sure that your code fulfills the assignment

requirements.Remember that array indices begin at 0.

----------------------------------------------------------------------------

Pseudocode

get diver's name (string)

get number judges (5-8)

display menu

FOR 3x

get dive choice (Aa-Ee)

seed randomizer

generate scores

FOR each of 3 dives

calc total

// complete the remaining pseudocode

display highest dive message

again?

*/

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

// Some Global Constants

const string

DIVE_NAME[5] = {"Forward Jump Pike",

"Forward Dive Straight",

"Forward 2.5 Tuck",

"Back 3.5 Tuck",

"Inward 0.5 Twist Straight"

};

const double DIVE_DIFFICULTY[5] = { 1.0, 1.6, 2.2, 3.4, 1.9 };

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

// Some Function Prototypes - you will need more

void initializeScores( // fill in );

void getName (string & /*OUT*/);

void getNumJudges (int & /*OUT*/);

void displayMenu (void);

void displayTitle (string /*IN*/, string /*IN*/);

double genRandomNum (void);

void best(string, int /*IN*/, int[NUM_DIVES],

double[NUM_DIVES][MAX_NUM_JUDGES] /*IN*/);

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

// Main Function

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

void main ()

{

/* Data Declarations */

string diverName = ""; // diver's name

int numJudges = 0; // number of judges input by user

// holds an integer derived from menu choice for each of 3 dives

// used as index to dive's name & difficulty held in CONST ARRAYS

int dives[NUM_DIVES];

// declare a 2-D array to hold scores

// declare a flag which ends the program when set to true

// set the seed randomizer

// main loop with only function calls

do

{

functions calls go here

} while ();

} // end main()

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

// Function Implementations

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

// inititlizeScores( complete the header)

//* Precondition: array w/ scores passed in

//* Postcondition: array w/ all elements set to zero passed back

{

}

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

void getName (string & name /*OUT*/)

//* Precondition: none

//* Postcondition: name of diver (string) passed by reference

{

cout << "Enter the Diver's name: ";

getline(cin,name);

} // end getName()

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

// getNumJudges( complete the header)

//* Precondition: none

//* Postcondition: number of judges (integer 5 - 8) passed by reference

{

double get_number;

cout << " How many Judges will be scoring (5 - 8)? : ";

cin >> get_number;

number = (int)get_number;

// write validation loop: no numbers (2, 3, 10, etc.) allowed in the boolean expression

cout << "**Error - must be 5 to 8 judges only**";

cout << " How many Judges will be scoring (5 - 8)? : ";

// complete the loop here

number = static_cast<int>(get_number);

} //* end validation loop

} //* end getNumJudges()

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

void displayMenu (void)

//* Precondition: none

//* Postcondition: menu of dives & difficulties displayed

{

cout << endl;

cout << " Menu" << endl;

cout << " ASU Diving Competition - 2016" << endl;

cout << " ------------------------------" << endl;

cout << " Dive Difficulty" << endl;

cout << endl;

cout << " A. Forward Jump Pike 1.0" << endl;

cout << " B. Forward Dive Straight 1.6" << endl;

cout << " C. Forward 2.5 Tuck 2.2" << endl;

cout << " D. Back 3.5 Tuck 3.4" << endl;

cout << " E. Inward 0.5 Twist Straight 1.9" << endl;

cout << " ------------------------------" << endl;

} // end displayMenu()

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

void getDiveChoices (int dives[NUM_DIVES] /*OUT*/)

//* Precondition: none

//* Postcondition: menu choices A-E converted to integers 0-4 and saved in array

{

// FOR loop to get dives to be judged {

char choice = ' ';

cout << " Enter dive " << i + 1 << " to be judged (A - E):";

cin >> choice;

choice = toupper(choice);

// validate input here

dives[i] = choice;

dives[i] = (int)dives[i] - 65; //*changes character data, A-E, into the integers 0-4

}// end FOR loop

} // end getDiveChoices()

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

double genRandomNum(void)

//* Precondition: rand() has been seeded

//* Postcondition: 1 score (double 0.1 - 10.0) returned

{

} // end genRandomNum()

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

void genScores(int numJudges/*IN*/, double Table[NUM_DIVES][MAX_NUM_JUDGES]/*OUT*/)

//* Precondition: none

//* Postcondition: array Table (double[][]) has been filled with random scores (0.1 - 10.0)

{

} // end genScores()

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

void zeroHighLow (int numJudges /*IN*/,

double diveArray[NUM_DIVES][MAX_NUM_JUDGES] /*IN-OUT*/)

//* Precondition: number of judges and array w/ scores passed in

//* Postcondition: high and low score for each dive are set to zero in array and passed out

{

int high,low;

for (// complete the conditions){

high = // call to highScore();

low = // call to lowScore();

diveArray[i][high] = 0.0;

diveArray[i][low] = 0.0;

}

} // end zeroHighLow()

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

int highScore ( // complete the header)

//* Precondition: number of judges, dive and array of scores passed in

//* Postcondition: index of high score (int) returned

{

} // end highScore()

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

int lowScore ( // complete the header)

//* Precondition: number of judges, dive and array of scores passed in

//* Postcondition: index of low score (int) returned

{

} // end lowScore()

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

void displayTitle (string beforeAfter /*IN*/, string name/*IN*/)

//* Precondition: string "before" or "after" and name passed in

//* Postcondition: title displayed

{

cout << endl << endl;

cout << " ASU Diving Competition - 2016" << endl;

cout << " Statistics for " << name << endl;

cout << " " << beforeAfter << " High and Low Scores Removed" << endl;

cout << " ------------------------------------------ "; //<< endl;

} // end displayTitle()

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

void displayDives (int numJudges /*IN*/, int dive[NUM_DIVES] /*IN*/,

double Table[NUM_DIVES][MAX_NUM_JUDGES] /*IN*/)

//* Precondition: number of judges, array with dive choices and array w/ scores passed in

//* Postcondition: name of dive, scores and total displayed for each dive

{

double

total = 0.0,

Best = 0.0;

cout << fixed << setw(24) << ""; //* indents and prevents a hard return

// display #1, #2, ... headings

cout << setw(8) << "Total";

for (int i = 0; i < NUM_DIVES; i++) {

cout << endl << setw(25) << DIVE_NAME[dive[i]];

// write inner loop needed for the remainder of the display

cout << setprecision(1) << setw(7) << total * DIVE_DIFFICULTY[dive[i]];

total = 0.0;

}

} // end displayDives()

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

void best (string name /*IN*/, int numJudges /*IN*/, int dive[NUM_DIVES] /*IN*/,

double Table[NUM_DIVES][MAX_NUM_JUDGES] /*IN*/)

//* Precondition: name, number of judges, array of dive choices and array w/ scores passed in

//* Postcondition: message with diver name, name of best dive and score of best dive displayed

{

int index = 0;

double total = 0.0,

Best = 0.0;

// write the need nested loops including another control sructure

cout << " " << name << ", your best dive is the " << DIVE_NAME[dive[index]]

<< " at " << setprecision(1) << setw(0) << Best << " points." << endl;

} // best()

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

void repeat ( // complete the header)

//* Precondition: none

//* Postcondition: bool variable passed back

{

char YesNo = ' ';

cout << endl;

cout << "Do you want to run the program again? (Y / N) : ";

cin >> YesNo;

// write the validation loop

// assign proper value to boolean variable

cout << endl;

} // end repeat()

















SAMPLE OUTPUT:


Enter the Diver's name: Ashley F. Jacob

How many Judges will be scoring (5 - 8)? : 8.7


Menu

ASU Diving Competition - 2016

------------------------------

Dive Difficulty

A. Forward Jump Pike 1.0

B. Forward Dive Straight 1.6

C. Forward 2.5 Tuck 2.2

D. Back 3.5 Tuck 3.4

E. Inward 0.5 Twist Straight 1.9

------------------------------

Enter dive 1 to be judged (A - E):c

Enter dive 2 to be judged (A - E):D

Enter dive 3 to be judged (A - E):e


ASU Diving Competition - 2016

Statistics for Ashley F. Jacob

Before High and Low Scores Removed

------------------------------------------

#1 #2 #3 #4 #5 #6 #7 #8 Total

Forward 2.5 Tuck 8.7 4.4 8.8 8.6 5.7 3.4 3.6 3.0 101.6

Back 3.5 Tuck 7.0 6.0 5.5 8.0 9.9 5.8 9.1 6.0 194.8

Inward 0.5 Twist Straight 9.1 3.5 3.5 5.1 0.6 6.2 2.7 5.5 68.8


ASU Diving Competition - 2016

Statistics for Ashley F. Jacob

After High and Low Scores Removed

------------------------------------------

#1 #2 #3 #4 #5 #6 #7 #8 Total

Forward 2.5 Tuck 8.7 4.4 0.0 8.6 5.7 3.4 3.6 0.0 75.7

Back 3.5 Tuck 7.0 6.0 0.0 8.0 0.0 5.8 9.1 6.0 142.5

Inward 0.5 Twist Straight 0.0 3.5 3.5 5.1 0.0 6.2 2.7 5.5 50.3

Ashley F. Jacob, your best dive is the Back 3.5 Tuck at 142.5 points.


Do you want to run the program again? (Y / N) : y

Enter the Diver's name: Angel S. Luria

How many Judges will be scoring (5 - 8)? : 3

**Error - must be 5 to 8 judges only**

How many Judges will be scoring (5 - 8)? : 10.6

**Error - must be 5 to 8 judges only**

How many Judges will be scoring (5 - 8)? : 5.7



Menu

ASU Diving Competition - 2016

------------------------------

Dive Difficulty

A. Forward Jump Pike 1.0

B. Forward Dive Straight 1.6

C. Forward 2.5 Tuck 2.2

D. Back 3.5 Tuck 3.4

E. Inward 0.5 Twist Straight 1.9

------------------------------


Enter dive 1 to be judged (A - E):A

Enter dive 2 to be judged (A - E):a

Enter dive 3 to be judged (A - E):c


ASU Diving Competition - 2016

Statistics for Angel S. Luria

Before High and Low Scores Removed

------------------------------------------

#1 #2 #3 #4 #5 Total

Forward Jump Pike 8.3 8.8 6.2 9.3 4.0 36.6

Forward Jump Pike 6.2 4.3 3.3 2.6 2.4 18.8

Forward 2.5 Tuck 8.0 2.2 4.3 9.8 3.3 60.7


ASU Diving Competition - 2016

Statistics for Angel S. Luria

After High and Low Scores Removed

------------------------------------------

#1 #2 #3 #4 #5 Total

Forward Jump Pike 8.3 8.8 6.2 0.0 0.0 23.3

Forward Jump Pike 0.0 4.3 3.3 2.6 0.0 10.2

Forward 2.5 Tuck 8.0 0.0 4.3 0.0 3.3 34.3


Angel S. Luria, your best dive is the Forward 2.5 Tuck at 34.3 points.

Do you want to run the program again? (Y / N) : n

Press any key to continue . . .


Explanation / Answer

#include<iostream>

#include<string>

#include <math.h>

#include <iomanip>

#include<time.h>

#include <ctime>

#define MAX_NUM_JUDGES 8

#define NUM_DIVES 3

using namespace std;

const string DIVE_NAME[5] = {"Forward Jump Pike","Forward Dive Straight","Forward 2.5 Tuck","Back 3.5 Tuck","Inward 0.5 Twist Straight"};

const double DIVE_DIFFICULTY[5] = { 1.0, 1.6, 2.2, 3.4, 1.9 };


void getName (string &name)

{

cin.clear();

cin.ignore();

cout << "Enter the Diver's name: ";

getline(cin,name);

}

void getNumJudges (int &number)

{

double get_number;

cout << "How many Judges will be scoring (5 - 8)? : ";

cin >> get_number;

number = (int)get_number;

while(number<5||number>8)

{

cout << "**Error - must be 5 to 8 judges only**";

cout << " How many Judges will be scoring (5 - 8)? : ";

cin >> get_number;

number = (int)get_number;

}

number = static_cast<int>(get_number);

}


void displayMenu (void)

{

cout << endl;

cout << " Menu" << endl;

cout << " ASU Diving Competition - 2016" << endl;

cout << " ------------------------------" << endl;

cout << " Dive Difficulty" << endl;

cout << endl;

cout << " A. Forward Jump Pike 1.0" << endl;

cout << " B. Forward Dive Straight 1.6" << endl;

cout << " C. Forward 2.5 Tuck 2.2" << endl;

cout << " D. Back 3.5 Tuck 3.4" << endl;

cout << " E. Inward 0.5 Twist Straight 1.9" << endl;

cout << " ------------------------------" << endl;

}

void getDiveChoices (int dives[NUM_DIVES])

{

char choice =' ';

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

{

cout << " Enter dive " << i + 1 << " to be judged (A - E):";

cin >> choice;

choice = toupper(choice);

dives[i] = choice;

dives[i] = (int)dives[i] - 65;

}

}

void displayTitle (string beforeAfter, string name)

{

cout << endl << endl;

cout << " ASU Diving Competition - 2016" << endl;

cout << " Statistics for " << name << endl;

cout << " " << beforeAfter << " High and Low Scores Removed" << endl;

cout << " ------------------------------------------ ";

}

double genRandomNum (void)

{

int ind1,ind2;

int f[10]={0,1,2,3,4,5,6,7,8,9};

double d[10]={0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9};

ind1 = rand()%10;

ind2 = rand()%10;

double res= double(f[ind1]) + d[ind2];

return res;

}

void genScores(int numJudges, double Table[NUM_DIVES][MAX_NUM_JUDGES])

{

srand(time(NULL));

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

{

for(int j=0;j<numJudges;j++)

{

Table[i][j]=genRandomNum();

}

}

}

int highScore (double arra[],int n)

{

int h=0;

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

{

if(arra[i]>arra[h])

h=i;

}

return h;

}

int lowScore ( double arra[],int n)

{

int m=0;

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

{

if(arra[i]<arra[m])

m=i;

}

return m;

}

void zeroHighLow (int numJudges, double diveArray[NUM_DIVES][MAX_NUM_JUDGES])

{

int high,low;

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

{

high = highScore(diveArray[i],numJudges);

low = lowScore(diveArray[i],numJudges);

diveArray[i][high] = 0.0;

diveArray[i][low] = 0.0;

}

}

void displayDives(int numJudges, int dive[NUM_DIVES],double Table[NUM_DIVES][MAX_NUM_JUDGES])

{

double total = 0.0,Best = 0.0;

cout << fixed << setw(24) << "";

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

cout<<"#"<<i+1<<" ";

cout << setw(8) << "Total";

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

{

cout <<endl<<setw(25)<<DIVE_NAME[dive[i]]<<" ";

for(int j=0;j<numJudges;j++)

{

cout<<setprecision(1)<<Table[i][j]<<" ";

total+= Table[i][j];

}

cout<< setw(7) << total * DIVE_DIFFICULTY[dive[i]];

if(Best<total)

{

Best = total;

}

total = 0.0;

}

}


void best (string name,int numJudges,int dive[NUM_DIVES],double Table[NUM_DIVES][MAX_NUM_JUDGES])

{

int index = 0;

double total = 0.0,

Best = 0.0;

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

{

for(int j=0;j<numJudges;j++)

{

total+=Table[i][j];

}

if(total>Best)

{

Best=total;

index = i;

}

total=0.0;

}

cout<<" "<<name<<", your best dive is the "<<DIVE_NAME[dive[index]]<<" at "<<setprecision(1)<<setw(0)<<Best*DIVE_DIFFICULTY[dive[index]]<<" points."<<endl;

}

void repeat (bool &flag)

{

char YesNo = ' ';

cout << endl;

cout << "Do you want to run the program again? (Y / N) : ";

cin >> YesNo;

while(!(YesNo=='y'||YesNo=='Y'||YesNo=='n'||YesNo=='N'))

{

cout<<"Enter y/Y or n/N"<<endl;

cin >> YesNo;

}

if(YesNo=='y'||YesNo=='Y')

flag=false;

else

flag = true;

cout << endl;

}

void inititlizeScores(double score[NUM_DIVES][MAX_NUM_JUDGES])

{

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

{

for(int j=0;j<MAX_NUM_JUDGES;j++)

{

score[i][j]=0.0;

}

}

}


int main()

{

string diverName = "";

int numJudges = 0;

int diveChoices;

int dives[NUM_DIVES];

double score[NUM_DIVES][MAX_NUM_JUDGES];

inititlizeScores(score);

bool flag=false;

do

{

getName(diverName);

getNumJudges(numJudges);

displayMenu();

getDiveChoices(dives);

genScores(numJudges,score);

displayTitle("before",diverName);

displayDives(numJudges,dives,score);

zeroHighLow(numJudges,score);

displayTitle("after",diverName);

displayDives(numJudges,dives,score);

best(diverName,numJudges,dives,score);

repeat(flag);

}while(!flag);

return 0;

}