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

Code:

ID_Functions.h:

bool hasAny(std::string str1, std::string str2);
bool CheckValidID(std::string str2);

ID_Functions.cpp:

#include <iostream>
#include "ID_Functions.h"
bool hasAny(std::string str1, std::string str2){
   size_t found;
   for(int i = 0; i < str1.length(); i++){
       found = str2.find(str1[i]);
       if (found != std::string::npos)
           return true;
   }
   return false;
}

bool CheckValidID(std::string str2){
   if (str2.length() < 5 || str2.length() > 10)
       return false;
   char ch = str2[0];
   if (!(('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z')))
       return false;
   if(!hasAny("abcdefghijklmnopqrstuvwxyz", str2))
       return false;
   if(!hasAny("ABCDEFGHIJKLMNOPQRSTUVWXYZ", str2))
       return false;
   if(!hasAny("0123456789", str2))
       return false;
   if(!hasAny("#_$", str2))
       return false;
   for(int i = 0; i < str2.length(); i++){
       ch = str2[i];
       if(!(('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || ('0' <= ch && ch <= '9') || ch == '#' || ch == '_' || ch == '$'))
           return false;
   }
   return true;
}

testvalidid.cpp:

#include <iostream>
#include "ID_Functions.h"
int main()
{
   std::string userInput;
   std::cout << "Enter User ID: ";
   std::cin >> userInput;
   while(userInput != "END"){
       if(CheckValidID(userInput))
           std::cout << userInput << " is valid." << std::endl;
       else
           std::cout << userInput << " is not valid." << std::endl;
       std::cout << "\nEnter userID: ";
       std::cin >> userInput;
   }
   return 0;
}

Output:


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