Okay! take a look to this program. It's the same like the one I posted earlier and it does the same job. Do not care about the indentation for now just copy the program and compile it.
Code:
#include <iostream>
#include <cctype>
#include<string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
void newCode();
void printCode();
void errorCode();
string billy [12];
int main()
{
int tester;
while((tester >= 1) || (tester < 4))
{
cout << "select one of these options\n";
cout << "(1) Insert a new code\n";
cout << "(2) Print the data\n";
cout << "(3) Program requirments\n";
cout << "(4) Exit the program\n";
cin >> tester;
if(tester==1)
newCode();
else if (tester==2)
printCode();
else if (tester==3)
errorCode();
else if (tester==4)
break;
else
cout << "ERROR!!! You must choose one of the following options 1 to 4";
}
return 0;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void newCode()
{
string serial_number;
int length;
string mystrArray [12];
cout<< "please enter a serial number of 12 characters:";
cin >> serial_number;
length = serial_number.length();
string mystr = serial_number;
int flag=0;
if (length!=12 )
cout << "There must be 12 characters exactly\n";
else for(int i=0;i<length;i++)
{
if (mystr[i]=='4')
{
flag=1;
break;
}
}
if(flag)
{
int flag1 =0;
for(int i=0;i<length;i++)
{
if (mystr[i]=='5')
{
flag1=1;
break;
}
}
if(flag1)
{
int flag2=0;
for(int i=0;i<length;i++)
{
if (mystr[i]=='8' || mystr[i]=='9')
{
flag2=1;
break;
}
}
if(flag2)
{
int flag3=0;
for(int i = 0; i< 4; i++)
{
if ((mystr[i] == 'A') || (mystr[i] == 'L') || (mystr[i] == 'P') || (mystr[i] == 'R') || (mystr[i] == 'T') || (mystr[i] == 'V')||(mystr[i] == 'W')||(mystr[i] == 'X'))
{
flag3=1;
break;
}
}
if(flag3)
{
int flag4=0;
for(int i = 4; i< 8; i++)
{
if ((mystr[i] == 'A') || (mystr[i] == 'L') || (mystr[i] == 'P') || (mystr[i] == 'R') || (mystr[i] == 'T') || (mystr[i] == 'V')||(mystr[i] == 'W')||(mystr[i] == 'X'))
{
flag4=1;
break;
}
}
if(flag4)
{
int flag5=0;
for(int i = 8; i< 12; i++)
{
if ((mystr[i] == 'A') || (mystr[i] == 'L') || (mystr[i] == 'P') || (mystr[i] == 'R') || (mystr[i] == 'T') || (mystr[i] == 'V')||(mystr[i] == 'W')||(mystr[i] == 'X'))
{
flag5=1;
break;
}
}
if(flag5)
{
int flag6=0;
for(int i = 0; i< 12; i++)
{
if ((mystr[i] == 'Q') || (mystr[i] == 'E') || (mystr[i] == 'Y') || (mystr[i] == 'U') || (mystr[i] == 'I') || (mystr[i] == 'O')||(mystr[i] == 'S')||(mystr[i] == 'D')||(mystr[i] == 'F')||(mystr[i] == 'G')||(mystr[i] == 'H')||(mystr[i] == 'J')||(mystr[i] == 'K')||(mystr[i] == 'Z')||(mystr[i] == 'C')||(mystr[i] == 'B')||(mystr[i] == 'N')||(mystr[i] == 'M')||(mystr[i] == '~') || (mystr[i] == '@') || (mystr[i] == '#') || (mystr[i] == '$') || (mystr[i] == '%') || (mystr[i] == '^')||(mystr[i] == '&')||(mystr[i] == '*')||(mystr[i] == '(')||(mystr[i] == ')')||(mystr[i] == '_')||(mystr[i] == '`')||(mystr[i] == '-')||(mystr[i] == '+')||(mystr[i] == '=')||(mystr[i] == 'q')||(mystr[i] == 'w')||(mystr[i] == 'e')||(mystr[i] == 'r') || (mystr[i] == 't') || (mystr[i] == 'y') || (mystr[i] == 'u') || (mystr[i] == 'i') || (mystr[i] == 'o')||(mystr[i] == 'p')||(mystr[i] == 'a')||(mystr[i] == 's')||(mystr[i] == 'd')||(mystr[i] == 'f')||(mystr[i] == 'g')||(mystr[i] == 'h')||(mystr[i] == 'j')||(mystr[i] == 'k')||(mystr[i] == 'l')||(mystr[i] == 'z')||(mystr[i] == 'x')||(mystr[i] == 'c')||(mystr[i] == 'v')||(mystr[i] == 'b')||(mystr[i] == 'n')||(mystr[i] == 'm')||(mystr[i] == '[')||(mystr[i] == ']')||(mystr[i] == '{')||(mystr[i] == '}')||(mystr[i] == ';')||(mystr[i] == '<')||(mystr[i] == '>')||(mystr[i] == ',')||(mystr[i] == '.')||(mystr[i] == '?')||(mystr[i] == '/'))
{
flag6=1;
}
}
if(flag6)
{
cout << "you have used not valid characters\n"<<endl;
}
else
{
cout << "This code is correct\n"<<endl;
cout << "Click on 2 to print the code\n"<<endl;
for ( int i=0;i<length;i++)
{
billy[i]=mystr[i];
}
}
}
else
{
cout << "The only valid letters are A,L,P,R,T,V,W, and X from 9 to 12 digits.\n"<<endl;
}
}
else
{
cout << "The only valid letters are A,L,P,R,T,V,W, and X from 5 to 8 digits.\n"<<endl;
}
}
else
{
cout << "The only valid letters are A,L,P,R,T,V,W, and X from 1 to 4 digits.\n"<<endl;
}
}
else
{
cout << "Either the digit 8 and 9 must appear at least once.\n"<<endl;
}
}
else
cout << "The digits 4 and 5 must appear at least once.\n"<<endl;
}
else
{
cout << "The digits 4 and 5 must appear at least once.\n"<<endl;
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void printCode()
{
for(int i = 0; i< 13; i++)
{
cout<<billy[i]<<endl;
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void errorCode()
{
// cout << "You are mising one or more of the following:\n";
cout << " 1. The digits 4 and 5 must appear at least once.\n";
cout << " 2. Either the digit 8 and 9 must appear at least once.\n";
cout << " 3. The only valid letters are A,L,P,R,T,V,W, and X.\n";
cout << " 3. Each four-character subsquence (1-4, 5-8, 9-12) must contaon at least one digit and at least one letter.\n";
cout << " \n"<<endl;
}
however, this is my new updated program which I did what you have said. Take a look at it
In this program the only different between the previous one is that I am using the Object Oriented Design. I tested the program what it works .. It is just not showing the menu and I run it.
Code:
#include <iostream>
using namespace std;
// declaring a class
class CRectangle
{
//Three methods in use
public:
void set_values(int, string);
string check();
void printCode(int);
private:
int x,flag,flag1,flag2,flag3,counter,counter1,counter2,counter4;
string y,mystr;
size_t found,found1,found2,found3,found4,found5,found6,found7,found8,found9,found10,found11;
string billy[];
};
//printing an array
void CRectangle::printCode (int a)
{
counter4=0;
while(counter <= a)
{
cout << billy[counter]<<endl;
}
}
//set the values
void CRectangle::set_values (int a, string b)
{
x = a;
y = b;
}
//check the four conditions
string CRectangle::check()
{
found = y.find('4');
found1 = y.find('5');
found2 = y.find('8');
found3 = y.find('9');
found4 = y.find('A');
found5 = y.find('L');
found6 = y.find('P');
found7 = y.find('R');
found8 = y.find('T');
found9 = y.find('V');
found10 = y.find('W');
found11 = y.find('X');
flag =0;
flag1=0;
flag2=0;
flag3=0;
counter=0;
counter1=4;
counter2=8;
mystr = y;
billy[12];
if(x != 12)
{
cout << "false"<< endl;
}
else if ((found==string::npos)||(found1==string::npos))
cout << "Error: The digits 4 and 5 must appear at least once."<<endl;
else if ((found2==string::npos)&&(found3==string::npos))
cout << "Error: Either the digit 8 and 9 must appear at least once." << endl;
else
while(counter<4)
{
if ( (found4!=string::npos) || (found5!=string::npos) || (found6!=string::npos) || (found7!=string::npos)|| (found8!=string::npos) || (found9!=string::npos) || (found10!=string::npos)||(found1!=string::npos))
{
flag=1;
break;
}
counter++;
}
if(flag){
while(counter1<8)
{
if ( (found4!=string::npos) || (found5!=string::npos) || (found6!=string::npos) || (found7!=string::npos)|| (found8!=string::npos) || (found9!=string::npos) || (found10!=string::npos)||(found11!=string::npos))
{
flag1=1;
break;
}
counter1++;
}
if(flag1){
while(counter2<12)
{
if ( (found4!=string::npos) || (found5!=string::npos) || (found6!=string::npos) || (found7!=string::npos)|| (found8!=string::npos) || (found9!=string::npos) || (found10!=string::npos)||(found11!=string::npos))
{
flag2=1;
break;
}
counter2++;
}
if(flag2){
while(counter<12)
{
if ( (mystr[counter] == 'Q') || (mystr[counter] == 'E') || (mystr[counter] == 'Y') || (mystr[counter] == 'U') || (mystr[counter] == 'I') || (mystr[counter] == 'O')||(mystr[counter] == 'S')||(mystr[counter] == 'D')||(mystr[counter] == 'F')||(mystr[counter] == 'G')||(mystr[counter] == 'H')||(mystr[counter] == 'J')||(mystr[counter] == 'K')||(mystr[counter] == 'Z')||(mystr[counter] == 'C')||(mystr[counter] == 'B')||(mystr[counter] == 'N')||(mystr[counter] == 'M')||(mystr[counter] == 'q')||(mystr[counter] == 'w')||(mystr[counter] == 'e')||(mystr[counter] == 'r') || (mystr[counter] == 't') || (mystr[counter] == 'y') || (mystr[counter] == 'u') || (mystr[counter] == 'i') || (mystr[counter] == 'o') || (mystr[counter] == 'p') || (mystr[counter] == 'a') || (mystr[counter] == 's') || (mystr[counter] == 'd') || (mystr[counter] == 'f') || (mystr[counter] == 'g') || (mystr[counter] == 'h') || (mystr[counter] == 'j') || (mystr[counter] == 'k') || (mystr[counter] == 'l') || (mystr[counter] == 'z') || (mystr[counter] == 'x') || (mystr[counter] == 'c') || (mystr[counter] == 'v') || (mystr[counter] == 'b') || (mystr[counter] == 'n') || (mystr[counter] == 'm') )
{
flag3=1;
break;
}
counter++;
}
}
}
}
if(flag3)
{
cout << "You are mising one or more of the following:\n";
cout << " 1. The only valid letters are A,L,P,R,T,V,W, and X.\n";
cout << " 2. Each four-character subsquence (1-4, 5-8, 9-12) must contain at least one digit and at least one letter.\n";
cout << " \n"<<endl;
}
else
{
cout << "The code is correct:" << y <<endl;
while(counter<12)
{
billy[counter]=mystr[counter];
counter++;
}
}
return y;
}
int main () {
int length;
string codeNumber;
string mystr = codeNumber;
CRectangle rect;
int tester =0;
do
{
cout << "select one of these options\n";
cout << "(1) Insert a new code\n";
cout << "(2) Print the data\n";
cout << "(3) Exit the program\n";
cin >> tester;
if(tester==1){
cout << "Insert a code of 12 characters:";
cin >> codeNumber;
length = codeNumber.length();
rect.set_values (length,codeNumber);
rect.check();
}
if (tester==2){
rect.printCode(length);
}
if (tester==3){
break;
}
else{
cout << "ERROR!!! You must choose one of the following options 1 to 4";
}
} while (tester > 0 && tester < 4);
return 0;
}