CIS71 Lab 12 - Noun Plurals (Strings) DUE: 10AM, Nov 22, 2006
Scope:
String manipulation
Reading: Chapter 9
PartA: Write a function: void plurals(char * noun, char * plural) that takes an input word (noun) and outputs its plural (plural) on the basis of these
rules:
a. If the noun ends in y, remove the y and add ies
b. If
the noun ends in s, ch, or sh, add es
c. In all other cases, just add s
Hints: given the string noun, you should first check its
length L by using strlen function. Then, you should
check if the last letter of noun is y. If yes, you should copy the first L-1 letters of noun to plural,
and concatenate string ies to it. If no, you should
check if noun ends with s, ch, or sh and make the similar actions. In all other cases, you should just copy
noun to plural and then concatenate s to its end. You should
remember to add null symbol \0 after the last letter in plural string.
PartB:
Using the plurals function from PartA, write a
program which, in a loop:
1. Prompts user to enter a string and reads it from input
2. Passes the string to function plurals, which finds its
plural
3. Prints out the plural string
4. Prompts the user to do another by typing y, or to quit
the program by typing anything else.
Sample Output:
Supply noun:chair
The plural is:chairs
Do Another (y/n)?y
Supply noun:dairy
The plural is:dairies
Do Another (y/n)?y
Supply noun:boss
The plural is:bosses
Do Another (y/n)?y
Supply noun:circus
The plural is:circuses
Do Another (y/n)?y
Supply noun:fly
The plural is:flies
Do Another (y/n)?y
Supply noun:dog
The plural is:dogs
Do Another (y/n)?y
Supply noun:clue
The plural is:clues
Do Another (y/n)?y
Supply noun:dish
The plural is:dishes
Do Another (y/n)?n
Press any key to continue
Deliverables:
Submit your program; attach
results of test runs of the program.