Respuesta :
Using the computational language C++ it is possible to write a code that adds the values of the letters and does the multiplication as well.
Writting the code in C++:
#include <iostream> //for input/output functions
#include <string> //for C++ style strings
#include <cctype> //for toupper utility function
#include <fstream> //for file I/O
using namespace std;
//function to calculate the score of the given word
int getScore(string word)
{
int score = 0;
int singles = 0;
char c; //variable to hold the current character
char prev='0'; //variable to hold the previous character
//'0' so that prev is not equal to c in the first place
bool doubled = false;
for(int i = 0; i < word.length(); i++)
{
c = toupper(word[i]);
switch(c)
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'S':
case 'U':
score = score+1;
singles++;
break;
case 'D':
case 'F':
case 'G':
case 'L':
case 'M':
case 'N':
case 'R':
case 'T':
score = score+2;
break;
case 'B':
case 'C':
case 'K':
case 'P':
case 'Y':
score = score+3;
break;
case 'H':
case 'J':
case 'Q':
case 'V':
case 'W':
case 'X':
case 'Z':
score = score+5;
break;
}
//if at any point, the previous character is the same as the current character, we double
if(c == prev)
doubled = true;
prev = c;
}
if(doubled) score *= 2;
//if 1 point characters are more than 3, we triple
if(singles >= 3) score *= 3;
return score;
}
//function to check if the given word is in the dictionary
bool inDictionary(string word)
{
//we assume that the dictionary is stored in a file called dictionary.txt
ifstream fin("dictionary.txt");
//check for file errors
if(!fin)
{
cout << "File did not load properly" << endl;
return false;
}
string current;
//read until the file ends
while(!fin.eof())
{
fin >> current;
//we found the word
if(current.compare(word) == 0)
return true;
}
return false;
}
int main(int argc, char const *argv[])
{
string word;
cout << "Please enter the word whose score you want to compute: ";
cin >> word;
cout << "Score is " << getScore(word) << endl;
if(inDictionary(word))
cout << "The given word was found in the dictionary." << endl;
else
cout << "The given word was not found in the dictionary." << endl;
return 0;
}
See more about C++ code at brainly.com/question/17544466
#SPJ1


