Question: You will write a program using while loops (not for loops!) in this lab. You will receive no credit if you use for loops. Write

You will write a program using while loops (not for loops!) in this lab. You will receive no credit if you use for loops.

Write a program scrabble_game.cpp that reads in text one character at a time and counts the number of occurrences of the following letters: j, k, h, c, d, and e in the text, and determines a total score for the text using a point based scheme. Both lower case and upper case letters should be counted together. When a period, ., or exclamation mark, !, appears in the input text, the program prints how many of each letter above only, the total score of the text (see point assignments below), and halts. Each letter being counted is assigned a score as follows: 'e' (1 point), 'd' (2 points), 'c' (3 points), 'h' (4 points), 'k' (5 points), and 'j' (8 points). All other characters have a score of 0 points. You will compute the total score of the input text by summing the number of occurrences of a letter above multiplied by its score. For example, if the input text is: she worked hard to build the deck Just right., then the counts are 4e, 4 d, 1 c, 4 h, 2 k, and 1 j. The total score for the phrase is 4 1 + 4 2 + 1 3 + 3 4 + 2 5 + 1 8 = 49.

1. Program scrabble_game.cpp:

a. To read in a single character, use cin to read a value of type char.

b. Use a while loop to read and count the characters in the input. Read in a character, check that the input character is not the period, ., nor the exclamation mark, !, and then enter the while loop.

c. Be sure to read in the next character at the end of the while loop.

d. Lower case and upper case vowels should be counted together. Thus a text with three characters e and four characters E will have a total of 7 occurrences of e.

e. You can compute the total score using the point values of each letter we are counting as you count each letter in the while loop or after you have finished determining the counts, i.e. after the while loop.

f. Run your program on various input including boundary cases such as just a period, ., or just an exclamation mark, !, as input.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!