Question: use switch statement please ( not if / else if ) and this is the openFiles function that teacher provided void openFiles ( ifstream& infile,

use switch statement please ( not if/else if) and this is the openFiles function that teacher provided
void openFiles(ifstream& infile, ofstream& outfile)
{
char inFileName[40];
char outFileName[40];
cout "Enter the input file name: ";
cin >> inFileName;
infile.open("CS1prog1.txt"); //open input file
cout "Enter the output file name: ";
cin >> outFileName;
outfile.open("outputP.txt"); //open output file
}
struct Athlete
{
int contestantNum;
double diving;
double gymnastics;
double skating;
double boxing;
double powerPosing;
double totalScore;
};
typedef Athlete AthleteData[SIZE];
void openFiles(ifstream& infile, ofstream& outfile);
void getContestants(ifstream& infile, AthleteData athletes, int& numContestants, int SIZE);
void printContestants(ofstream& outfile, AthleteData athletes, int numContestants);
void calculateTotal(Athlete& athlete);
void closeFiles(ifstream& infile, ofstream& outfile);
in the while loop, teacher does while (contestant !=-1) Purpose: To declare, define and call functions and to declare and use an array of structs using
the typedef statement.
Problem: In many athletic competitions, athletes compete in several events and receive a score
for each. These scores are then combined into a single result.
Your job is to write a program that calculates the results of MANY competitors
competing for the "Athlete of the Year" award. ALL athletes compete and receive a
score in five events: (D)iving, G(ymnastics),(S)kating,(B)oxing, and Power
(P)osing. Their total is computed to determine the winner.
Method: For each contestant, you will
Read in the contestant number and his/her scores in each event.
Print out the contestant number, the score for each event, and the TOTAL
number of points the athlete accumulated (add the five scores together).
At the end, you should
Compare all the athletes scores to identify the winner of the "Athlete of the
Year" award and display that contestant number AND their total score.
Input: Each athlete's scores are grouped together in the input file, but unfortunately do not
appear in any fixed order (the score keepers got the score sheets out of order).
Therefore, you will have to read in the event name (D, G, B, S, or P) BEFORE you
know which event to update. The set of scores for each athlete are separated from
one another by the contestant number (i.e., there is a line with an integer contestant
number followed by 5 lines of event and score, that is, B 7.5). The end of the input
file is signaled by a sentinel value (-1). Use this value to control your looping. You
will fetch the input from a file called CS2prog1.txt. This file is already created and
will be emailed to you. The input file looks similar to the following (but has more
data):
4
G 8.9
P 7.5
S 7.8
D 5.5
B 8.6
13
P 8.5
G 8.6
D 6.5
S 6.9
B 8.3
.
-1 Output: Output both contestant's numbers, the scores for each event, the resulting TOTAL
points accumulated.
Output the winner by printing the contestant number and his/her TOTAL score.
SAMPLE:
Contestant: 4
Diving: ,5.5
Gymnastics: 8.9
Boxing: ,8.6
Skating: ,7.8
Posing: ,7.5
TOTAL: 38.3
Contestant: 87
Diving:
ATHLETE OF THE YEAR: Contestant ? with TOTAL of ?
Requirements:
Use the struct you declare and define for Athlete.
Add functions as you see fit. You will be graded on your decisions. You must add a
function to GetContestants that returns the entire array by reference. You must add a
function to DisplayAllContestants that receives the entire array. Then call the other
functions you wrote in them to get the input or display the output.
Label all output and format it neatly and clearly. Print appropriate messages as well.
Remember to comment and format your program as well.
use switch statement please ( not if / else if )

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!