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()...
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...
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.
Please, I need full explanation and correct answers. Thank you. 1) What characteristics distinguish capital assets...
Please, I need full explanation and correct answers. Thank you. 1) What characteristics distinguish capital assets from inventory? 2) What does it mean when a capital asset (such as equipment) is impaired? 3) For each type of business, explain how the capital asset (PP&E) contributes to generating revenue by the business: Business Type of Asset Lawn care Lawn mower Jewellery store Zamboni Arena Display cases Doctors office Waiting room furniture Auto parts manufacturer Warehouse
4. ( Just true or false for each, no need for explanation,thank you) a.If factors being...
4. ( Just true or false for each, no need for explanation,thank you) a.If factors being studied cannot be controlled, the data are said to be observational.True or False b.After rejecting the null hypothesis of equal treatments, a researcher decided to compute a 95 percent confidence interval for the difference between the mean of treatment 1 and mean of treatment 2 based on Tukey's procedure. At α = .05, if the confidence interval includes the value of zero, then we...
Write a program that calculates the compound interest for an investment. (C++ coding language) If you...
Write a program that calculates the compound interest for an investment. (C++ coding language) If you deposit an amount of money P , the principal, at an interest rate r then the interest will compound over time. This means that the interest earned each period becomes part of the principal and the next time you get interest you earn interest on the interest. This is known as compounding. The equation for compound interest is ( r)n·t Pn=P0 1+n where P0...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT