Question

A particular talent competition has five judges, each of whom awards a score between 0 and...

A particular talent competition has five judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores, such as 8.3, are allowed. A performer’s final score is determined by dropping the highest and the lowest score received then averaging the three remaining scores. Write a program that does the following:

1. Reads names and scores from an input file into a dynamically allocated array of structures. The first number in the input file represents the number of performers.

2. Calculates the final score of each performer.

3. Sorts the array in descending order by the final score using the insertion sort algorithm.

4. Writes the sorted array to a file, in a table format with a header of your choice and data nicely aligned (strings to the left, numbers to the right, aligned by the decimal point). The output file’s name is created by adding “out” to the input file’s name. For instance, if the input file’s name is performers.txt, the output file’s name will be performersout.txt

5. Displays highest score, the winner’s names and scores. If two or more performers have the same highest score, all are considered winners. Display the output in a readable format of your choice.

The Performer structure has three fields:

name (string) such as John Lee

scores (an array) 7.5 7.5 7.5 7.5 7.5

final (double) 7.5

Input: Read data from an input file. Assume the input files have been validated. However, your program should detect if a file is empty and display an error message. First create the input files: copy and paste the following data into new text files or use the existing text files.

performers.txt

8

John Lee; 7.0 7.8 7.1 7.9 7.5

David T. Ng; 8.3 2.9 9.8 9.2 9.7

Mary Johnson; 8.3 8.0 8.9 7.9 8.5

Andy V. Garcia; 9.1 8.9 9.0 8.7 9.1

Ann Peterson; 9.0 8.8 9.1 9.7 9.3

Lucy A. Smith; 8.2 8.4 8.9 9.3 8.5

Dan Nguyen; 9.0 5.6 8.9 9.9 7.3

Sue K. Warren; 7.9 8.2 7.6 8.1 8.0

contestants.txt

11

Linda Johnson; 9.3 9.6 9.9 9.9 9.0

Steve Chen; 8.3 2.9 9.8 9.2 9.7

Mary Livingston; 8.3 8.0 8.9 7.9 8.5

Tom A. Retter; 9.1 8.9 9.0 8.7 9.1

Dana Wu; 9.0 8.8 9.1 9.7 9.3

James Michael Owen; 9.9 9.6 9.9 9.0 9.3

Marie Kondo; 9.6 9.0 9.9 9.9 9.3

Bob Schuster; 8.2 8.4 8.9 9.3 8.5

Kevin Yu; 8.3 9.2 9.8 2.9 9.7

Tina Queen; 9.0 9.6 9.9 9.9 9.3

Jonathan Edwards; 9.9 9.6 9.0 9.9 9.3

test.txt

7

John Lee; 8.3 7.5 8.9 9.9 8.6

David T. Ng; 8.3 8.9 9.9 8.6 7.5

Mary Johnson; 8.3 7.5 8.9 8.6 9.9

Andy V. Garcia; 7.5 8.3 8.9 9.9 8.6

John Lee; 9.9 8.3 7.5 8.9 8.6

Ann Peterson; 8.3 8.9 9.9 7.5 8.6

Dan Nguyen; 8.3 9.9 7.5 8.9 8.6

testempty.txt

I have some codes:

#include

using namespace std;

/* Define a struct named Performer with the following fields:

1. name (string)

2. scores (an array of 5 doubles)

3. final (double) */

// Function prototypes

void printWelcome(void);

void readPerfData(); // <== add parameters, change void if needed

void calculateScore(); // <== add parameters, change void if needed

void insertionSort(); // <== add parameters, change void if needed

void writeFile(); // <== add parameters, change void if needed

void displayResults(); // <== add parameters, change void if needed

void printEnd(void);

int main( void )

{ string inFileName[] = {"performers.txt", "contestants.txt", "test.txt", "testempty.txt", ""};

int choice = 1; // to stop the program to allow the user to see the results one file at a time

for (string *ptr = inFileName; choice == 1 && *ptr != ""; ptr++) // test loop: takes the names of 4 input files from an array

{ printWelcome();

readPerfData(); // <== change call to match with definition

calculateScore(); // <== change call to match with definition

insertionSort(); // <== change call to match with definition

writeFile(); // <== change call to match with definition

displayResults(); // <== change call to match with definition

printEnd();

cout << "Please enter 1 to continue 0 to stop" << endl;

cin >> choice; }

return 0; }

// main /********************** */

void printWelcome(void)

{ cout << "Welcome\n"; }

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

void readPerfData() // <== add parameters, change void if needed

{ cout << "Read Performers Data\n"; }

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

void calculateScore() // <== add parameters, change void if needed

{ cout << "calculateScore\n"; }

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

void insertionSort() // <== add parameters, change void if needed

{ cout << "Insertion Sort Descending\n"; }

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

void writeFile() // <== add parameters, change void if needed

{ cout << "Write report to file\n"; } /********************** */

void displayResults() // <== add parameters, change void if needed

{ cout << "Display the winners and their scores\n"; }

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

void printEnd(void)

{ cout << "Good Bye!\n"; }

0 0
Add a comment Improve this question Transcribed image text
Answer #1

About my knowledge The common approach for checking if a file is empty or not is to first check if the file exist or not and then check if it contains any content or not.

#include

using namespace std;

/* Define a struct named Performer with the following fields:

1. name (string)

2. scores (an array of 5 doubles)

3. final (double) */

// Function prototypes

void printWelcome(void);

void readPerfData(); // <== add parameters, change void if needed

void calculateScore(); // <== add parameters, change void if needed

void insertionSort(); // <== add parameters, change void if needed

void writeFile(); // <== add parameters, change void if needed

void displayResults(); // <== add parameters, change void if needed

void printEnd(void);

int main( void )

{ string inFileName[] = {"performers.txt", "contestants.txt", "test.txt", "testempty.txt", ""};

int choice = 1; // to stop the program to allow the user to see the results one file at a time

for (string *ptr = inFileName; choice == 1 && *ptr != ""; ptr++) // test loop: takes the names of 4 input files from an array

{ printWelcome();

readPerfData(); // <== change call to match with definition

calculateScore(); // <== change call to match with definition

insertionSort(); // <== change call to match with definition

writeFile(); // <== change call to match with definition

displayResults(); // <== change call to match with definition

printEnd();

cout << "Please enter 1 to continue 0 to stop" << endl;

cin >> choice; }

return 0; }

// main /********************** */

void printWelcome(void)

{ cout << "Welcome\n"; }

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

void readPerfData() // <== add parameters, change void if needed

{ cout << "Read Performers Data\n"; }

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

void calculateScore() // <== add parameters, change void if needed

{ cout << "calculateScore\n"; }

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

void insertionSort() // <== add parameters, change void if needed

{ cout << "Insertion Sort Descending\n"; }

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

void writeFile() // <== add parameters, change void if needed

{ cout << "Write report to file\n"; } /********************** */

void displayResults() // <== add parameters, change void if needed

{ cout << "Display the winners and their scores\n"; }

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

void printEnd(void)

{ cout << "Good Bye!\n"; }

11

Linda Johnson; 9.3 9.6 9.9 9.9 9.0

Steve Chen; 8.3 2.9 9.8 9.2 9.7

Mary Livingston; 8.3 8.0 8.9 7.9 8.5

Tom A. Retter; 9.1 8.9 9.0 8.7 9.1

Dana Wu; 9.0 8.8 9.1 9.7 9.3

James Michael Owen; 9.9 9.6 9.9 9.0 9.3

Marie Kondo; 9.6 9.0 9.9 9.9 9.3

Bob Schuster; 8.2 8.4 8.9 9.3 8.5

Kevin Yu; 8.3 9.2 9.8 2.9 9.7

Tina Queen; 9.0 9.6 9.9 9.9 9.3

Jonathan Edwards; 9.9 9.6 9.0 9.9 9.3

John Lee; 7.0 7.8 7.1 7.9 7.5

David T. Ng; 8.3 2.9 9.8 9.2 9.7

Mary Johnson; 8.3 8.0 8.9 7.9 8.5

Andy V. Garcia; 9.1 8.9 9.0 8.7 9.1

Ann Peterson; 9.0 8.8 9.1 9.7 9.3

Lucy A. Smith; 8.2 8.4 8.9 9.3 8.5

Dan Nguyen; 9.0 5.6 8.9 9.9 7.3

Sue K. Warren; 7.9 8.2 7.6 8.1 8.0

7

John Lee; 8.3 7.5 8.9 9.9 8.6

David T. Ng; 8.3 8.9 9.9 8.6 7.5

Mary Johnson; 8.3 7.5 8.9 8.6 9.9

Andy V. Garcia; 7.5 8.3 8.9 9.9 8.6

John Lee; 9.9 8.3 7.5 8.9 8.6

Ann Peterson; 8.3 8.9 9.9 7.5 8.6

Dan Nguyen; 8.3 9.9 7.5 8.9 8.6

Add a comment
Know the answer?
Add Answer to:
A particular talent competition has five judges, each of whom awards a score between 0 and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A particular talent composition has 5 judges, each of whom awards a score between 0 and...

    A particular talent composition has 5 judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores, such as 8.3, are allowed. A performer's final score is determined by dropping the lowest and the highest score received, then averaging the 3 remaining scores. Write a program that uses this method to calculate a contestant's score. It should include the following functions: double getJudgeData() should ask the user for a judge's score and validate the score....

  • The data contained in the file named StateUnemp show the unemployment rate in March 2011 and...

    The data contained in the file named StateUnemp show the unemployment rate in March 2011 and the unemployment rate in March 2012 for every state.† State      Unemploy- ment Rate March 2011        Unemploy- ment Rate March 2012 Alabama              9.3          7.3 Alaska 7.6          7.0 Arizona                 9.6          8.6 Arkansas              8.0          7.4 California             11.9       11.0 Colorado              8.5          7.8 Connecticut        9.1          7.7 Delaware             7.3          6.9 Florida 10.7      ...

  • 4.3 Analysis Assignment #4 Note 1: all assignments moving forward must adhere to the appropriate Six Ste...

    4.3 Analysis Assignment #4 Note 1: all assignments moving forward must adhere to the appropriate Six Step Process (SSP). As our study materials have specified, the SSP has 3 versions. Version 1 is to be used for all t-tests; for all correlation analyses and Version 3 is be used for all regression analyses. Note 2: The data sets for Q1, Q2 and Q3 below can be downloaded here. Week 4 Analysis Assignments.xlsx Q1: (30 points) Complete the following data analysis:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT