Question

In: Computer Science

*Need in C language also need full documentation/explanation of each line* Thank you! Write a program...

*Need in C language also need full documentation/explanation of each line*
Thank you!

Write a program that records high-score data from a simulated FIFA soccer game available online. The program will ask the user to enter the number of scores, create two dynamic arrays sized accordingly, ask the user to enter the indicated number of names and scores, and then print the names and scores sorted by score in descending order.
The output from your program should look exactly like this (given the same inputs in bold):
How many FIFA scores will you enter?: 5
Enter the name for Player #1: Ronaldo
Enter the score for FIFA scorer #1: 10400
Enter the name for Player #2: Didier
Enter the score for FIFA scorer #2: 9800
Enter the name for Player #3: Pele
Enter the score for scorer #3: 12300
Enter the name for Player #4: Kaka
Enter the score for scorer #4: 8000
Enter the name for Player #5: Cristiano
Enter the score for scorer #5: 8400
Top Scorers:
Pele: 12300
Ronaldo: 10400
Didier: 9800
Cristiano: 8400
Kaka: 8000

Process returned 0 (0x0) execution time : 23.997 s
Press any key to continue.

Additional Requirements
The data must be stored in two dynamic arrays: an array of strings named names, and an array of ints named scores. These arrays must be declared and allocated using "new" in the main function.
The user input of the names and scores should be done in a function named readData() and should include appropriate input validation. It should have the following signature:
void readData(string names[], int scores[], int size) // void function for user input to be stored in two arrays
You must also write two more functions: one to sort both arrays in descending order by score, and one to display the final list of names and scores. They should have the following signatures.
void sortData(string names[], int scores[], int size) // void function with a descending sort on multiple arrays
void displayData(const string names[], const int scores[], int size) // void function displays content from two arrays
The main function should be very short. It should just get the number of scores, allocate the two arrays, invoke these three functions, and then deallocate the arrays.
Some of you may not have studied selection sorting algorithms in the Gaddis text Chapter 8 or reviewed the selection sort algorithm covered in the lesson notes from the array review module. You may use as much code from the Gaddis sort algorithms as you like but first make sure to understand and trace the sort and the necessary swaps made or you may use our own algorithm. You may use C++'s built-in swap() function, but do not use C++'s sort() function.

Solutions

Expert Solution

#include <iomanip>
#include<iostream>
#include<string.h>
using namespace std;
int size;
//function definition
void readData(string names[], int scores[], int size)
{
cout<<"How many FIFA scores will you enter ? : ";
cin>>size;
::size=size;//assigning local varible value to global variable
for(int i=0;i<size;i++)
{
cout<<"Enter the name for player #"<<i+1<<" : ";
cin>>names[i];
cout<<"Enter the score for FIFA scorer #"<<i+1<<" : ";
cin>>scores[i];
}
}
void displayData(const string names[], const int scores[], int size)
{
cout<<"Top Scores :\n";
for(int i=0;i<size;i++)
{
cout<<left<<setw(25)<<names[i]<<scores[i]<<"\n";
}
}
void sortData(string names[], int scores[], int size)
{
string temp_name=names[0];
int temp_scores=scores[0];

for(int i=0;i<size;i++)//iterations for array sorting
{
for(int j=i;j<size;j++)
{
if(scores[j]<scores[j+1])
{
temp_scores=scores[j+1];
temp_name=names[j+1];
scores[j+1]=scores[j];
names[j+1]=names[j];
names[j+1]=temp_name;
scores[j]=temp_scores;
}
}
}
}

int main()
{
int *scores = new int[10]();//allocation of dynamic memory
string *names=new string[10]();
readData(names,scores,size);//function calls
sortData(names,scores,size);
displayData(names,scores,size);
delete [] scores;//deallocation of dynamic memmory
delete [] names;
return 0;
}

OUTPUT

How many FIFA scores will you enter ? : 5
Enter the name for player #1 : Ronaldo
Enter the score for FIFA scorer #1 : 10400
Enter the name for player #2 : Didier
Enter the score for FIFA scorer #2 : 9800
Enter the name for player #3 : Pele
Enter the score for FIFA scorer #3 : 12300
Enter the name for player #4 : kaka Kaka
Enter the score for FIFA scorer #4 : 8000
Enter the name for player #5 : Cristiano
Enter the score for FIFA scorer #5 : 8400
Top Scores :
Ronaldo 10400
Didier 12300
Pele 9800
Kaka 8400
Cristiano 8000



Related Solutions

Hello! *Need in C language also need full documentation/explanation of each line* Designing and implementing an...
Hello! *Need in C language also need full documentation/explanation of each line* Designing and implementing an Array of Structures - Course Grade Write a program that uses a structure to store the following data: Member Name Description Name Student name Idnum Student ID number Scores [NUM_TESTS] an array of test scores Average Average test score Grade Course grade Declare a global const directly above the struct declaration
const int NUM_TESTS = 4; //a global constant The program should ask the...
I need specific codes for this C program assignment. Thank you! C program question: Write a...
I need specific codes for this C program assignment. Thank you! C program question: Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and...
C# language Question: You need to write a program for students who receive bursaries in the...
C# language Question: You need to write a program for students who receive bursaries in the department, managing the free hours they have to do. For each recipient you store the recipient’s name and the number of hours outstanding. All recipients start with 90 hours. Implement class Recipients which has the private attributes Name and Hours. In addition to the constructor, the class has the following methods: public String getName() // Returns the name of the recipient public int getHours()...
Write a general example of interrupts in C language with comments. Thank you
Write a general example of interrupts in C language with comments. Thank you
C LANGUAGE ONLY Write a C program to count the frequency of each element in an...
C LANGUAGE ONLY Write a C program to count the frequency of each element in an array. Enter the number of elements to be stored in the array: 3 Input 3 elements of the array: element [0]: 25 element [1]: 12 element [2]: 43 Expected output: The frequency of all elements of an array: 25 occurs 1 times 12 occurs 1 times 3 occurs 1 times
PLEASE INCLUDE #FOR EACH LINE EXPLANATION Write a PYTHON PROGRAM that prompts for an integer and...
PLEASE INCLUDE #FOR EACH LINE EXPLANATION Write a PYTHON PROGRAM that prompts for an integer and prints the integer, but if something other than an integer is input, the program keeps asking for an integer. Here is a sample session: Input an integer: abc Error: try again. Input an integer: 4a Error: try again. Input an integer: 2.5 Error: try again. Input an integer: 123 The integer is: 123 Hint: the string isdigit method will be useful to solve this...
I need to write a program in C with the following specification * ​​​​​​​Line one of...
I need to write a program in C with the following specification * ​​​​​​​Line one of the standard input will have the total number of people which must not be greater than 10 * Each of the subsequent lines of input will be the first name of a person and their number (ex. "Adam 85") one space between name and number * Each name must be a maximum of 14 characters * Put the first names into an array called...
Program this in C thank you PROBLEM DESCRIPTION: Write a program to implement the following requirement:...
Program this in C thank you PROBLEM DESCRIPTION: Write a program to implement the following requirement: The program will read from standard input two things - a string str1 on the first line of stdin (this string may be an empty string) - a string str2 on the second line of stdin (this string may be an empty string) Note that stdin does not end with '\n'. The program will output a string that is the concatenation of string str1...
Write a program in C++ that Copies Story.txt to DuplicateStory.txt. Each line in Story.txt will be...
Write a program in C++ that Copies Story.txt to DuplicateStory.txt. Each line in Story.txt will be written three times in DuplicateStory.txt.
Write a C++ die roller program. We need you to write a program that will roll...
Write a C++ die roller program. We need you to write a program that will roll dice for them, but not just six-sided dice. Your program needs to be able to take an input in for form nDx or ndx where the d is the letter d or D. n may or not be present. If it is, it represents the number of dice. If not, assume it is a 1. x may or may not be present. If it...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT