Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that records high-score data for a fictitious game. The program

ID: 3670313 • Letter: W

Question

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 exactly like this:

The data must be stored in two arrays: an array of strings named names, and an array of ints named scores. These arrays must be declared in the main function.

All of the user input should be done in a function named initializeArrays(). It should have the following signature:

You must also write two more functions: one to sort both arrays, and one to display the final list of names and scores. They should have the following signatures.

The main function should be very short. It should just declare the arrays and then invoke these three functions.

Explanation / Answer

#pragma once

#include <string>

#include <unordered_map>

#include <vector>

#include <iostream>

#include <memory>

class Sample : public std::enable_shared_from_this<Sample>

{

static void main(std::vector<std::wstring> &args)

{

std::unordered_map<std::wstring, int> dataMap;

std::shared_ptr<Scanner> keyboard1 = std::make_shared<Scanner>(System::in);

std::shared_ptr<Scanner> keyboard2 = std::make_shared<Scanner>(System::in);

// Ask the user for the names and scores for 5 people.

for (int i = 1;i <= 5;i++)

{

std::wcout << i << std::wstring(L". Enter the name ") << std::endl;

std::wstring name = keyboard1->next();

std::wcout << i << std::wstring(L". Enter the score") << std::endl;

int score = keyboard2->nextInt();

dataMap[name] = score;

}

std::shared_ptr<Set<std::unordered_map::Entry<std::wstring, int>>> s = dataMap.entrySet();

std::vector<std::unordered_map::Entry<std::wstring, int>> l(s);

Collections::sort(l,std::make_shared<ComparatorAnonymousInnerClassHelper>());

for (auto entry : l)

{

std::wcout << std::wstring(L"Name of Student== ") << entry.first << std::wstring(L" and his Score==") << entry.second << std::endl;

}

}

private:

class ComparatorAnonymousInnerClassHelper : public std::enable_shared_from_this<ComparatorAnonymousInnerClassHelper>, public Comparator<std::unordered_map::Entry<std::wstring, int>>

{

public:

ComparatorAnonymousInnerClassHelper()

{

}

virtual int compare(std::unordered_map::Entry<std::wstring, int> arg0, std::unordered_map::Entry<std::wstring, int> arg1)

{

return (arg1.getValue()->compare(arg0.getValue()));

}

};

};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote