Monday 27 February 2012

Selection: If & Switch 4.1, 4.2, 4.3 and 4.4

Activity 4.1
Blog Task: Apply Discount



1. Use the 5 step process to create the algorithm for the following problem (modified from activity 1.1)

You need to know the cost of sending a parcel to someone. The price of sending the item will depend upon its weight. The postal service has set a standard charge per kilo of item weight. If the postage charge is greater than $100.00, a 10% discount is applied to the amount.
Inputs: 
postal service kilo charge.
parcel weight. 
Processing:
Multiply postal service kilo charge by parcel weight
 if total cost charge is greater then $100.00 a 10% discount is deducted to the cost.
Outputs:
TotalCost

Start CalculateTotalCost 
1.Prompt user for the postal service kilo charge
  2. Get postal service kilo charge
  3.Prompt user for postal service kilo charge 
  4. Get postal service kilo charge
  5. TotalCost = postal service kilo charge x parcel weight
  6. If Total Cost charge >$100.00  
  7.10% discount is deducted to cost.
  8 .  Display TotalCost 
End 




Activity 4.2
Blog Task: Or


1. Read the following pseudocode:

If Number > 8 Or Number = 10
Display “This number meets the condition.”
Else
Display “This number does not meet the condition.”
End If
2. Answer the following question:
What number would need to be stored in Number to make this program display the message This number does not meet the condition? Why?   

 This is a silly question because the pseudocode is repeating itself.
Any number less then 8 because the code is asking for a number greater then 8 rather then less.  


Activity 4.3
Blog Task: And


1. Read the following pseudocode:

If Number > 8 And Number < 10
Display “This number meets the condition.”
Else
Display “This number does not meet the condition.”
End If
2. Answer the following question:
What number would need to be stored in Number to make this program display the message This number does not meet the condition? Why?

Any number but 9 because the code is asking for the number greater then 8 but less then 10. 




Activity 4.4
Blog Task: Switch


1. Create the pseudocode for a switch statement that checks the value of a variable named Color. The possible values include Pink, Green, Purple, Orange, Black. The switch statement should display the color. Include an Else Case.  


Switch Color 
Case "Pink"
            "Display Pink" 

Case  "Green" 
           "Display Green" 

Case "Purple"
             "Display Purple"

Case "Orange" 
           "Display Orange" 

Case "Black" 
          "Display Black" 

Case "Else" 
            "If Else Display Not Pink, Green, Purple, Orange, Black



1 comment: