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....
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:...
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...
Programming in C++ Write a program that prints the values in an array and the addresses...
Programming in C++ Write a program that prints the values in an array and the addresses of the array’s elements using four different techniques, as follows: Array index notation using array name Pointer/offset notation using array name Array index notation using a pointer Pointer/offset notation using a pointer Learning Objectives In this assignment, you will: Use functions with array and pointer arguments Use indexing and offset notations to access arrays Requirements Your code must use these eight functions, using these...
The purpose of this C++ programming assignment is to practice using an array. This problem is...
The purpose of this C++ programming assignment is to practice using an array. This problem is selected from the online contest problem archive, which is used mostly by college students worldwide to challenge their programming ability and to prepare themselves for attending programming contests such as the prestige ACM International Collegiate Programming Contest. For your convenience, I copied the description of the problem below with my note on the I/O and a sample executable. Background The world-known gangster Vito Deadstone...
(C programming) Use a one-dimensional array to solve the following problem. Read in 20 numbers, each...
(C programming) Use a one-dimensional array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, print it only if it’s not a duplicate of a number already read. Provide for the “worst case” in which all 20 numbers are different. Use the smallest possible array to solve this problem. Your solution must include a function called isUnique() that returns 1 (true) if the number input is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT