You are on page 1of 5

Chris Trimble

Tuesday Night
7/15/2014

Unit 5
Assignment & Exercise
1. Explain what is meant by the term conditionally executed.
If this condition is true, the action is performed. If the condition is false, the
action is skipped. The action is conditionally executed because it is performed
only when a certain condition is true.
2. You need to test a condition and then execute one set of statements if the
condition is true. If the condition is false, you need to execute a different set of
statements. What structure will you use?
A single alternative decision structure
3. If you need to test the value of a variable and use that value to determine which
statement or set of statements to execute, which structure would be the most
straightforward to use?
A nested decision structure
4. Briefly describe how the AND operator works.
The AND operator connects two Boolean expressions into one compound
expression. Both subexpressions must be true for the compound expression to be
true.
5. Briefly describe how the OR operator works.
The OR operator connects two Boolean expressions into one compound
expression. One or both subexpressions must be true for the compound expression
to be true. It is only necessary for one of the subexpressions to be true, and it does
not matter which.
6. When determining whether a number is inside a range, which logical operator is it
best to use?
AND
7. What is a flag and how does it work?
A variable that signals when some condition exists in the program.

1. Design an If- Then statement (or a flowchart with a single alternative decision
structure) that assigns 20 to the variable y and assigns 40 to the variable z if the
variable x is greater than 100.
If x > 100 Then
y = 20 AND z = 40
End If
2. Design an If- Then statement (or a flowchart with a single alternative decision
structure) that assigns 0 to the variable b and assigns 1 to the variable c if the
variable a is less than 10.
If a < 10 Then
b = 0 AND c = 1
End If
3. Design an If- Then- Else statement (or a flowchart with a dual alternative decision
structure) that assigns 0 to the variable b if the variable a is less than 10.
Otherwise, it should assign 99 to the variable b.
If a < 10 Then
b=0
Else
b = 99
End If
4. The following pseudocode contains several nested If- Then- Else statements.
Unfortunately, it was written without proper alignment and indentation. Rewrite the
code and use the proper conventions of alignment and indentation.
If score < 60 Then
Display " Your grade is: F."
Else
If score < 70 Then
Display " Your grade is: D."
Else
If score < 80 Then
Display " Your grade is: C."
Else
If score < 90 Then
Display " Your grade is: B."

Else
Display " Your grade is: A."
End
5. Design nested decision structures that perform the following: If amount1 is
greater than 10 and amount2 is less than 100, display the greater of amount1 and
amount2.
If amount1 > 10 AND amount2 < 100 Then
If amount1 > amount2 Then
Display amount1 is greater
Else
Display amount2 is greater
End If
Roman Numerals

If inputNmbr == 1Then
Display I
Else
If inputNmbr == 2Then
Display II
Else
If inputNmbr == 3 Then
Display III
Else
If inputNmbr == 4 Then
Display IV
Else
If inputNmbr == 5 Then
Display V
Else
If inputNmbr == 6 Then
Display VI
Else
If inputNmbr == 7 Then
Display VII
Else
If inputNmbr == 8 Then
Display VIII
Else
If inputNmbr == 9 Then
Display IX
Else

If inputNmbr == 10 Then
Display X
Else
Display ERROR!
End If
2. Areas of Rectangles

Programming Code:

Module Module1
Sub Main()

'declare variables
Dim length1 As Double = 0
Dim width1 As Double = 0
Dim length2 As Double = 0
Dim width2 As Double = 0
Dim area1 As Double = 0
Dim area2 As Double = 0
'Get input from the user
Console.WriteLine("")
Console.Write("Enter the length of the 1st rectangle: ")
length1 = Console.ReadLine()
Console.WriteLine("")
Console.Write("Enter the width of the 1st rectangle: ")
width1 = Console.ReadLine()
Console.WriteLine("")
Console.Write("Enter the length of the 2nd rectangle: ")
length2 = Console.ReadLine()
Console.WriteLine("")
Console.Write("Enter the width of the 2nd rectangle: ")
width2 = Console.ReadLine()
Console.WriteLine("")
'Calculate area of the rectangles
area1 = length1 * width1
area2 = length2 * width2
'Display total area of each rectangle
Console.WriteLine("")
Console.Write("The area of the 1st rectangle is " & area1 & ".")
Console.WriteLine("")
Console.Write("The area of the 2nd rectangle is " & area2 & ".")
Console.WriteLine("")
Console.WriteLine("")
'Deciding if the areas are the same or if one is biiger than the other
If area1 = area2 Then
Console.WriteLine("The areas are the same.")
Console.Write("")
Else
If area1 > area2 Then
Console.WriteLine("The 1st rectangle has the greater area.")
Console.Write("")
Else
Console.WriteLine("The 2nd rectangle has the greaterarea.")

Console.Write("")
End If
End If
End Sub
End Module

3. Mass and Weight


Weight = Mass 9.8

Programming Code
Module Module1
Sub Main()
'declare variables
Dim mass As Double = 0
Dim weight As Double = 0
'Get input from the user
Console.WriteLine("")
Console.Write("Enter the mass (in kilograms): ")
mass = Console.ReadLine()
Console.WriteLine("")
'Calculate weight of object
weight = mass * 9.8
'Display total weight of object
Console.WriteLine("")
Console.Write("The objects weight is " & weight & " Newtons.")
Console.WriteLine("")
Console.WriteLine("")
'Deciding if the object is too heavy or too light.
If weight > 1000 Then
Console.WriteLine("The object is too heavy.")
Console.Write("")
Else
If weight < 10 Then
Console.WriteLine("The object is too light.")
Console.Write("")
Else
Console.WriteLine("The objects weight is just right.")
Console.Write("")
End If
End If
End Sub
End Module

You might also like