Question

In: Computer Science

Develop a program in C++, using functions, to validate a userID. Valid userID specifications: • 5...

Develop a program in C++, using functions, to validate a userID. Valid userID specifications:

• 5 - 10 characters long.

• must begin with a letter.

• must contain at least one upper case letter.

• must contain at least one lower case letter.

• must contain at least one decimal digit.

• must contain at least one of the following special characters: #_$

• must not contain any other characters than those specified above.

The main program should loop, inputting userIDs and outputting the userID followed by "valid" or "not valid" as appropriate until the user enters "END". At that point the program ends. You may only use the following system include files: You should develop a comprehensive test set of userIDs. Include this test set in a block comment at the end of your main program. I.e., in the main.cpp file. Write two functions as described below. These should be properly entered into the two files: ID_Functions.h and ID_Functions.cpp. I.e., two functions go into one file. Do not use a "using namespace" in the header, .h, file. Instead, use explicit namespace resolution as needed. E.g., you will have to use std::string to declare a string.

Solutions

Expert Solution

Please look at my code and in case of indentation issues check the screenshots.

---------------ID_Functions.h----------------


//functio declarations
bool containsAnyOf(std::string anyOf, std::string testStr);
bool IsValidID(std::string testStr);

---------------ID_Functions.cpp----------------

#include <iostream>
#include "ID_Functions.h"


bool containsAnyOf(std::string anyOf, std::string testStr){   //returns true if any char in anyOf is present in testStr
   size_t found;
   for(int i = 0; i < anyOf.length(); i++){   //loop through the length of anyOf
       found = testStr.find(anyOf[i]);           //checks if ith char of anyOf is found in testStr
       if (found != std::string::npos)           //if found return true
           return true;
   }
   return false;
}


bool IsValidID(std::string testStr){
   if (testStr.length() < 5 || testStr.length() > 10)   //string size 5-10 chars check
       return false;

   char ch = testStr[0];
   if (!(('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z')))   //must begin with a letter.
       return false;

   if(!containsAnyOf("abcdefghijklmnopqrstuvwxyz", testStr)) //must contain at least one upper case letter.
       return false;

   if(!containsAnyOf("ABCDEFGHIJKLMNOPQRSTUVWXYZ", testStr)) //must contain at least one upper case letter.
       return false;

   if(!containsAnyOf("0123456789", testStr))   //must contain at least one decima digit.
       return false;

   if(!containsAnyOf("#_$", testStr))           //must contain at least one of #_$
       return false;

   for(int i = 0; i < testStr.length(); i++){   //check if any char is not from above characters
       ch = testStr[i];
       if(!(('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || ('0' <= ch && ch <= '9') || ch == '#' || ch == '_' || ch == '$'))
           return false;
   }
   return true;   //if all conditions are met, return false
}

---------------main.cpp----------------

#include <iostream>
#include "ID_Functions.h"

int main()
{
   std::string inp;
   std::cout << "Enter userID: ";
   std::cin >> inp;                   //read input string
   while(inp != "END"){               //if it is not END
       if(IsValidID(inp))               //check if valid
           std::cout << inp << " valid" << std::endl;
       else
           std::cout << inp << " not valid" << std::endl;
       std::cout << "Enter userID: ";   //read next string
       std::cin >> inp;
   }


   return 0;
}

--------------Screenshots-------------------

------------------Output-----------------

----------------------------------------------------------------------------------------
Please give a thumbs up if you find this answer helpful.
If it doesn't help, please comment before giving a thumbs down.
Please Do comment if you need any clarification.
I will surely help you.

Thankyou


Related Solutions

Develop a program in C++, using functions, to validate a userID. Valid userID specifications: • 5...
Develop a program in C++, using functions, to validate a userID. Valid userID specifications: • 5 - 10 characters long. • must begin with a letter. • must contain at least one upper case letter. • must contain at least one lower case letter. • must contain at least one decimal digit. • must contain at least one of the following special characters: #_$ • must not contain any other characters than those specified above. The main program should loop,...
C++ Develop program in C++ using arrays of characters, subscript operator, the cstring library, and functions...
C++ Develop program in C++ using arrays of characters, subscript operator, the cstring library, and functions with arguments. Create programs with small functions where main goes to a series of functions where the real work takes place. Don’t use global variables and don’t use break within a loop (unless working with a switch statement). Functions can’t have more than 30 statements of code, not including comments, blank lines, or variable definitions. Don’t use a return in the middle of the...
Run the program and enter domain names to validate. Note that even valid input is flagged...
Run the program and enter domain names to validate. Note that even valid input is flagged as invalid. Change the program to validate a domain name. A valid domain name for this program has a second-level domain followed by a core gTLD. Run the program again. import java.util.Scanner; public class CoreGtldValidation {    public static void main (String [ ] args) { Scanner scnr = new Scanner(System.in); String coreGtld1; String coreGtld2; String coreGtld3; String coreGtld4; String inputName; String searchName; String...
Develop a program using Threads in C/C++ to estimate the value of PI using the Monte...
Develop a program using Threads in C/C++ to estimate the value of PI using the Monte Carlo method use: C/C++ #include srand((unsigned)(myid)); x = ((double)rand()) / ((double)RAND_MAX); y = ((double)rand()) / ((double)RAND_MAX); Your program will allow the user to specify the number of threads (range 1 to 10) and the total number of data points (range 10 to 1,000,000) used for the Monte Carlo simulation on the command line. Note, DO NOT assume the number of data points is always...
Develop a program using Threads in C/C++ to estimate the value of PI using the Monte...
Develop a program using Threads in C/C++ to estimate the value of PI using the Monte Carlo method use: C/C++ #include srand((unsigned)(myid)); x = ((double)rand()) / ((double)RAND_MAX); y = ((double)rand()) / ((double)RAND_MAX); Your program will allow the user to specify the number of threads (range 1 to 10) and the total number of data points (range 10 to 1,000,000) used for the Monte Carlo simulation on the command line. Note, DO NOT assume the number of data points is always...
Design c++ program so that it correctly meets the program specifications given below.   Specifications: Create a...
Design c++ program so that it correctly meets the program specifications given below.   Specifications: Create a menu-driven program that finds and displays areas of 3 different objects. The menu should have the following 4 choices: 1 -- square 2 -- circle 3 -- right triangle 4 -- quit If the user selects choice 1, the program should find the area of a square. If the user selects choice 2, the program should find the area of a circle. If the...
write C++ program using functions (separate function for each bottom) Write a program to find if...
write C++ program using functions (separate function for each bottom) Write a program to find if a number is large word for two given bottom base - bottom1 and bottom2. You can predict that a number, when converted to any given base shall not exceed 10 digits. . the program should ask from user to enter a number that it should ask to enter the base ranging from 2 to 16 after that it should check if the number is...
Please C++ create a program that will do one of two functions using a menu, like...
Please C++ create a program that will do one of two functions using a menu, like so: 1. Do Catalan numbers 2. Do Fibonacci numbers (recursive) 0. Quit Enter selection: 1 Enter Catalan number to calculate: 3 Catalan number at 3 is 5 1. Do Catalan numbers 2. Do Fibonacci numbers (recursive) 0. Quit Enter selection: 2 Enter Fibonacci number to calculate: 6 Fibonacci number 6 is 8 Create a function of catalan that will take a parameter and return...
C coding • Implement, using structures and functions as appropriate, a program which requires you to...
C coding • Implement, using structures and functions as appropriate, a program which requires you to enter a number of points in 3 dimensions. The points will have a name (one alphanumeric character) and three coordinates x, y, and z. Find and implement a suitable way to stop the input loop. The program, through an appropriate distance function, should identify the two points which are the furthest apart. Another function should calculate the centre of gravity of the point cloud...
Write a program to validate parenthesis of any given equation by using the following criteria (you...
Write a program to validate parenthesis of any given equation by using the following criteria (you MUST use stacks); Number of open parenthesis “(“must be same as number of close parentheses “)” For example if I input “3 + 4 * (98+34*(34+8)*34*(3+x)” the program should display an error message, because number of open parenthesis “(“is 3 and number of closed “)” parenthesis is 2. Stack-Driver.cpp: #include "stack.h" #include "stack.cpp" #include<stdio.h> #include<stdlib.h> #include<time.h> int main() {    stack<int> my_stack(100);    srand(time(NULL));...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT