Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello there, can you help with code using C++ on unordered_map.h file. I had compiler syntax errors. There are three functions implementation errors: 1) GetLetterValue

Hello there, can you help with code using C++ on unordered_map.h file. I had compiler syntax errors. There are three functions implementation errors:

1) GetLetterValue has incorrect implementation

2) LoadFile has an implementation error

3) FindWordScore has implementation issue and standard for loop iterator error

Here are my codes; I'll give you a thumbs up, thank you.

class DSA_Lab6 { friend class DSA_TestSuite_Lab6; // Giving access to test code

// Data members

int mLetterValues[26]; std::unordered_map mScrabbleMap;

public: // In Scrabble, each letter has a value associated with it. // This method will populate the array of letter values. // // In: _letterValues The array of 26 values.

void PopulateLetterValues(const int* _letterValues) { // TODO: Implement this method for (int i = 0; i

int GetLetterValue(char _letter) const { // TODO: Implement this method

int scoreSingleLetter;// =mLetterValues[_letter-97];

char t = toupper(_letter); scoreSingleLetter += mLetterValues[int(t) - 65]; return scoreSingleLetter;

std::cout

// Get the value of a word // This is done by adding up the values of each letter in the word // // In: _word The word to get the value of // // Return: The total value of the word.

int GetWordValue(const std::string& _word) const { // TODO: Implement this method.

int world = 0; for (int i = 0; i

// Create a pair to add into the scrabbleMap // This will have a \"first\" of the word, and a \"second\" of the total score // // In: _word The word for the pair // // Return: A pair that contains the word and the total score.

std::pair CreatePair(const std::string& _word) const { // TODO: Implement this method.

int volt = CreatePair(_word); std::pair isPair; isPair.first = _word; isPair.second = volt; return isPair; }

// Load a file containing all of the possible scrabble words, along with their values // This file will contain one word per line // In: _filename The name of the file to load // // Note: You may want to use one or more existing methods to help.

void LoadWords(const char* _filename) { // TODO: Implement this method .

std::fstream fileData; //open file.

fileData.open(\"_filename\"); //check file

if (!fileData) { std::cout

else { //create bank object.

std::string line; //read file data.

while (getline(fileData, line)) { if (line.length()) { std::stringstream split(line); std::string huffman; std::vector _data; while (split >> huffman) { _data.push_back(huffman); } mScrabbleMap[_data[0]] = GetWordValue(_data[0]); } } } }

// Searches for a word in the map, and retrieves the score for that word // // In: _word The word to search for // // Return: The word score for _word (or -1 if not found).

int FindValueInMap(const std::string& _word) { // TODO: Implement this method.

unordered_map ::iterator it; for (it = mScrabbleMap.begin(); it != mScrabbleMap.end(); it++) { //find word.

if (it->first == _word) { return it->second; } } return -1; } };

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

Explain the idea behind the Dividend Discount Model (DDM).

Answered: 1 week ago