473,804 Members | 3,194 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Having trouble with a recursion program - Wff 'n Proof

2 New Member
Hello everyone. I've been working on an assignment which is described here
[HTML]http://scidiv.bcc.ctc. edu/mg/211/programs/program5.htm[/HTML]
I've gotten to a point where it works for most cases but definitely has problems. My version allows for more than one total WFF, which isn't allowed. For instance, "pp" should not qualify, but it does in my version. Also, something like "ANp" isn't a wff, but would identify as so in my program. I've really gotten to the point where I'm just stuck in my own head at this point, unable to figure out how to do this. Well, here's my code. This was written using Visual C++ 2005, although that probably doesn't matter much. Also, we are allowed to use more arguments to the recursive function than just the string input. I'd really appreciate any suggestions.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. bool WFF(string);
  8.  
  9. int main()
  10. {
  11.     string input;
  12.     ofstream outData;
  13.  
  14.     outData.open("output.dat");
  15.  
  16.     cout << "Enter a string to test: ";
  17.     getline(cin, input);
  18.     while (! input.empty())
  19.     {
  20.         if (WFF(input))
  21.         {
  22.             cout << input << " is a WFF.\n";
  23.             outData << input << " is a WFF.\n"; 
  24.         }
  25.         else
  26.         {
  27.             cout << input << " is not a WFF.\n";
  28.             outData << input << " is not a WFF.\n"; 
  29.         }
  30.         cout << "Enter a string to test: ";
  31.         getline(cin, input);
  32.     } 
  33.     return 0;
  34.  
  35. }
  36.  
  37. bool WFF(string input)
  38. {
  39.     if ((input[0]=='p'||input[0]=='q'||input[0]=='r'||input[0]=='s')&&
  40.          input.length()==1)        
  41.         return true; 
  42.     if ((input[0]=='p'||input[0]=='q'||input[0]=='r'||input[0]=='s')&&
  43.          input.length()>1)        
  44.         return WFF(input.substr(1,input.length()-1));
  45.     if (input[0]=='N'&&input.length()>1)
  46.         return WFF(input.substr(1,input.length()-1));
  47.     if ((input[0]=='C'||input[0]=='A'||input[0]=='K'||input[0]=='E')&&
  48.          input.length()>2)        
  49.         return WFF(input.substr(1,input.length()-1));
  50.     else
  51.         return false;
  52. }
Jan 20 '07 #1
1 2132
Thundercleese
2 New Member
Anyone have any ideas at all? : ) I'm dyin' over here.
Jan 21 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

43
4175
by: Lorenzo Villari | last post by:
I've tried to transform this into a not recursive version but without luck... #include <stdio.h> void countdown(int p) { int x;
10
2530
by: paulw | last post by:
Hi Please give problems that "HAS TO" to use recursion (recursive calls to itself.) Preferrably real world examples, not knights tour. I'm thinking about eliminating the use of stack... Thanks.
5
1284
by: Ioannis Vranos | last post by:
The following code is supposed to print all folder names of a folder but it does not work. Why? Change the folder in main() to a folder suitable for your system so as to test it. I created this proof-of-concept example, because I encountered similar recursion problems in a more complex project.
18
3727
by: MTD | last post by:
Hello all, I've been messing about for fun creating a trial division factorizing function and I'm naturally interested in optimising it as much as possible. I've been told that iteration in python is generally more time-efficient than recursion. Is that true? Here is my algorithm as it stands. Any suggestions appreciated!
9
4541
by: Hemal | last post by:
Hi All, I need to know the memory required by a c program. Is there any tool/utility which can give me the memory usage in terms of DATA segment, TEXT segment, BSS segment etc. I am working on linux platform and my target is ARM processor. But i guess it should not matter. Actually i need to know both RAM & ROM usage.
5
1618
by: Milan Krejci | last post by:
the thing is that descentant branches i dont want to expand do expand. $id variable contains an array of branches i want the program to go through (alcohol's id -beer id etc) function tree_list($parent, $level,$id) { // retrieve all children of $parent $result = mysql_query('SELECT cname,cid FROM kategorie '. 'WHERE parent="'.$parent.'";'); while ($row = mysql_fetch_array($result)) {
13
2916
by: Mumia W. | last post by:
Hello all. I have a C++ program that can count the YOYOs that are in a grid of Y's and O's. For example, this Y O Y O O Y O Y O Y O O Y O Y Y O Y O Y O O Y O O Y Y O Y O
15
1454
by: Gigs_ | last post by:
Can someone explain me this if l == : return else: return f(l) + l # <= cant figure this, how is all sum at the end? thanks!
35
4744
by: Muzammil | last post by:
int harmonic(int n) { if (n=1) { return 1; } else { return harmonic(n-1)+1/n; } } can any help me ??
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9152
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.