CLASS OBJECTIVE
Create an algorithm to decide between three different formulas, by using the decision symbol in Raptor, to calculate areas from a rectangle, circle or triangle.
INTRODUCTION
In the last course you learned to use the IF() function in a spreadsheet. It helped you to create programs in which users could make decisions, for example, between answers or products, etc. Now you'll program Raptor algorithms to make decisions, to select between different options.
DECISIONS
Just like in the last class, you just have to drag the decision (selection) symbol from the left panel to the flowchart. It is very important to place it where a decision has to be made, after you have saved information in a variable.
Once you've inserted the symbol you can double click on it to configure the decision. A decision is a compairson operation like in spreadsheets. For example, N1=10, lastname="González", etc.
ACTIVITY
Today's program will calculate areas of common shapes: rectangle, circle or triangle. Open Raptor and start saving the file. Name it Areas of common shapes.
Obviously, you'll have to use decisions, Selections symbols, to create different paths in the code.
From this point on it's important that you receive less instructions, so look at the flowchart and try to solve the problem.
- Use an input to ask for the shape: (1) for triangle, (2) for rectangle, (3) for circle. The variable will be named Shape.
- Remember to double click on every symbol to set the configurations. For example, to get the decision about the shape or to get the shapes dimensions ,you need inputs, and every input need a variable to save the data.
- Use the selection symbol, as shown, to create the four paths. Ask for the variable Shape to decide the path.
- Each path should ask for the data of the selected shape, for example: triangle need the base and the height to calculate the area.
- If the user don't select a correct option, then a message should be shown.
Test the program and if it works send it to your teacher through Classroom.
CLASS NOTES
As always, write down in your notebook the title of the class, the objective and follow the instructions.
- In your own words, What is the difference between sequential programming (last class) and decisions/selections programming? (Use at least 60 words)
- Now explain the Rhombus symbol (Diamond): What does it do? What does it need to work properly?