Programming Assignment 6 Due April 15, 2015 at 11:59 PM Objectives

advertisement
Programming Assignment 6
Due April 15, 2015 at 11:59 PM
Objectives
This assignment will involve practice with string objects, using the string class library.
Task
Write the following programs, each in a separate file. Filenames should be:
• password.cpp
• piglatin.cpp
(Note that the filenames are all lowercase)
Exercise 1
Filename: password.cpp
This is based on programming challenge 12 in chapter 10 of the textbook.
Many computer systems, web sites, etc. allow user accounts with passwords. When allowing
users to choose passwords, many systems have requirements regarding the strength of the chosen
password.
Write a program that allows a user to choose a password. The password is to be a single string of
characters that contains no white space.
• Your program needs to require that the chosen password meets the following criteria:
– The password must be at least 6 characters long
– The password must contain at least one lowercase letter
– The password must contain at least one uppercase letter
– The password must contain at least one digit
• Whenever the user enters a password that fails to meet one or more of these criteria:
– Display a an error message informing the user of each criteria they have not met. (Note:
There could be multiple ones).
– Make them re-enter a new password
• Once the user enters a VALID password, ask them to enter it once more to verify their choice.
– If this entry matches the original chosen password, print a message saying that their
password is now set
– If this entry does not match the chosen password, make them start the process over from
the beginning
Sample run: (user input underlined)
1
Enter your password: mommy1
Password needs to contain at least one uppercase letter.
Enter your password: Mom2
Password needs to have 6 or more characters.
Enter your password: dad
Password needs to have 6 or more characters.
Password needs to contain at least one uppercase letter.
Password needs to contain at least one digit.
Enter your password: MYNAME4
Password needs to contain at least one lowercase letter.
Enter your password: Friend8
Now re-enter your password for verification: Friend
Password does not match. Start over.
Enter your password: ClamChowder66
Now re-enter your password for verification: ClamChowder66
You have now entered a valid password.
Exercise 2
Filename: piglatin.cpp
Write a function, called ToPigLatin, which is described below:
• Here is a starter file, which contains a main test program, as well as the function prototype,
which is:
string ToPigLatin(const string& word);
This function receives a string object (word) as a parameter, passed by const reference (so
that the original won’t change).
• You are to define this function so that it returns a string object that is the ”Pig Latin”
translation of the original incoming string (word).
• For our purposes, we will use the following as the rules for translation of a word into ”Pig
Latin”:
– A word is a consecutive sequence of letters (a-z, A-Z) or apostrophes. You may assume
that the input to the function will only be a single ”word”. Examples: Zebra , doesn’t
, apple
– If a word starts with a vowel, the Pig Latin version is the original word with ”way”
added to the end
2
– If a word starts with a consonant, or a series of consecutive consonants, the Pig Latin
version transfers all consonants up to the first vowel to the end of the word, and adds
”ay” to the end.
– The letter ’y’ should be treated as a consonant if it is the first letter of a word, but
treated as a vowel otherwise.
– Optional BONUS feature, for Extra Credit: If the original word is capitalized, the new
Pig Latin version of the word should be capitalized in the first letter (i.e. the previous
capital letter may not be capitalized any more).
• In the starter file is a main() program that I have already provided you with for testing. This
program prompts the user to type in 5 words, then it calls the function for each of them
and prints the converted version of each of the 5 strings. Note that the main() function does
all of the output – your function should do NO output (just the appropriate conversion and
return). The output from your test runs should match mine exactly. Do not change the
main() program in any way.
Sample runs: (user input underlined)
Sample Run 1
Input 5 words: Flower yellow bypass apple Igloo
Pig Latin version of the 5 words:
Owerflay ellowyay ypassbay appleway Iglooway
Sample Run 2
Input 5 words: string Hamburger Rhythm queen zippitydoodah
Pig Latin version of the 5 words:
ingstray Amburgerhay Ythmrhay ueenqay ippitydoodahzay
Requirements
• No global variables, except where specified.
• You may use any of these libaries:
– iostream
– iomanip
– cctype
– string
• Readable and well-documented source code.
Submitting
Submit only your source code files through Blackboard by April 15 at 11:59 PM. This will consist
of the following files:
• password.cpp
• piglatin.cpp
3
Download