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...
C Programming question: Develop a program named “sample” that prints the value of two functions: 1....
C Programming question: Develop a program named “sample” that prints the value of two functions: 1. Function f1 takes a single input argument of type int and returns the value of its input argument as float 2. Function f2 takes a single input argument of type char and returns an int. The output of f2 is the result of the sum of the values of the global variables, and the input argument minus the value of char ‘a’ plus 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...
C++ Here is a program that to validate the ISBN number from user typed and output...
C++ Here is a program that to validate the ISBN number from user typed and output "Valid" if the number is valid, and "Invalid" otherwise. I want to change this program to read the file, and to validate the ISBN number from the file. Please add comments. #include <iostream> #include <string> using std::cin; using std::cout; using std::string; // remove dashes convert letters to upper case string normalize(const string &isbn) { string ch; for (char i : isbn) { if (i...
Python - Rewriting a Program Rewrite Program 1 using functions. The required functions are in the...
Python - Rewriting a Program Rewrite Program 1 using functions. The required functions are in the table below. Create a Python program that will calculate the user’s net pay based on the tax bracket he/she is in. Your program will prompt the user for their first name, last name, their monthly gross pay, and the number of dependents. The number of dependents will determine which tax bracket the user ends up in. The tax bracket is as follows: 0 –...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT