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. - #include <iostream>
-
#include <string>
-
#include <fstream>
-
-
using namespace std;
-
-
bool WFF(string);
-
-
int main()
-
{
-
string input;
-
ofstream outData;
-
-
outData.open("output.dat");
-
-
cout << "Enter a string to test: ";
-
getline(cin, input);
-
while (! input.empty())
-
{
-
if (WFF(input))
-
{
-
cout << input << " is a WFF.\n";
-
outData << input << " is a WFF.\n";
-
}
-
else
-
{
-
cout << input << " is not a WFF.\n";
-
outData << input << " is not a WFF.\n";
-
}
-
cout << "Enter a string to test: ";
-
getline(cin, input);
-
}
-
return 0;
-
-
}
-
-
bool WFF(string input)
-
{
-
if ((input[0]=='p'||input[0]=='q'||input[0]=='r'||input[0]=='s')&&
-
input.length()==1)
-
return true;
-
if ((input[0]=='p'||input[0]=='q'||input[0]=='r'||input[0]=='s')&&
-
input.length()>1)
-
return WFF(input.substr(1,input.length()-1));
-
if (input[0]=='N'&&input.length()>1)
-
return WFF(input.substr(1,input.length()-1));
-
if ((input[0]=='C'||input[0]=='A'||input[0]=='K'||input[0]=='E')&&
-
input.length()>2)
-
return WFF(input.substr(1,input.length()-1));
-
else
-
return false;
-
}
1 2132
Anyone have any ideas at all? : ) I'm dyin' over here.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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;
|
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.
|
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.
|
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!
|
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.
| |
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)) {
|
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
|
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!
|
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 ??
|
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...
|
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,...
| |
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |