Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Software Development Software Development
Search Search
Search for:
Tech Support Guy > > >

C++ Help


(!)

Rhino24's Avatar
Rhino24 Rhino24 is offline
Member with 41 posts.
THREAD STARTER
 
Join Date: Feb 2008
Experience: Beginner
22-Feb-2008, 09:42 AM #1
C++ Help
Hello, I have a project and I just need some help with the source code. Is there anyone out there that can get me started on the right foot. O.K and the problems goes like this; I have to write equivalent expressions for each of the following, then write a program to show that the original expression and the new expression in each case are equivalent:

a) ! ( x < 5 ) && ! ( y >= 7 )
b) ! ( a == b ) || ! ( g != 5 )
c) ! ( x <= 8 ) && ( y > 4 )
d) ! ( i > 4 ) || ( j <= 6 )

Can anyone HELP me out Please!!

Thanks
TheRobatron's Avatar
TheRobatron TheRobatron is offline
Computer Specs
Senior Member with 551 posts.
 
Join Date: Oct 2007
Location: England
Experience: Intermediate
25-Feb-2008, 02:43 PM #2
I don't quite understand... What is the code that you're trying to write going to do?
Rhino24's Avatar
Rhino24 Rhino24 is offline
Member with 41 posts.
THREAD STARTER
 
Join Date: Feb 2008
Experience: Beginner
25-Feb-2008, 04:04 PM #3
I have to use De Morgan's law to write equivalent expressions for each of the following that I listed, then write a program to show the original expression and the new expression in each case are equivalent.
Methiah's Avatar
Methiah Methiah is offline
Junior Member with 7 posts.
 
Join Date: Feb 2008
28-Feb-2008, 11:35 PM #4
Is this to simply test if it is true for single input values of x, y (for example)?
or a range of values?

A crude way of doing it is simply

// input range to scan values
cin >> lowerx;
cin >> upperx;
...

// loop over all combinations of x and y
for (int x = lowerx; x < upperx; x++)
{
for (int y = lowery; y < uppery; y++)
{
if (!(x<5)&&!(y>=7) != !((x<5)||(y>=7))) // test equivalence
{
printf("Expressions are not equivalent. x = %d, y = %d", x, y);
return;
}
}
}

printf("Expressions are equivalent over the specified range");
return;

of course there is no need to scan the range, you just have four cases to examine
to show De Morgan's law to be correct
e.g. !a && !b == !(a || b) or !a || !b == !(a && b)
when
a == TRUE, b == TRUE
a == TRUE, b == FALSE
a == FALSE, b == FALSE
a == FALSE, b == TRUE


// test a single set of values of x and y

bool a = x < 5;
bool b = y >= 7;


if (!a && !b == !(a || b))
printf("Equivalent");
else
printf("Not equivalent");

and just test the four cases with specific values of x and y (doesn't matter which values really)
e.g.
x = 4, y = 7 (TRUE, TRUE)
x = 4, y = 6 (TRUE, FALSE)
x = 5, y = 6 (FALSE, FALSE)
x = 5, y = 7 (FALSE, TRUE)

It all really depends on what the question expects from you.
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑