Do not be frustrated to read if the code looks too long but it is very simple program. I am new in programing and I have done it without using the object oriented design , but for this one I have to use the object oriented design. So, I compiled the program and it has these following errors:
Error E2040 workingArea2.cpp 6: Declaration terminated incorrectly
Error E2040 workingArea2.cpp 17: Declaration terminated incorrectly
Error E2275 workingArea2.cpp 29: { expected
Error E2321 workingArea2.cpp 165: Declaration does not specify a tag or an identifier
Error E2268 workingArea2.cpp 181: Call to undefined function 'newCode' in function main()
*** 5 errors in Compile ***
I am sure about the codes because I just copied them from the previous program that works the same. I am not sure how does the object oriented design look like so after reading a lot of topics about the object oriented design I came up with this style but I am not really sure about it. So, anyone has any hint or comment on my code that I should change ?
Code:
#include <iostream>
using namespace std;
void SteptsCode()
{
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;
};
// If all the conditions are valid, all the characters will be stored in an array from newCode(). Then, this method is going to print the code
class printCode()
{
int i=0;
string billy [12];
public:
for( i = 0; i< 13; i++)
{
cout<<billy[i]<<endl;
}
};
class void newCode()
{
int tester;
string serial_number;
int length;
string mystr = serial_number;
int flag=0;
string mystrArray [12];
string billy [12];
public:
cout<< "please enter a serial number of 12 characters:";
cin >> serial_number;
length = serial_number.length();
string mystr = serial_number;
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;
}
};
int main()
{
int tester;
while((tester > 0) || (tester < 5))
{
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)
SteptsCode();
else if (tester==4)
break;
else
cout << "ERROR!!! You must choose one of the following options 1 to 4";
}
return 0;
}