Sei sulla pagina 1di 2

Program 7: Scrabble and Strings

1. Write a function that returns the Scrabble value of a word:


int scrabbleValue(char* word);
The Scrabble value of a letter varies depending on its rarity, and the
Scrabble value of a word is the sum of the Scrabble values of its letters.
AEILNORSTU have value 1, DG have value 2, BCMP have value 3, FHVWY
have value 4, K has value 5, JX have value 8, and QZ have value 10. Count
upper and lower case as equivalent.
The input strings may contain both upper and lower case (even though
Scrabble tiles are only upper case.) If a letter is non-alphabetic, count it
as a zero.
Write the function WITHOUT using array indexes.
programs like strlen.

See the example

Write a main() that tests your function by interacting with the user:
Enter a word: pitfall
Scrabble value: 12
Don't do I/O in the function, only in the main() function. Follow
specifications exactly, including the name of the function. Document your
function nicely, use sensible layout and indenting, use sensible variable
names, and test thoroughly.
The main() function keeps asking the user for a word and printing out
its scrabble score until the user enters a single letter Q.
Put all user interaction in the main() function. Dont use any global
variables. Turn in a source program using the Blackboard assignment
tool. I may cut-and-paste your function into my testing program, so your
function must follow specifications.

2. Write a main() that asks the user for a word or phrase and then
prints out an inverted triangle based on that phrase. Do this by printing
the full phrase on line one with a space after each letter, then print the
phrase on line two starting with a space and having a space after each
letter but omitting the last letter, then print the phrase on line three
starting with two spaces and having a space after each letter but omitting
the last two letters and so on. Continue until there are no characters left:

enter your word: ABRACADABRA


A B R A C A D A B R A
A B R A C A D A B R
A B R A C A D A B
A B R A C A D A
A B R A C A D
A B R A C A
A B R A C
A B R A
A B R
A B
A

Assume a reasonable maximum length for the phrase. The user may
enter any phrase with any printable characters although the output looks
better if the user enters only upper case. If you want, you might do this
all in the main() function. But it would probably be better to somehow
use a function. You can use any of the standard string functions, so for
example you can use strlen() and strcat(). Others might be
helpful. Turn in a source program using the Blackboard assignment tool.
Grading: Grading will be based both on the style of the programs (good
variable names, nice formatting, and sensible code) and correctness.
Correctness will be tested with a number of test strings. Turn in just one
source file with two mains, labeled main01 and main02.

Potrebbero piacerti anche