PDA

Click to See Complete Forum and Search --> : c++ challange


linuxcomando
June 27th, 2002, 12:52 AM
Thought id give you programers a challeng, Ill post the program prob tommorow.

De Morgan's Laws can sometimes make it more convenient for us to express a logical expression. These laws state that the expression !(condition1 && condition2) is logically equivalent to the expression (!condition1 ||!condition2). Also the expression !(condition1 || condition2) is logically equivalent to the (!condition1 && !condition2). Use De Morgan's Laws to write equivalent expressions for each of the following then write a program to show that both the original expressions 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 ))

avdven
June 27th, 2002, 01:03 AM
I think these are right (it's been a while since I've used DeMorgan's Law)

a) !(x < 5) && !(y >= 7) = !((x < 5) || (y >= 7))

b) !(a == b) || !(g != 5) = !((a == b) && (g != 5))

c) !((x <= 8) && (y > 4)) = !(x <= 8) || !(y > 4)

d) !((i > 4) || (j <= 6)) = !(i > 4) && !(j <= 6)

Sorry, but I don't feel like writing a program right now... Nice idea, though!

AJ

xmaddness
June 27th, 2002, 01:05 AM
a) !( x < 5) && !( y >= 7 )
b) !( a == b) || !(g != 5)
c) !( ( x <= 8 ) && ( y > 4) )
d) !( (i > 4 ) || ( j <= 6 ))


a)

!(x<5) && !(y>=7)

!((x<5)||(y>=7))

#include <iostream.h>
int main()
{
int x;

if (!(x<5) && !(y>=7))!=(!((x<5)||(y>=7)))
{
cout<<"That's not Right!";
}
else
{
cout<<"You are correct!";
}
return 0;
}

I don't have a compiler at work. Does that prog look like it will work? I think it should, but then again i'm still learning c++. I'm not even gunna attempt any more unless this one works. heh
x

(V)/\><
June 27th, 2002, 02:11 AM
a) !( x < 5) && !( y >= 7 ) == !( x < 5 || y >= 7 )
b) !( a == b) || !(g != 5) == !( a == b && g != 5 )
c) !( ( x <= 8 ) && ( y > 4) ) == !( x <= 8 ) || !( y > 4 )
d) !( (i > 4 ) || ( j <= 6 )) == !( i > 4 ) && !( j <= 6 )

#include <iostream>
using namespace std ;
void main ()
{
for( x=0, y=0; x=-1; x++,y++)
{
if ( (!( x < 5) && !( y >= 7 )) == (!( x < 5 || y >= 7 )) cout << "bOOOOOOGA\a\t" ;
else cerr << "blAAAAARRRGH" << endl ;
}
}

sqoal
July 1st, 2002, 03:05 PM
i'm very2x confused

chaoswraith
July 1st, 2002, 03:32 PM
The answers simplified as far as they can go are:

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

as for the program, i'm too tired at the moment to write it up...

Chaoswraith

ammo
July 1st, 2002, 05:12 PM
Heh, for a second I just felt like I was back in a first year CS maths course again!
Don't do that again! ;)

Ammo