1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

C++ Help

Discussion in 'Software Development' started by Rhino24, Feb 22, 2008.

Thread Status:
Not open for further replies.
Advertisement
  1. Rhino24

    Rhino24 Thread Starter

    Joined:
    Feb 8, 2008
    Messages:
    41
    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
     
  2. TheRobatron

    TheRobatron

    Joined:
    Oct 25, 2007
    Messages:
    551
    I don't quite understand... What is the code that you're trying to write going to do?
     
  3. Rhino24

    Rhino24 Thread Starter

    Joined:
    Feb 8, 2008
    Messages:
    41
    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.
     
  4. Methiah

    Methiah

    Joined:
    Feb 28, 2008
    Messages:
    7
    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
As Seen On...

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.

Join over 733,556 other people just like you!

Loading...
Similar Threads
  1. Rhino24
    Replies:
    1
    Views:
    1,080
  2. Rhino24
    Replies:
    7
    Views:
    1,093
  3. banani
    Replies:
    1
    Views:
    1,182
  4. HAJ
    Replies:
    2
    Views:
    974
  5. eke21
    Replies:
    4
    Views:
    1,063
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/685948