Question
In C++ String Processing How do you determine if a string value is valid or not? You would have to dismantle the string according to
In C++
String Processing
How do you determine if a string value is valid or not? You would have to dismantle the string according to a set of validity rules. Writing a series of convoluted Ifs, Else Ifs, ANDs, OR tests is not practical nor easily updated or maintained. What other approach is there ?
Determine if the ID string codes are valid:
- ID codes consists of Five characters positions (anything less than 5 positions is invalid)
- The first two positions must be Letters (A Z)
- The last three positions consist of Digit symbols (0 to 9)
- Upper and lower case letters are the same (A is the same as a)
- NOT all ID patterns are valid. The following are valid ID patterns:
- A, K, S - Followed by B, C, D, Followed by 101 to 110
- B, H, N - Followed by A, F, G, H, Followed by 113 to 118 or 213 or 220 or 560 or 890
- C or T - Followed by K, L, Z, Followed by 134, 138, 145 or 246
- M, O, Z - Followed by A, D, F, Followed by 177 to 181 or 333 to 335
- Any other pattern is not valid
- User enters an ID code and the application will display that it is Valid or Invalid
- A large number of IFelse statements is not practical (26 X 26 X 10 X 10 X 10 possibilities) page: 559, character array holding X amount of values and setting the format
Example Output:
Valid Customer ID Rules:
1 - A, K, S - Followed by B, C, D, Followed by 101 to 110
2 - B, H, N - Followed by A, F, G, H, Followed by 113 to 118 or 213 or 220 or 560 or 890
3 - C or T - Followed by K, L, Z, Followed by 134, 138, 145 or 246
4 - M, O, Z - Followed by A, D, F, Followed by 177 to 181 or 333 to 335
Enter a Customer ID: AB107
Customer ID is AB107
Customer ID is Valid
Hit Any Key to continue...
Validate Another ID (Y or N): y
Valid Customer ID Rules:
1 - A, K, S - Followed by B, C, D, Followed by 101 to 110
2 - B, H, N - Followed by A, F, G, H, Followed by 113 to 118 or 213 or 220 or 560 or 890
3 - C or T - Followed by K, L, Z, Followed by 134, 138, 145 or 246
4 - M, O, Z - Followed by A, D, F, Followed by 177 to 181 or 333 to 335
Enter a Customer ID: MF201
Customer ID is MF201
Invalid Digits (Must be 177 to 181, 333 to 335)...
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started