Practical work
Write the following exercises, each in a separate file. Filenames should be:
1) Write the following functions. Each of these functions should have a single parameter -- accepting a c-style string as an argument. The function should only do what is specified (note that none of these functions do any output to the screen). Your functions should use const in the prototype wherever it is appropriate:
(user input is underlined, to distinguish it from output)
Input a line of text, up to 100 characters:
> The quick brown fox jumped. The lazy dog, he was jumped over.
A) Count the number of vowels in the string
B) Count the number of consonants in the string
C) Convert the string to uppercase
D) Convert the string to lowercase
E) Display the current string
F) Enter another string
M) Display this menu
X) Exit the program
Enter your menu selection: a
Number of vowels: 16
Enter your menu selection: B
Number of consonants: 31
Enter your menu selection: c
Enter your menu selection: e
The string:
THE QUICK BROWN FOX JUMPED. THE LAZY DOG, HE WAS JUMPED OVER.
Enter your menu selection: D
Enter your menu selection: E
The string:
the quick brown fox jumped. the lazy dog, he was jumped over.
Enter your menu selection: f
Input a new line of text, up to 100 characters:
> Mary Had A Little Lamb. His name was Fleecy Pete.
Enter your menu selection: C
Enter your menu selection: e
The string:
MARY HAD A LITTLE LAMB. HIS NAME WAS FLEECY PETE.
Enter your menu selection: d
Enter your menu selection: E
The string:
mary had a little lamb. his name was fleecy pete.
Enter your menu selection: b
Number of consonants: 24
Enter your menu selection: a
Number of vowels: 14
Enter your menu selection: x
Goodbye
2) Write a function, called ToPigLatin, which is described below:
· char* ToPigLatin(char* word);
This function receives a c-style string (word) as a parameter.
(user input is underlined, to distinguish it from output)
Input 5 words: Flower yellow bypass apple Igloo
Pig Latin version of the 5 words:
Owerflay ellowyay ypassbay appleway Iglooway
Input 5 words: string Hamburger Rhythm queen zippitydoodah
Pig Latin version of the 5 words:
ingstray Amburgerhay Ythmrhay ueenqay ippitydoodahzay
Материалы на данной страницы взяты из открытых источников либо размещены пользователем в соответствии с договором-офертой сайта. Вы можете сообщить о нарушении.