Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Rewrite your most recent high scores program so that each name/score pair is stored in a struct named highscore. Except as noted below, this new

Rewrite your most recent high scores program so that each name/score pair is stored in a struct named highscore. Except as noted below, this new program will continue to meet all of the requirements of your most recent high scores program. Your new program should meet the following requirements:

The highscore struct should have two fields:

an int named score

and a char array named name. The char array should have 24 elements, making the maximum length of the name 23. (If you prefer to use a char pointer and a dynamically allocated array, that is fine as well. However, this may result in a number of complications, so be prepared for the challenge.)

The data should be stored in a single array, a dynamically allocated array of highscore structs.

Your program should use three functions that accept the array of highscore structs:

void initializeData(highscore scores[], int size) void sortData(highscore scores[], int size) void displayData(const highscore scores[], int size) 

You may use any sort algorithm, but I would recommend using the selection sort from lesson 9.6. Don't use C++'s sort() function, but you can use the swap() function.

Note that when you swap your array elements, you can swap the entire struct. You don't need to swap the name and the score separately.

You may assume that the user enters names that are 23 characters or less. Getting this to work correctly if the user enters names that are too long -- that is, making it so that you put the first 23 characters in the name variable and ignore the remaining characters on the line -- is complicated. You can do this as an extra challenge if you want, but it's not required.

/*Code to edit */

#include using namespace std; int main() {

int size; int i,j; int p,q,r; int *score; char **string; cout<<"How many scores will you enter?"; cin>>size; score = new int[size]; string = new char*[size]; for( i=0;i

for( j=0;j>string[j];

cout<<"Enter the score for score#"<>score[j]; } }

/*Rewrite the code to edit to meet the requirements of this assignment. Please display the code and output produced. */

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions