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...
Please write code in C, thank you. Write a program that reads a list of integers,...
Please write code in C, thank you. Write a program that reads a list of integers, and outputs whether the list contains all even numbers, odd numbers, or neither. The input begins with an integer indicating the number of integers that follow. Assume that the list will always contain less than 20 integers. Ex: If the input is: 5 2 4 6 8 10 the output is: all even Ex: If the input is: 5 1 3 5 7 9...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT