Results 1 to 2 of 2

Thread: Help needed with fragment question

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Location
    UK
    Posts
    1

    Lightbulb Help needed with fragment question

    Hi

    I've just started a computer course and am fairly new to VB.

    My lecturer dumped this on me out of the blue, I'm not so strong at this (theory, written work) as just making, designing and testing projects. This is the sort of thing I struggle with. Any help, with answers and/or explanations will be welcome. Here is the evil problem in question:
    (1)For each of the lines (A) – (E) give a condition showing when the outcome of the fragment is assigned by that line
    (2)produce outcome table
    (3) Make a equivalent fragment involving a single case statement of the form “if……then….else”
    (4)Make a equivalent fragment involving a single case statement with five ifs

    Code:
    Case
    	If q then case
    		If p then x:=x+1				(A)
    		else x:=x+2					(B)
    		end-case
    else case
    		if r then case
    			if p then x:=x+1			(C) 
    			 else x:=x+2				(D)
    			end-case
    		else x:=x+2					(E)
    end-case
    end-case


    Any help, any at all! (lol) will be welcome.

    Thanks

  2. #2
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: Help needed with fragment question

    First, let me rewrite that code so that it is more readable.
    Code:
    Case
      If q then case
        If p then x:=x+1    (A)
        else x:=x+2         (B)
        end-case
      else case
        if r then case
          if p then x:=x+1  (C)
          else x:=x+2       (D)
          end-case
        else x:=x+2         (E)
        end-case
      end-case
    Now then, I don't have a clue what language this is supposed to be. Nevertheless, I can see what this should do, and can write equivalent VB code.
    VB Code:
    1. If q Then
    2.   If p Then
    3.     x = x + 1   '(A)
    4.   Else
    5.     x = x + 2   '(B)
    6.   End If
    7. Else
    8.   If r Then
    9.     If p Then
    10.       x = x + 1 '(C)
    11.     Else
    12.       x = x + 2 '(D)
    13.     End If
    14.   Else
    15.     x = x + 2   '(E)
    16.   End If
    17. End If
    Hopefully that make more sense to you. Part (1) should be easy. For line (A) to be executed, q must be true and p must also be true. For line (B), q must be true and p must be false. And so on...
    (A) q true, p true, r doesn't matter
    (B) q true, p false, r doesn't matter
    (C) q false, r true, p true
    (D) q false, r true, p false
    (E) q false, r false, p doesn't matter

Posting Permissions

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



Click Here to Expand Forum to Full Width