Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/ / This program tests a password for the American Equities / / web page to see if the format is correct / / Place

// 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 testPassWord(char[]);
int countLetters(char*);
int countDigits(char*);
int main()
{
char passWord[20];
cout << "Enter a password consisting of exactly 5"
<< "letters and 3 digits:" << endl;
cin.getline(passWord,20);
if (testPassWord(passWord))
cout << "Please wait - your password is being verified" << endl;
else
{
}
cout << "Invalid password. Please enter a password "
<< "with exactly 5 letters and 3 digits" << endl;
cout << "For example, my37RuN9 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 0;
}
Lesson 10A 189
//**************************************************************
// testPassWord
//
// task: determines if the word in the
// character array passed to it, contains
// exactly 5 letters and 3 digits.
// data in: a word contained in a character array
// data returned: true if the word contains 5 letters & 3
// digits, false otherwise
//
//**************************************************************
bool testPassWord(char custPass[])
{
int numLetters, numDigits, length;
length = strlen(custPass);
numLetters = countLetters(custPass);
numDigits = countDigits(custPass);
if (numLetters ==5 && numDigits ==3 && length ==8)
return true;
else
return false;
}
// the next 2 functions are from Sample Program 10.5
//**************************************************************
// countLetters
//
// task: counts the number of letters (both
// capital and lower case)in the string
// data in: a string
// data returned: the number of letters in the string
//
//**************************************************************
int countLetters(char *strPtr)
{
int occurs =0;
while(*strPtr !='\0')
{
if (isalpha(*strPtr))
occurs++;
strPtr++;
}
return occurs;
}
continues
190 LESSON 10 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 countDigits(char *strPtr)
{
int occurs =0;
while(*strPtr !='\0')
{
if (isdigit(*strPtr))// isdigit determines if
// the character is a digit
occurs++;
strPtr++;
}
return occurs;
}
Exercise 1: 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 2: Alter the program so that a valid password consists of 10 characters, 6 of which must be digits and the other 4 letters.
Exercise 3: Adjust your program from Exercise 2 so that only lower case
letters are allowed for valid password

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

More Books

Students also viewed these Databases questions