Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The American Equities investment company offers a wide range of investment opportunities ranging from mutual funds to bonds. Investors can check the value of their
The American Equities investment company offers a wide range of investment
opportunities ranging from mutual funds to bonds. Investors can check the value of their portfolio from the American Equities web page. Information about
personal portfolios is protected via encryption and can only be accessed using
a password. The American Equities company requires that a password consist of
characters, of which must be letters and the other digits. The letters and digits can be arranged in any order. For example,
rtAAq
actyN
LoDwa
myNUM
are all valid passwords. However, the following are all invalid:
theNEw It contains more than characters also more than
letters
bemoon It contains less than digits.
$retrn It contains only digits and has an invalid character $
LESSON Characters and Strings
American Equities needs a program for their web page that determines whether or
not an entered password is valid. The program americanequities.cpp from the
Lab folder performs this task. The code is the following:
This program tests a password for the American Equities
web page to see if the format is correct
Place Your Name Here
#include
#include
#include
using namespace std;
function prototypes
bool testPassWordchar;
int countLetterschar;
int countDigitschar;
int main
char passWord;
cout "Enter a password consisting of exactly
"letters and digits:" endl;
cin.getlinepassWord;
if testPassWordpassWord
cout "Please wait your password is being verified" endl;
else
cout "Invalid password. Please enter a password
"with exactly letters and digits" endl;
cout "For example, myRuN is valid" endl;
Fill in the code that will call countLetters and
countDigits and will print to the screen both the number of
letters and digits contained in the password.
return ;
Lesson A
testPassWord
task: determines if the word in the
character array passed to it contains
exactly letters and digits.
data in: a word contained in a character array
data returned: true if the word contains letters &
digits, false otherwise
bool testPassWordchar custPass
int numLetters, numDigits, length;
length strlencustPass;
numLetters countLetterscustPass;
numDigits countDigitscustPass;
if numLetters && numDigits && length
return true;
else
return false;
the next functions are from Sample Program
countLetters
task: counts the number of letters both
capital and lower casein the string
data in: a string
data returned: the number of letters in the string
int countLetterschar strPtr
int occurs ;
whilestrPtr
if isalphastrPtr
occurs;
strPtr;
return occurs;
continues
LESSON Characters and Strings
countDigits
task: counts the number of digits in the string
data in: a string
data returned: the number of digits in the string
int countDigitschar strPtr
int occurs ;
whilestrPtr
if isdigitstrPtr isdigit determines if
the character is a digit
occurs;
strPtr;
return occurs;
Exercise : Fill in the code in bold and then run the program several times
with both valid and invalid passwords. Read through the program and
make sure you understand the logic of the code.
Exercise : Alter the program so that a valid password consists of characters, of which must be digits and the other letters.
Exercise : Adjust your program from Exercise so that only lower case
letters are allowed for valid passwords.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started