c++ challange
Results 1 to 7 of 7

Thread: c++ challange

  1. #1
    Senior Member linuxcomando's Avatar
    Join Date
    Sep 2001
    Posts
    430

    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 ))

  2. #2
    The Iceman Cometh
    Join Date
    Aug 2001
    Posts
    1,210
    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

  3. #3
    Webius Designerous Indiginous
    Join Date
    Mar 2002
    Location
    South Florida
    Posts
    1,121
    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

  4. #4
    Senior Member
    Join Date
    Jun 2002
    Posts
    394
    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 ;
    }
    }
    Hmm...theres something a little peculiar here. Oh i see what it is! the sentence is talking about itself! do you see that? what do you mean? sentences can\'t talk! No, but they REFER to things, and this one refers directly-unambigeously-unmistakably-to the very sentence which it is!

  5. #5
    Banned
    Join Date
    Jun 2002
    Posts
    9
    i'm very2x confused

  6. #6
    Junior Member
    Join Date
    Jun 2002
    Posts
    14
    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

  7. #7
    Senior Member
    Join Date
    Sep 2001
    Posts
    1,027
    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
    Credit travels up, blame travels down -- The Boss

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides