Question

In: Computer Science

Instructions (In C++ Please) Verification This programming lab makes use of an array of characters. The...

Instructions (In C++ Please)

Verification

This programming lab makes use of an array of characters. The program will validate the characters in the array to see if they meets a set of requirements.

Requirements:

Must be at least 6 characters long (but not limited to 6, can be greater)

Contains one upper case letter

Contains one lower case letter

Contains one digit

Complete the code attached. Must use pointer while checking the characters.

Download Source Lab 3 File:

#include using namespace std;

// Global constants const int SIZE = 80;

// The maximum size of the array const int MIN = 6;

// The minimum number characters

// Function prototypes void displayRequirements();

void displayResult(char[]);

int main()

{

char cstring[SIZE];

displayRequirements();

cout << "Enter a password: ";

cin.getline(cstring, SIZE);

displayResult(cstring);

return 0;

}

void displayRequirements()

{

// Display the password requirements.

cout << "Password Requirments:\n"

<< " - The password should be at least "

<< MIN << " characters long.\n"

<< " - The password should contain at least one uppercase\n"

<< " and at least one lowercase letter.\n"

<< " - The password should have at least one digit.\n\n";

}

void displayResult(char str[])

{

bool length, upper, lower, digit;

length = upper = lower = digit = false;

int lengthCount = 0;

}

Solutions

Expert Solution

The completed C++ code is provided below, please comment if any doubts:

Note: The given code is completed below, the added portion is highlighted

C++ Code:

#include<iostream>
using namespace std;

// Global constants
const int SIZE = 80;

// The maximum size of the array
const int MIN = 6;

// The minimum number characters

// Function prototypes
void displayRequirements();
void displayResult(char[]);

int main()

{

   char cstring[SIZE];
   displayRequirements();
   cout << "Enter a password: ";
   cin.getline(cstring, SIZE);
   displayResult(cstring);
   return 0;
}
void displayRequirements()
{

   // Display the password requirements.

   cout << "Password Requirments:\n"

   << " - The password should be at least "

   << MIN << " characters long.\n"

   << " - The password should contain at least one uppercase\n"

   << " and at least one lowercase letter.\n"

   << " - The password should have at least one digit.\n\n";

}

void displayResult(char str[])

{
   bool length, upper, lower, digit;
   length = upper = lower = digit = false;
   int lengthCount = 0;
   char *pw = str;

   //while there is characters in the string
   while(*pw != '\0')
   {
       //check whether the character is lower case letter
       if(*pw >='a' && *pw <= 'z')
       {
           lower=true;
       }

       //check whether the character is upper case letter
       if(*pw >='A' && *pw <= 'Z')
       {
           upper=true;
       }

       //check whether the character is a digit
       if(*pw >='0' && *pw <= '9')
       {
           digit=true;
       }

       //update the pointer to next
       pw++;
       lengthCount++;

   }


   //check the length requirement
   if(lengthCount>=6)
   {
       length = true;
   }

   //check whether all the requirements satisfied
   if(length && upper && lower && digit)
   {
       //display the result
       cout<<" The password is valid!!!!"<<endl;
   }
   else
   {
       cout<<" The password not satisfying the requirements!!!!"<<endl;
   }
  

}

Sample Outputs:


Related Solutions

Instructions: 1. Please use only C as the language of programming. 2. Please submit the following:...
Instructions: 1. Please use only C as the language of programming. 2. Please submit the following: (1) the client and the server source files each (2) a brief Readme le that shows the usage of the program. 3. Please appropriately comment your program and name all the identifiers suitable, to enable enhanced readability of the code. Problem: Write an ftp client and an ftp server such that the client sends a request to ftp server for downloading a file. The...
In C++, Create an array of 10 characters. Use a loop to prompt for 10 letters...
In C++, Create an array of 10 characters. Use a loop to prompt for 10 letters (a-z|A-Z) and store each in the array. If an invalid character is entered, re-prompt until a valid char is entered. After 10 characters are stored in the array, use a loop to print out all characters in the array from the first to the last element. Then, use another loop starting at the last element to print all characters in the array in reverse...
java Programming Problem 1: Reverse Characters Create an application ReverseCharacters in which you use an array-based...
java Programming Problem 1: Reverse Characters Create an application ReverseCharacters in which you use an array-based stack to read a sentence from the keyboard, and reverse the order of the letters in each word. Print the initial sentence, as well as the result of the reversal operation. Your Tasks: Using the information given in your textbook, create a class named ArrayBasedStack, that will help you solve the problem given above by providing the stack operations you need for this application....
using lunix or C programming to answer this lab please fill in the blanks with the...
using lunix or C programming to answer this lab please fill in the blanks with the answere being highlighted, so i can understand. First, type the following command:             sort employee What is the order that employee is sorted in? ___________________________________________ Give a brief description of how the file is sorted. _____________________________________________________________________________________________________________________________________________________________________________________________________ Now, sort on the field for last name.         sort +1 employee Look at the sorted file. Are all the names sorted in alphabetical order? ______________________ Give a brief description...
Create a C++ program that makes use of both concepts i.e. Array of structure and array...
Create a C++ program that makes use of both concepts i.e. Array of structure and array within the structure by using the following guidelines: 1. Create an Array of 5 Structures of Student Records 2. Each structure must contain: a. An array of Full Name of Student b. Registration Number in proper Format i.e 18-SE-24 c. An array of Marks of 3 subjects d. Display that information of all students in Ascending order using “Name” e. Search a particular student...
Use C Programming - Given an array of integers and a number K, find the smallest...
Use C Programming - Given an array of integers and a number K, find the smallest element in array greater than or equal to K. If such element exists in the array, display it otherwise display "-1". Example: Input:     8     1 3 4 7 8 9 9 10     5     where: First line represents the number of elements in the array. Second line represents the elements in the array. Third line represents the value of K. Output:     7 Explanation:...
USE C PROGRAMMING, call all functions in main, and use a 2 by 3 2d array...
USE C PROGRAMMING, call all functions in main, and use a 2 by 3 2d array to test, thanks. get_location_of_min This function takes a matrix as a 2-D array of integers with NUM_COLS width, the number of rows in the matrix and two integer pointers. The function finds the location of the minimum value in the matrix and stores the row and column of that value to the memory location pointed to by the pointer arguments. If the minimum value...
write a program in C Write a function that is passed an array of characters containing...
write a program in C Write a function that is passed an array of characters containing letter grades of A, B, C, D, and F, and returns the total number of occurrences of each letter grade. Your function should accept both lower and upper case grades, for example, both 'b' and 'B' should be bucketed into your running total for B grades. Any grade that is invalid should be bucketed as a grade of 'I' for Incomplete. You must use...
Instructions: You are not required to use R markdown for the lab assignment. Please include ALL...
Instructions: You are not required to use R markdown for the lab assignment. Please include ALL R commands you used to reach your answers in a word or pdf document. Also, report everything you are asked to do so. Problem 3 : In lab lecture notes and demo code, I simulated random samples from Exp(1) to verify classical central limit theorem numerically. I also stressed that no matter what type of random samples you use, the standardized partial sum Sn...
Instructions: You are not required to use R markdown for the lab assignment. Please include ALL...
Instructions: You are not required to use R markdown for the lab assignment. Please include ALL R commands you used to reach your answers in a word or pdf document. Also, report everything you are asked to do so. Problem 1 : Consider a binomial random variable X ∼ Bin(100, 0.01). 1. Report P(X = 7), P(X = 8), P(X = 9), try to use one ONE R command to return all these three values. 2. Find the probability P(0...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT