473,545 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Truth Table help

//I need a little help with this program, it runs but the output is not
correct.
//Can i get some help here please u fellas???

// This Program asks for user input like 1 && 0 and prints if it is true or
false
// it calculates the input to perform Logical operation from input

#include <iostream>
using namespace std;

// Defines class

class Myclass{
public:
int func();
};

// Function to perform operation

int Myclass::func() {

char x[32] = ""; // array to receive input

cout << "\n\t\t\t T R U T H T A B L E\n" // asks for input
<< "\t\t\t ========= =========\n\n"
<< "Logical operators allow us to form more complex test expressions\n"
<< "for decision and repetition statements. The logical operators
are:\n\n"
<< "1. && (logical and)\n"
<< "2. || (logical or)\n"
<< "3. ! (logical not)\n\n"
<< "Please enter 1 for true, 0 for false with a logical operator\n"
<< "Parenthese s may be used to alter the order in which operators are
applied.\n"
<< "Example:\n "
<< "1 && 0 or 1 || 0 ";

cin.getline(x, 32, '\n'); // stores input in variable called x

cout << bool (x) << endl; // prints out true or false value
return 0;
}

// Main function invokes perform operation function

int main(){
Myclass mc;
mc.func();
return 0;
}
Jul 19 '05 #1
5 8732

"PerritoPer ron" <pe***@aol.tv > wrote in message
news:3g******** ************@tw ister.austin.rr .com...
//I need a little help with this program, it runs but the output is not
correct.
//Can i get some help here please u fellas???

// This Program asks for user input like 1 && 0 and prints if it is true or false
// it calculates the input to perform Logical operation from input

#include <iostream>
using namespace std;

// Defines class

class Myclass{
public:
int func();
};

// Function to perform operation

int Myclass::func() {

char x[32] = ""; // array to receive input

cout << "\n\t\t\t T R U T H T A B L E\n" // asks for input
<< "\t\t\t ========= =========\n\n"
<< "Logical operators allow us to form more complex test expressions\n"
<< "for decision and repetition statements. The logical operators
are:\n\n"
<< "1. && (logical and)\n"
<< "2. || (logical or)\n"
<< "3. ! (logical not)\n\n"
<< "Please enter 1 for true, 0 for false with a logical operator\n"
<< "Parenthese s may be used to alter the order in which operators are
applied.\n"
<< "Example:\n "
<< "1 && 0 or 1 || 0 ";

cin.getline(x, 32, '\n'); // stores input in variable called x

cout << bool (x) << endl; // prints out true or false value
You need to learn how to write a parser. This is not a quick or easy
operation. Do not expect a one line solution like bool(x), we're talking
maybe 40 lines of code, depending on how sophisticated you want to get. You
need to analyse the input data character by character and make choices based
in the input you find.

To be perfectly honest this seems far too difficult for you at your current
level of ability, but if you really want to know how find a book on parsing
and study. For instance Stroustrup has a parser in chapter 6 'The C++
Programming Language', or Avo Sethi and Ullman in chapter 2 of 'Compilers,
Principles, Techniques and Tools'


return 0;
}

// Main function invokes perform operation function

int main(){
Myclass mc;
mc.func();
return 0;
}


john
Jul 19 '05 #2
You right I don't know about parsing..
but I am writting here to get some help and maybe you can lead me on how to
parse..
if you could learned it, so could I.
so can you just give me an example or some guidelines here please.
Thanks John..

----- Original Message -----
From: "John Harrison" <jo************ *@hotmail.com>
Newsgroups: comp.lang.c++
Sent: Sunday, July 13, 2003 3:08 PM
Subject: Re: Truth Table help


"PerritoPer ron" <pe***@aol.tv > wrote in message
news:3g******** ************@tw ister.austin.rr .com...
//I need a little help with this program, it runs but the output is not
correct.
//Can i get some help here please u fellas???

// This Program asks for user input like 1 && 0 and prints if it is true or
false
// it calculates the input to perform Logical operation from input

#include <iostream>
using namespace std;

// Defines class

class Myclass{
public:
int func();
};

// Function to perform operation

int Myclass::func() {

char x[32] = ""; // array to receive input

cout << "\n\t\t\t T R U T H T A B L E\n" // asks for input
<< "\t\t\t ========= =========\n\n"
<< "Logical operators allow us to form more complex test expressions\n" << "for decision and repetition statements. The logical operators
are:\n\n"
<< "1. && (logical and)\n"
<< "2. || (logical or)\n"
<< "3. ! (logical not)\n\n"
<< "Please enter 1 for true, 0 for false with a logical operator\n"
<< "Parenthese s may be used to alter the order in which operators are
applied.\n"
<< "Example:\n "
<< "1 && 0 or 1 || 0 ";

cin.getline(x, 32, '\n'); // stores input in variable called x

cout << bool (x) << endl; // prints out true or false value

You need to learn how to write a parser. This is not a quick or easy
operation. Do not expect a one line solution like bool(x), we're talking
maybe 40 lines of code, depending on how sophisticated you want to get.

You need to analyse the input data character by character and make choices based in the input you find.

To be perfectly honest this seems far too difficult for you at your current level of ability, but if you really want to know how find a book on parsing and study. For instance Stroustrup has a parser in chapter 6 'The C++
Programming Language', or Avo Sethi and Ullman in chapter 2 of 'Compilers,
Principles, Techniques and Tools'


return 0;
}

// Main function invokes perform operation function

int main(){
Myclass mc;
mc.func();
return 0;
}


john

Jul 19 '05 #3

"PerritoPer ron" <pe***@aol.tv > wrote in message
news:8b******** ************@tw ister.austin.rr .com...
You right I don't know about parsing..
but I am writting here to get some help and maybe you can lead me on how to parse..
if you could learned it, so could I.
so can you just give me an example or some guidelines here please.
Thanks John..


The trouble is that it is far too big a subject to deal with in a newsgroup
post. That's why I'd recommend a book.

But you will need to write code something like this (x is the string you've
read in so far)

switch (x[i])
{
case '0':
// do whatever
break;
case '1':
// do whatever
break;
case '&':
// do whatever
break;
case '|':
// do whatever
break;
case '!':
// do whatever
break;
case '(':
// do whatever
break;
case ')':
// do whatever
break;
}

Basically you have to break down the expression into individual characters,
make decisions based on what you find. Also you need to understand
recursion, because the routines you write will be recursive.

You are not going to figure this out by yourself, even with help from this
newsgroup, no-one could. You need to find a book or a person who can explain
this to you.

john

Jul 19 '05 #4
I know about loops, functions, pointers, arrays and switch,

the point John is that tomorrow I have to turn that sucker in...

I am just putting things together now...

what about to ouput..??

Thanks again John you helped me some..

Jul 19 '05 #5

"PerritoPer ron" <pe***@aol.tv > wrote in message
news:Tv******** ************@tw ister.austin.rr .com...
I know about loops, functions, pointers, arrays and switch,

Don't think you'll need pointers.
the point John is that tomorrow I have to turn that sucker in...
Tough, you're not going to get a complete solution, but something will be
better than nothing.

I am just putting things together now...

what about to ouput..??
Huh?

Thanks again John you helped me some..


I'm surprised you're being asked to do this without having had the concepts
explained (or did you just skip those lessons). It seems very difficult.

John
Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6588
by: Mario | last post by:
Can some1 help me with the code for a truth table????
0
1244
by: dayzman | last post by:
Hi, Does anyone know of a C++ package that outputs a (optimised) boolean expression given a truth table? Cheers, Michael
6
2177
by: Tony Johansson | last post by:
Hello Experts! I have the user defined class called Boolean that should be handle all kind of logic expression such as if (a && b && c) or if (!a && b && c) osv I have the class definition Boolean and the main program below. I have overloaded these operator symbols =, ==, !=, !, ||, &&. Now to my question I have some problem with this...
2
1437
by: lemnitzer | last post by:
TV report: all 15 British sailors confess to illegally entering Iranian Waters Here are the links: http://news.google.com/news?hl=en&ned=us&q=all+15&btnG=Search+News http://www.canada.com/ottawacitizen/news/story.html?id=64454ab9-229c-44a8-9875-2f59e570c5f9&k=44029 NOW COMPARE THAT WITH THE YANK MOTHER FUCKING PEDOPHILE BASTARDS AND...
6
17097
by: natkw1 | last post by:
Hi all, I'm new to C and kind of confused on this. I've had a look around this group for suggestions but still not sure why the warning is occurring. What I've done is this <code snip> void foo(char loc) {
1
1619
by: Rohanrajs82 | last post by:
Hi, Can anybody help me? I have to construct a truth table of 97 columns. I have tester channels from 1 to 97. I have to make a truth table with all the possible combinations. Also, I have some dummy channels in it where I have to put a dummy value. Regards, Rohan.
6
11437
by: ambanks04 | last post by:
ok taking computer science class anybody know what to do i am not computer literate CoSc 111.003 Spring 2008 Assignment 4 1) Each student shall design, develop, code, test and submit an Original computer program which uses a function or functions to display the TRUTH TABLES for the Logical And, the Logical Or, and the Logical Not...
5
6585
by: andrea | last post by:
Well I would like to make a little program that given a certain logical expression gives the complete truth table. It's not too difficult in fact, I just have some doubts on how to design it. I thought something like that: class Term:
0
7499
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...
0
7432
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...
0
7689
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7456
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...
0
7786
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6022
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...
0
5076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3490
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...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.