#include <conio.h> #include <iomanip> #include <iostream> #include<stdlib.h> #in
ID: 3755126 • Letter: #
Question
#include <conio.h>
#include <iomanip>
#include <iostream>
#include<stdlib.h>
#include <time.h>
#include<sstream>
#include <string>
using namespace std;
int main()
{
char again = 'y';
string demo;
string customerid;
char first, second;
int third;
const int idsize = 5;
stringstream converter;
while (again == 'y')
{
cout << " Enter the customer ID to validate: ";
getline(cin, customerid);
getline(cin, customerid);
if (customerid.length() == idsize)
{
system("cls");
first = customerid[0];
first = toupper(first);
second = customerid[1];
second = toupper(second);
demo = "";
for (int n = 0; n < 3; n++)
{
demo += customerid.at(n+2);
}
converter.clear();
converter.str(demo);
converter >> third;
switch (first)
{
case 'A':
case 'B':
case 'C':
switch (second)
{
case 'B':
case 'C':
case 'D':
switch (third)
{
case 101:
case 102:
case 103:
case 104:
case 105:
case 106:
case 107:
case 108:
case 109:
case 110:
cout << " Customer ID " << customerid << " is valid";
break;
default:
cout << " Customer ID " << customerid << " is not valid";
}
break;
}
break;
default:
cout << " Customer ID " << customerid << " is not valid";
}
}
else
{
cout << " The id " << customerid << " is not of valid length ";
}
cout << " Run again yes(y)or no(n)...";
cin >> again;
again = tolower(again);
cin.ignore();
system("cls");
}
}
This is what i have so far
Determine if the ID string codes are valid: 1. ID codes consists of 5 characters positions (anything less than 5 positions is invalid) 2. The first two positions must be Letters (A-Z) . The last three positions consists of Digit symbols (0 to 9) 4. Upper and lower case letters are the same (A" is the same as "a") 5. NOT all ID patterns are valid. The following are valid ID patterns: a. A, K, S- Followed by B, C, D, Followed by 101 to 110 b. B, H, N- Followed by A, F, G, H, Followed by 113 to 118 or 213 or 220 or 560 or 890 c. Cor T-Followed by K, L. Followed by i 34, l 38, 145 or 246 d. M, O,Z- Followed by A, D, F, Followed by 177 to 181 or 333 to 335 e. Any other pattern is not valid r enters an ID code and the application will display that it is Valid or Invalid 6. Use 7. A large number of IF...else statements is not practical (26 X 26 x 10x 10x 10 possibilities) 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 - Cor T- Followed by K, L, Z, Followed by 134, 138, 145 or 246 4-M, 0,2-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 1180r 213 or 220 or 560 or 890 3 - Cor T- Followed by K, L, Z, Followed by 134, 138, 145 or 246 4-, 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)...Explanation / Answer
#include <iomanip>
#include <iostream>
#include<stdlib.h>
#include <time.h>
#include<sstream>
#include <string>
using namespace std;
int check1(char first) {
if(first == 'A' || first == 'K' || first == 'S') {
return 1;
} else if(first == 'B' || first == 'H' || first == 'N') {
return 2;
} else if(first == 'C' || first == 'T' ) {
return 3;
} else if(first == 'M' || first == 'O' || first == 'Z') {
return 4;
} else {
return 5;
}
}
int check2(char second, int firstCheck) {
if(firstCheck == 1 && (second == 'B' || second == 'C' || second == 'D')) {
return 1;
} else if(firstCheck == 2 && (second == 'A' || second == 'F' || second == 'G' || second || 'H')) {
return 2;
} else if(firstCheck == 3 && (second == 'K' || second == 'L' || second == 'Z' )) {
return 3;
} else if(firstCheck == 4 && (second == 'A' || second == 'D' || second == 'F')) {
return 4;
} else {
return 5;
}
}
int check3(int third, int firstCheck) {
if(firstCheck == 1 && (third >= 101 && third <= 110)) {
return 1;
} else if(firstCheck == 2 && ((third >= 101 && third <= 110) || third == 213 || third == 220 || third == 560)) {
return 2;
} else if(firstCheck == 3 && (third == 134 || third == 138 || third == 145 || third == 246)) {
return 3;
} else if(firstCheck == 4 && ((third >= 117 && third <= 181) || (third >= 333 && third <= 335) )) {
return 4;
} else {
return 5;
}
}
int main()
{
char again = 'y';
string demo;
string customerid;
char first, second;
int third;
const int idsize = 5;
stringstream converter;
while (again == 'y')
{
cout << " Enter the customer ID to validate: ";
getline(cin, customerid);
cout << customerid << endl;
if (customerid.length() == idsize)
{
first = customerid[0];
first = toupper(first);
second = customerid[1];
second = toupper(second);
demo = "";
for (int n = 0; n < 3; n++)
{
demo += customerid.at(n+2);
}
converter.clear();
converter.str(demo);
converter >> third;
int firstCheck = check1(first);
int secondCheck = check2(second, firstCheck);
int thirdCheck = check3(third, firstCheck);
// cout << firstCheck << " " << secondCheck << " " << thirdCheck << endl;
if(firstCheck == secondCheck && secondCheck == thirdCheck) {
cout << "Customer ID is VALID" << endl;
} else {
cout << "Customer ID is INVALID" << endl;
}
}
else
{
cout << " The id " << customerid << " is not of valid length ";
}
cout << " Run again yes(y)or no(n)...";
cin >> again;
again = tolower(again);
cin.ignore();
}
}
Please comment for any assistance
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.