|
-
Jan 31st, 2007, 02:40 PM
#1
Thread Starter
New Member
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
-
Jan 31st, 2007, 05:53 PM
#2
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:
If q Then
If p Then
x = x + 1 '(A)
Else
x = x + 2 '(B)
End If
Else
If r Then
If p Then
x = x + 1 '(C)
Else
x = x + 2 '(D)
End If
Else
x = x + 2 '(E)
End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|