Server IP : 172.16.15.8 / Your IP : 18.219.231.197 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/jwmccreary/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// Recursion Assignment // Proving whether or not a string of characters is a WFF // Justin McCreary // Instructor: Mrs. Ames // 11/4/08 #include <iostream> using namespace std; //----------------------------------------------------------------------------- // WFFCatcher inputs one character at a time until it returns a true or false // statement, upon which the code checks whether or not it is a WFF. //----------------------------------------------------------------------------- bool WFFCatcher() { char ch; cin.get(ch); //inputs character if( ch == 'p' || ch == 'q' || ch == 'r' || ch == 's' ) { return true; //base case 1 } else if ( ch == 'N' ) { return WFFCatcher(); //general case } else if (ch == 'C' || ch == 'A' || ch == 'K' || ch == 'E') { return WFFCatcher() && WFFCatcher(); //general case } else { return false; //base case 2 } } int main () { bool W = true; char ch; cout << "Enter a string to determine whether or not it is WFF : "; W = WFFCatcher(); //Asks for a true or false statement cin.get(ch); if ( W == true) //Checks whether or not true { // if true, checks whether or not it went through the entire string if(ch != '\n') cout << "Not a WFF.\n"; else cout << "A WFF.\n"; } // if false, outputs this statement else cout << "Not a WFF.\n"; return 0; }