1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Wewaii [24]
3 years ago
12

Write a program that records high-score data for a fictitious game. the program will ask the user to enter five names, and five

scores. it will store the data in memory, and print it back out sorted by score. the output from your program should look approximately like this: enter the name for score #1: suzy enter the score for score #1: 600 enter the name for score #2: kim enter the score for score #2: 9900 enter the name for score #3: bob enter the score for score #3: 1012 enter the name for score #4: armando enter the score for score #4: 8000 enter the name for score #5: tim enter the score for score #5: 514
Computers and Technology
1 answer:
Harman [31]3 years ago
3 0

Scores.cpp

#include <iostream>

#include <string>

using namespace std;

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()

{

   string names[5];

   int scores[5];

   //reading names and scores

   initializeArrays(names, scores, 5);

   //sorting the lists based on score.

   sortData(names, scores, 5);

   //displaying the contents of both arrays

   displayData(names, scores, 5);

 

  return 0;

}

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];

       }

}

void sortData(string names[], int scores[], int size){

   

       int temp = 0;

       string tempStr = "";

       

       for(int i=0; i < size; i++){

               for(int j=1; j < (size-i); j++){

                      //checking max score and sorting based on it.

                       if(scores[j-1]< scores[j]){

                               //swap the elements!

                           //swapping scores

                               temp = scores[j-1];

                               scores[j-1] = scores[j];

                               scores[j]=temp;

                               

                               //swapping names

                               tempStr = names[j-1];

                               names[j-1] = names[j];

                               names[j]=tempStr;

                       }

                       

               }

       }

}

void displayData(const string names[], const int scores[], int size){

   cout<<"Top Scorers:"<<endl;

       //printing the elements up to the size of both arrays.

       for(int i=0; i<size; i++){

           cout<<names[i]<<": "<<scores[i]<<endl;

       }

}

You might be interested in
Use the variables k and total to write a while loop that computes the sum of the squares of the first 50 counting numbers, and a
pshichka [43]
Int   k=0.total=0;
while(k++<50)
    total+=k*k;
    

5 0
3 years ago
Pls help I will give points
Fed [463]

Answer:

phone !!

Explanation:

since it's a mobile app, that would apply to a handheld device !!

i hope this helps !!

3 0
3 years ago
Read 2 more answers
The computers in the administrative offices of the four schools throughout the district are networked to enable employees to acc
muminat
These computers in administrative offices or schools throughout the district that are networked to each other has the type of network most likely used by the workers is LAN network. Usually LAN networks are used in small offices or rooms.
3 0
3 years ago
Program ____ let programmers write code using a word processing-like interface.​
kati45 [8]
<span>Program "editor" </span>let programmers write code using a word processing-like interface.​

This is utilized by programming software engineers; gives them a chance to compose code utilizing a word processing like interface that usually includes functions, like, AutoCorrect and AutoComplete.it is also called text editor.
3 0
3 years ago
Write a static method called bothStart that allows the user to input two Strings and returns the String that is the longest subs
marishachu [46]

Answer:

  1.    public static String bothStart(String text1, String text2){
  2.        String s = "";
  3.        if(text1.length() > text2.length()) {
  4.            for (int i = 0; i < text2.length(); i++) {
  5.                if (text1.charAt(i) == text2.charAt(i)) {
  6.                    s += text1.charAt(i);
  7.                }else{
  8.                    break;
  9.                }
  10.            }
  11.            return s;
  12.        }else{
  13.            for (int i = 0; i < text1.length(); i++) {
  14.                if (text1.charAt(i) == text2.charAt(i)) {
  15.                    s += text1.charAt(i);
  16.                }else{
  17.                    break;
  18.                }
  19.            }
  20.            return s;
  21.        }
  22.    }

Explanation:

Let's start with creating a static method <em>bothStart()</em> with two String type parameters, <em>text1 </em>&<em> text2</em> (Line 1).  

<em />

Create a String type variable, <em>s,</em> which will hold the value of the longest substring that both inputs start with the same character (Line 2).

There are two possible situation here: either <em>text1 </em>longer than<em> text2 </em>or vice versa. Hence, we need to create if-else statements to handle these two position conditions (Line 4 & Line 13).

If the length of<em> text1</em> is longer than <em>text2</em>, the for-loop should only traverse both of strings up to the length of the <em>text2 </em>(Line 5). Within the for-loop, we can use<em> charAt()</em> method to extract individual character from the<em> text1</em> & <em>text2 </em>and compare with each other (Line 15). If they are matched, the character should be joined with the string s (Line 16). If not, break the loop.

The program logic from (Line 14 - 20) is similar to the code segment above (Line 4 -12) except for-loop traverse up to the length of <em>text1 .</em>

<em />

At the end, return the s as output (Line 21).

5 0
3 years ago
Other questions:
  • (a) Implement (in Java) the RadixSort algorithm to sort in increasing order an array of integer keys.
    10·1 answer
  • If a memory reference takes 100 nanoseconds, how long does a paged memory reference take?
    6·1 answer
  • You can minimize the Ribbon with a command contained on the _____.
    7·1 answer
  • Which of the following is a correct group scope type in AD, windows server 2016?
    6·1 answer
  • 1. Which sentence best expresses the main idea
    12·1 answer
  • The create_python_script function creates a new python script in the current working directory, adds the line of comments to it
    6·1 answer
  • In order to detect repeated lines anywhere in the input, myuniq must keep track of all of the lines it has seen as it moves thro
    9·1 answer
  • Xercise 1<br>1.<br>What is system? Explain the components of system in brief.​
    12·1 answer
  • Some people recommend deleting social media accounts because of the troubling legal and ethical implications of social media. Do
    9·1 answer
  • With which type of test question should you leave yourself extra time to answer?
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!