computer programming in c language Objectives : Apply the problem-solving proces
ID: 3707466 • Letter: C
Question
computer programming in c language
Objectives:
Apply the problem-solving process from initial problem analysis through code testing
Use decomposition to identify main tasks, and determine the correct sequence for the tasks in order to solve the problem
Practice using keyboard input to fill arrays
Practice using loops to process data in arraysusing common algorithms
Description:
The topic of this programming assignment is determining the gold-medal winner of a half-pipe snowboarding competition, based on scores that are examples of actual data compiled and analyzed during the recent winter Olympic Games in South Korea. The name of all snowboarders and scores earned for one run are saved in a data file.
A snowboarder’s halfpipe run is scored as follows:
A team of six judges scores each halfpipe run.In the actual games, competitors had three runs to try to earn their very highest possible score. However, for this lab, the data for each snowboarder will reflect just their highest score, regardless on which run it occurred.
Each judge gives a subjective score from 1 to 100 based on overall impression,composed of height maintained throughout the run;variety and difficulty of maneuvers; and execution skill. (The six individual scores are not publicized, so we will have to make an assumption on data type.)
The highest and lowest scores of the six judges are dropped for the run.
Then, the four remaining scores are averaged, and the person with the highest average score wins the gold medal.
Instructions:
Assume that each judge’s score is an integer. For each of 3 snowboarders (will a loop be helpful with this?), you will be prompting the user to enter the following dataon one line using the keyboard:
firstnamelastnamescore1 score2 score3 score4 score5 score6
The user should be instructed to separate each data element by at least one space.
The first and last name of each snowboarder should be read in and stored in separate arrays named firstnames and lastnames. (If you want to practice more with strings, you may want to explore how to read in and save the whole name at one time and save it in an array called names.)
A loop should be used to read in and save scores for each snowboarder into an array of integers named scores. The snowboarder with the highest floating point average of four scores (see description above to understand which four scores) is the winner of the gold medal.
Complete the Problem Description, Input, Output, and Assumptions sections of a Lab Report. Decide on the tasks necessary for applying the rules to determine the gold medal winner. In the Algorithm section of your lab report, draw a decomposition diagram showing an overview of the main tasks required.
Below the decomposition diagram in your lab report, list the sequence in which tasks should be executed. This is not a detailed algorithm, simply a high-level sequence.
Include in the Example section of your lab report an example worked by hand, using the following sample data below (with a pretend mix of male/female USA athletes).
Name
Six judges’ scores
Avg (excluding min and max)
Sean White
96
98
88
99
98
100
97.75
Chloe Kim
92
99
100
98
99
97
98.25
Ben Ferguson
90
95
91
85
94
88
90.75
Write the code to determine the average score for each competitor. For each snowboarder, display a message stating the person’s whole name and the average of that snowboarder’s four scores. This will help verify that your program works correctly for each person.
Finally, write the code to determine the gold medal-winning score. Display a message stating the winner’s whole name and average score.
Use the sample data to test your program and verify that actual results match expected results. In the Test Plan section of yourlab report, documentthe first test case using the sample data, and also a screenshot of the execution results obtained using the sample data.
Next, construct a test case usingtest data of your own, and execute your program to verify that actual results match expected results. You may use your own choice of names (perhaps you and your friends?) and scores. Document your test data in the in the Test Plan section of yourlab report, and include a screenshot of the execution results using your test data.
Deliverables:
Name your C program using the following pattern: yourFirstName_yourLastName_Lab2.c
Complete the sections of the Lab Report as instructed above, including both screenshots of execution results.
Upload both your C source code file and the Lab Report to the Piazza folder named “Lab 2.”
Scoring:Your grade for this assignment will be determined by four criteria:
Does your program compile and run, producing the correct results according to the instructions?
Does your program demonstrate good programming practices, such as well-documented code with comments, effective use of white space, proper indentation, appropriate variable names, etc.?
Are the required Lab Report sections complete and thoroughly documented?
Are you submitting your assignment on time?
Name
Six judges’ scores
Avg (excluding min and max)
Sean White
96
98
88
99
98
100
97.75
Chloe Kim
92
99
100
98
99
97
98.25
Ben Ferguson
90
95
91
85
94
88
90.75
Explanation / Answer
// File Name: ScoreMedal.c
#include<stdio.h>
#include<stdlib.h>
#define MAX 100
// Defines a structure to store player information
struct playerScore
{
// To store player first name
char firstName[20];
// To store player last name
char lastName[20];
// To store player 6 judge score
float score[6];
};// End of structure
// Function to read file and store it in structure objects
int readFile(struct playerScore player[])
{
// To store number of records
int countRecord = 0;
// Loops variable
int c;
// File pointer declared
FILE *fRead;
// Opens the file for reading and checks whether it can be opened or not
if ((fRead = fopen("ScoreJudge.txt", "r")) == NULL)
{
// If unable to open shows error message
printf("Error! in opening file for reading");
// Program exits if the file pointer returns NULL.
exit(1);
}// End of if condition
// Loops till end of file
while(!feof(fRead))
{
// Reads first name and stores it in structure object countRecord index position's data member firstName
fscanf(fRead,"%s ", player[countRecord].firstName);
// Reads last name and stores it in structure object countRecord index position's data member lastName
fscanf(fRead," %s", player[countRecord].lastName);
// Loops 6 times for scores
for(c = 0; c < 6; c++)
// Reads score and stores it in structure object countRecord index position's data member score index position c
fscanf(fRead, "%f", &player[countRecord].score[c]);
// Increase the record counter by one
countRecord++;
}// End of while condition
// Closes the file
fclose(fRead);
// Returns number of records
return countRecord;
}// End of function
// Function to display player information
void displayRecord(struct playerScore player[], int countRecord)
{
// Loop variable
int c, d;
// Loops till number of records
for(c = 0; c < countRecord; c++)
{
// Displays each player first and last name
printf(" First Name: %s Last Name: %s ", player[c].firstName, player[c].lastName);
printf(" Six Judges scores: ");
// Loops 6 times for scores
for(d = 0; d < 6; d++)
// Displays each player 6 scores
printf(" Score - %d %5.2f", (d + 1), player[c].score[d]);
}// End of for loop
}// End of function
// Function to display gold medalist player information
void goldMedal(struct playerScore player[], int countRecord)
{
// Loop variable
int c, d;
// To store minimum, maximum and total score of each payer
float min, max, total;
// To store average score of each player
float average[countRecord];
// To store found position.
int position;
// Loops till number of records
for(c = 0; c < countRecord; c++)
{
// Stores first score of each player as minimum score
min = player[c].score[0];
// Stores first score of each player as maximum score
max = player[c].score[0];
// Stores zero as total for each player
total = 0;
// Finds minimum and maximum score of each player
// Loops 6 times for scores starting from one because zero index position used above for min and max
for(d = 1; d < 6; d++)
{
// If current player's current score is greater than the earlier maximum score
if(player[c].score[d] > max)
// Update the maximum to current player's current score
max = player[c].score[d];
// If current player's current score is less than the earlier minimum score
if(player[c].score[d] < min)
// Update the minimum to current player's current score
min = player[c].score[d];
}// End of inner for loop
// Calculates total excluding minimum and maximum score
// Loops 6 times for scores
for(d = 0; d < 6; d++)
{
// Checks if current player's current score is not equals to minimum and not equals to maximum
if(player[c].score[d] != min && player[c].score[d] != max)
// Add the score to total
total += player[c].score[d];
}// End of inner for loop
// Calculates each player average excluding minimum and maximum score
average[c] = (total / 4);
}// End of outer for loop
// Finds the maximum average
// Stores the starting average as the maximum average
max = average[0];
// Loops till number of records starting from one index position because zero index position used above
for(c = 1; c < countRecord; c++)
{
// Checks if the current average is greater than the earlier maximum
if(average[c] > max)
{
// Update the maximum to current average
max = average[c];
// Stores the loop counter value as the current maximum position
position = c;
}// End of if condition
}// End of for loop
// Displays the top average scorer
printf(" Person Secure Gold Medal: ");
printf(" First Name: %s Last Name: %s Average Score %.2f: ", player[position].firstName, player[position].lastName, average[position]);
}// End of function
// main function definition
int main()
{
// Declares an array of structure object of MAX size
struct playerScore player[MAX];
// Calls the function to read file contents and store the number of records returned by the function
int numberOfRecords = readFile(player);
// Calls the function to display all players information
displayRecord(player, numberOfRecords);
// Calls the function to display the gold medalist player information
goldMedal(player, numberOfRecords);
}// End of main function
Sample Output:
First Name: Sean
Last Name: White
Six Judges scores:
Score - 1 96.00
Score - 2 98.00
Score - 3 88.00
Score - 4 99.00
Score - 5 98.00
Score - 6 100.00
First Name: Chloe
Last Name: Kim
Six Judges scores:
Score - 1 92.00
Score - 2 99.00
Score - 3 100.00
Score - 4 98.00
Score - 5 99.00
Score - 6 97.00
First Name: Ben
Last Name: Ferguson
Six Judges scores:
Score - 1 90.00
Score - 2 95.00
Score - 3 91.00
Score - 4 85.00
Score - 5 94.00
Score - 6 88.00
Person Secure Gold Medal:
First Name: Chloe
Last Name: Kim
Average Score 98.25:
ScoreJudge.txt file contents
Sean White 96 98 88 99 98 100
Chloe Kim 92 99 100 98 99 97
Ben Ferguson 90 95 91 85 94 88
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.