C++ code only......
Overview:
Synopsis: Type in a word and get a point value. A point value is the sum of the points of the individual letters multiplied by any bonus multipliers (defined later).
In both Words With Friends and the scrabble game, a individual letters in a word are given specific values.
Your program will let me keep typing in words and giving me the point value until I stop the program.
---------------------------------------------------------------------------------------------------------------------------------------------
Basic Point values:
For this lab, calculate the value of a word with the following specific rules:
A, E, I, O, S, U are worth 1 point
D, F, G, L, M, N, R, T are worth 2 points
B, C, K, P, Y are worth 3 points
H, J, Q, V, W, X, Z are worth 5 points.
If the word was CAT, the value would be 3 + 1 + 2 or 6 points.
-------------------------------------------------------------------------------------------
Bonus Point multipliers
DOUBLE: Any word that contains two (or more) of the same letter in a row has it's value doubled. Some examples are 'asset' and 'little'. You can only double things once.
TRIPLE: Any word that has three (or more) 1 point letters has it's value triples. You can only triple a word once. 'asset' has 4 single point letters (a, s, s, and e), while little only has 2 (i and e)
You can both DOUBLE and TRIPLE a word.
--------------------------------------------------------------------------------------------------------------------------------------------
Dictionary Lookup
You also need to check to see if the word is in a dictionary. There's one at
http://www.csit.parkland.edu/~kurban/permanent/lists/ and it's called web2.txt
It contains one word per line and is already sorted. You can make your own smaller dictionary to test it if you like.
Please do not turn in the dictionary.
-----------------------------------------------------------------------------------------------------------------------
Requirements
Your program will ask the user for a word (without spaces) and print it's value.
Ignore any special characters or numbers that are entered. [I won't include these in my test cases].
If the word isn't in the dictionary, report that the word isn't a valid word.
You HAVE to use my rules or you will receive 0 credit!
----------------------------------------------------------------------------------------------------------
Examples:
asset = (1 + 1 + 1 + 1 + 2) * 2 * 3 = 18 (double letters, 3 single point letters)
little = (2 + 1 + 2 + 2 + 2 + 1) * 2 = 24 (double letters)
abacadabra = (1 + 3 + 1 + 3 + 1 + 2 + 1 + 3 + 2 + 1) * 3 = 56 (3 single point letters)
football = (2 + 1 + 1 + 2 + 3 + 1 + 2 + 2) * 2 * 3= 84 (double letters only double once, 3 single point letters)

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

Ver imagen lhmarianateixeira
Ver imagen lhmarianateixeira
Ver imagen lhmarianateixeira