-
c++ challange
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 ))
-
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
-
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
-
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 ;
}
}
-
-
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
-
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