| CODE |
| #include<iostream> #include<string> #include<cctype> using std::string; using std::cout; using std::cin; using std::endl; // Here are some function declarations unsigned short getMenuSelection( ); void binaryConversionUsingArithmeticOperators(unsigned long); void binaryConversionUsingBitwiseOperators (unsigned long); void isPalindromeUsingIteration(string); void isPalindromeUsingRecursion(string); // Utilityfunctions declarations void initializeArray(unsigned short[],int); void initializeArray(string[],int); void printBinary(unsigned short[],int); void printBinary(string[],int); int main() { unsigned short choice; do { choice = getMenuSelection(); cout <<"You chose Menu Option #"<<choice<<endl; switch(choice) { case 1 : unsigned long a; cout<<" Please enter an integer "; cin>>a; binaryConversionUsingArithmeticOperators(a); break; case 2 : cout<<" Please enter an integer "; cin >>a; binaryConversionUsingBitwiseOperators(a); break; case 3 : string b; cout<<"Please enter a string "; cin>>b; isPalindromeUsingIteration(b); break; case 4: string b; cout<<"Please enter a string "; cin>>b; isPalindromeUsingIteration(b); break; case 5: break; default: cout<<"you should never get here\a\a\a\a!!!"; } }while(choice != 5); cout<<"you choose to quit\a\a\a"<<endl; return 0; } //function definitions unsigned short getMenuSelection() { unsigned short selection=0; do { cout<<"-1- Binary Conversion using Arithmetic Operators"<<endl; cout<<"-2- Binary Conversion using Bitwise Operators"<<endl; cout<<"-3- Testing for Palindroms Using Iteration"<<endl; cout<<"-4- Testing for Palindroms Using Recursion"<<endl; cout<<"-5- Quit"<<endl; cout<<"please enter your selection <1-5>:"<<endl; cin>>selection; } while(selection<1 || selection>5); return selection; } void binaryConversionUsingArthematicOperators(unsigned long x) { unsigned short binaryDigit[100], numberOfDigits=0; initializeArray(binaryDigit,100); do { binaryDigit[numberOfDigits++]=x%2; x=x/2; }while(x!=0); printBinary(binaryDigit,numberOfDigits); } void binaryConversionUsingBitwiseOperator(unsigned long x) { unsigned short binaryDigit [100], numberOfDigits=0; initializeArray(binaryDigit , 100); do { binaryDigit[numberOfDigits++]=x&1; x=x>>1; }while(x!=0); printBinary(binaryDigit, numberOfDigits); } void isPalindromeUsingIteration(string y) { while (length>1) { if ( y[] != [y + length - 1]) { return false; } ++y; length=length-2; } return true; } void isPalindromeUsingRecursion(string y) { if ( length<2 ) { return true; } else { if ( y[] != [y + length - 1]) { return false; } else { return ispalindromeUsingRecursion(string y+1); } } } //utality function definitions void initializeArray (unsigned short a[], int size) { for(int i=0;i<size; i++) a[i]=0; } void printBinary(unsigned short a[], int size) { for(int i=size-1; i>=0; i--) cout<<a[i]; cout<<endl; } void initializeArray (string b[], int length) { for(int i=0;i<length; i++) b[i]=b; } void printBinary(string b[], int length) { for(int i=length-1; i>=0; i--) cout<<b[i]; cout<<endl; |
| CODE |
| #include<iostream> #include<string> #include<cctype> using std::string; using std::cout; using std::cin; using std::endl; int length; // Here are some function declarations unsigned short getMenuSelection( ); void binaryConversionUsingArithmeticOperators(unsigned long); void binaryConversionUsingBitwiseOperators (unsigned long); void isPalindromeUsingIteration(string); void isPalindromeUsingRecursion(string); // Utilityfunctions declarations void initializeArray(unsigned short[],int); void initializeArray(string[],int); void printBinary(unsigned short[],int); void printBinary(string[],int); int main() { unsigned short choice; do { choice = getMenuSelection(); cout <<"You chose Menu Option #"<<choice<<endl; switch(choice) { case 1 : unsigned long a; cout<<" Please enter an integer "; cin>>a; binaryConversionUsingArithmeticOperators(a); break; case 2 : cout<<" Please enter an integer "; cin >>a; binaryConversionUsingBitwiseOperators(a); break; case 3 : string b; cout<<"Please enter a string "; cin>>b; isPalindromeUsingIteration(b); break; case 4: string b; cout<<"Please enter a string "; cin>>b; isPalindromeUsingIteration(b); break; case 5: break; default: cout<<"you should never get here\a\a\a\a!!!"; } }while(choice != 5); cout<<"you choose to quit\a\a\a"<<endl; return 0; } //function definitions unsigned short getMenuSelection() { unsigned short selection=0; do { cout<<"-1- Binary Conversion using Arithmetic Operators"<<endl; cout<<"-2- Binary Conversion using Bitwise Operators"<<endl; cout<<"-3- Testing for Palindroms Using Iteration"<<endl; cout<<"-4- Testing for Palindroms Using Recursion"<<endl; cout<<"-5- Quit"<<endl; cout<<"please enter your selection <1-5>:"<<endl; cin>>selection; } while(selection<1 || selection>5); return selection; } void binaryConversionUsingArthematicOperators(unsigned long x) { unsigned short binaryDigit[100], numberOfDigits=0; initializeArray(binaryDigit,100); do { binaryDigit[numberOfDigits++]=x%2; x=x/2; }while(x!=0); printBinary(binaryDigit,numberOfDigits); } void binaryConversionUsingBitwiseOperator(unsigned long x) { unsigned short binaryDigit [100], numberOfDigits=0; initializeArray(binaryDigit , 100); do { binaryDigit[numberOfDigits++]=x&1; x=x>>1; }while(x!=0); printBinary(binaryDigit, numberOfDigits); } void isPalindromeUsingIteration(string y) { while (length>1) { if (y[] != [y + length - 1]) { cout<<"false"<<endl; } ++y; length=length-2; } cout<<"true"<<endl; } void isPalindromeUsingRecursion(string y) { if ( length<2 ) { cout<<"true"<<endl; } else { if ( y[] != [y + length - 1]) { cout<<"false"<<endl; } else { cout<<ispalindromeUsingRecursion(string y+1)<<endl; } } } //utality function definitions void initializeArray (unsigned short a[], int size) { for(int i=0;i<size; i++) a[i]=0; } void printBinary(unsigned short a[], int size) { for(int i=size-1; i>=0; i--) cout<<a[i]; cout<<endl; } void initializeArray (string b[], int length) { for(int i=0;i<length; i++) } void printBinary(string b[], int length) { for(int i=length-1; i>=0; i--) cout<<b[i]; cout<<endl; } |
| QUOTE |
error C2360: initialization of 'b' is skipped by 'case' label (45) : see declaration of 'b' (51) : error C2086: 'b' : redefinition (56) : error C2360: initialization of 'b' is skipped by 'case' label (51) : see declaration of 'b' (56) : error C2360: initialization of 'b' is skipped by 'case' label (45) : see declaration of 'b' (58) : error C2361: initialization of 'b' is skipped by 'default' label (51) : see declaration of 'b' (58) : error C2361: initialization of 'b' is skipped by 'default' label (45) : see declaration of 'b' (114) : error C2059: syntax error : ']' (115) : error C2143: syntax error : missing ';' before '{' (118) : error C2675: unary '++' : 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' does not define this opera tor or a conversion to a type acceptable to the predefined operator (131) : error C2059: syntax error : ']' (132) : error C2143: syntax error : missing ';' before '{' (135) : error C2181: illegal else without matching if (137) : error C2065: 'ispalindromeUsingRecursion' : undeclared identifier (137) : error C2275: 'string' : illegal use of this type as an expression c:\program files\microsoft visual studio\vc98\include\xstring(612) : see declaration of 'string' |
| CODE |
| string b; |
| CODE |
| unsighned long a; |
| CODE |
| int main() { string b; unsighned long a; unsigned short choice; do { //bla bla }while(/*bla bla*/) } Another reason you do this, is because you may have to go into the 2 switch before you get to the 1 switch, and there is no defined a variable, and you would screw up the program. [code]if (y[] != [y + length - 1]) |
| CODE |
| lenght+=stringb.size(); |
| CODE |
| void isPalindromeUsingRecursion(string y) { if ( length<2 ) { cout<<"true"<<endl; } else { if ( y[] != [y + length - 1]) { cout<<"false"<<endl; } else { cout<<[b][u]ispalindromeUsingRecursion(string y+1)[b][u]<<endl; } } } |
| QUOTE |
| if ( y[] != [y + length - 1]) |