
he 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(). It should have the following signature:
void readData(string names[], int scores[], int size)
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 displayData(const string names[], const int scores[], int size)
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 sorting
#include <iostream>
#include<string>
using namespace std;
// function declarations
void initializeArrays(string names[], int scores[], int size);
void sortData(string names[], int scores[], int size);
void displayData(const string names[], const int scores[], int size);
int main()
{
int size;
cout << "How many scores will you enter?:";
cin >> size;
string* names = new string[size];
int* scores = new int[size];
initializeArrays(names, scores, size);
sortData(names, scores, size);
displayData(names, scores, size);
cin.get();
system("PAUSE");
return 0;
}
/* This function will get the user inputs* and populate those values into an array*/
void initializeArrays(string names[], int scores[], int size)
{
for (int i = 0; i < size; i++)
{
cout << "Enter the name for score #" << i + 1 << ":";
cin >> names[i];
cout << "Enter the score for score #" << i + 1 << ":";
cin >> scores[i];
}
}
/* This function will sort the array based on scores*/
void sortData(string names[], int scores[], int size)
{
string temp;
int tempScore;
for (int i = 0; i < size; i++)
{
for (int j = i + 1; j < size; j++)
{
if (scores[i] < scores[j])
{
temp = names[i];
names[i] = names[j];
names[j] = temp;
tempScore = scores[i];
scores[i] = scores[j];
scores[j] = tempScore;
}
}
}
}
// This function will display the output
void displayData(const string names[], const int scores[], int size)
{
cout << "Top Scores :" << endl;
for (int i = 0; i < size; i++)
{
cout << names[i] << ": " << scores[i] << endl;

Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 3 images

- Using C++ Programming language: Assume you want a function which expects as parameters an array of doubles and the size of the array. Write the function header that accepts these parameters but is defined in such a way that the array cannot be modified in the function. You can use your own variable names for the parameters.arrow_forwardIn C++, Write a function named that accepts argc and args with the same data type as command line arguments (int argc, char * args[]). It will return two boolean values. It checks whether each of command line argument ending with a comma (‘,’) or not. If they all are, it will return true. Otherwise, it returns false. It will also return true if there is no argument is given. In addition, it also returns another boolean flag indicating whether one of the arguments is just a comma only.For this question, you are not allowed to use string class and its method or string function such as strlen.arrow_forwardC programming:you are to design and write a menu driven program as shown by the sample menu below. should the user select [G] the program will ask the user to enter a single deposit into the bank account(this would be a 1D array) the rest of the menu options are self-explanatory. demonstrate a bubble sort, the usee of user preventive coding, switch statement, demonstrate the use of functions along will call by value and call by reference where necessary. Program Menu System (Your solution should display this menu) **** BANKING MAIN MENU*** [G]et a new deposit [S]um of all deposits…arrow_forward
- 16. NULL can be assigned to a void pointer. True O Falsearrow_forwardC++ Use 2 D arrays String and float Make simplearrow_forwardIn C++ language Write a function that takes a 1 Demensional array and an integer n and reutrns the number of times 'n' appears in the array. If 'n' does not appear in the array, return -1.arrow_forward
- When a function accepts several arguments, how important is it what order they are sent in?arrow_forwardIn C++, When an array is passed to a function as a pointer, the function doesn't know the size of the array. List 3 ways to handle this problem.arrow_forwardAssume the following main module is in a program that includes the binarysearch function that was shown in a chapter. Why doesn't the pseudocode in the main module work?arrow_forward
- When a function accepts several arguments, how important is it what order those arguments are sent in?arrow_forwardpython function!: a function called popular_color with one parameter, of type dict[str, str] of names and favorite colors. The return type is a str and it is the most commonly occuring color. If two colors are tied for popularity, the first color shown will be picked.arrow_forwardAlert: Don't submit AI generated answer and please submit a step by step solution and detail explanation for each steps. Write a python program using functionsarrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





