SDI project 2
Flowchart Symbols and What They Mean
The Project 2 flowchart can seen a bit daunting, but if you break it down into its pieces and parts, you’ll see that it’s not a scary as it looks. To begin, let’s take a look at the flow of the main code.
We know that this part of the flowchart is the main code because it contains the Start and Finish support details in the Terminator symbols. Remember that these indicate where our code will begin and where it will end.
The next symbol of the flowchart indicates Internal Storage, which is the technical term for stored values. This symbol also contains support details that tell us what should be happening in our code at this time. In this case, we need to declare and define our string variable, number variable, and our array.
The next symbol is the Predefined Process symbol. This symbol indicates that there is a function that needs to be performed. In this case, the support detail tells us the name of the function we need to look for. For simplicity, we’ve simply called it Procedure in the flowchart. This indicates that control of the code is being passed to another process and won’t return to our main code until that process is complete.
To see what the flow will be in this other process, we need to look for a flowchart with the same support details. That is, the separate flowchart for our procedure should begin with a Start oval with the word Procedure in it. And, if you look at the Project 2 flowchart, you’ll see that we do, indeed have that!
1
The Procedure Flowchart
You’ll notice that there’s a new symbol containing the support detail Argument and it’s pointing at the Procedure oval. This indicates that we have to send an argument to the procedure. It can be any data type you want to use (number, string, Boolean, etc.). You do this in the code when you call the function. So, let’s assume you’re going to use the name myProcedure as the name of your procedure and you want to pass the number 5 as the argument. You would write the code like this:
! myProcedure(5);
The number 5 will be passed to the procedure as the argument.
Notice, also, that the first symbol within the procedure flowchart is a Conditional symbol and that the support detail reads Argument Conditional. This means that the first thing that should happen in your procedure code is an if statement that somehow uses the argument that is passed. So, if we use the previous example of passing an argument of 5, your first step in the procedure will be to compare that 5 to something, such as a variable. Then, you need to send some kind of output to the console.
The final symbol in the Procedure flowchart is the Back symbol. This indicates that the procedure is finished and control is passed back to the main code. If you look at the flowchart for our main code, you’ll see that the next symbol in the flowchart is another Predefined Process symbol with the support details of Boolean Function. Remember that this indicates that control of the code will flow to a separate function. Do we have a flowchart that begins with an Terminator symbol with support details indicating it’s a Boolean Function? Yes, we do!
2
The Boolean Function
This function begins with the Terminator symbol but has two Argument symbols pointing into the symbol. This means that you will need to send two arguments to this function. Again, the data type can be whatever you would like to use. Remember that in order to do this, you also have to declare your function so that it can accept arguments.
Similar to the procedure function, we need to perform an if statement to perform a comparison conditional. Once the conditional is done, you also need to perform some kind of output to the console.
The next symbol is the Terminator for the function but rather than simply send control back to the main code, we also want to return a value from the function. This means we are sending a value out of the function and back to the main code for use. You can do this by calling the function from a variable assignment. So, if you have declared a variable myReturn, you can call the function like the following:
! myReturn = booFunction(“some string”, 5);
The value returned from the function will be stored in the variable myReturn. Also, notice that the Terminator symbol reads, Return Boolean. This means that your Boolean function must return a Boolean value, so in our example, myReturn will be either true or false.
Once control has been returned to the main code, the next symbol is another Predefined Process symbol, which indicates that the Number Function is the next to be called.
3
The Number Function
The first thing you should notice about this function is that the Argument symbol pointing into the Number Function terminator says Number instead of Argument. This is because you are required to send a number as an argument to this function. Similarly, you’ll notice that the Return must also be a number.
This function contains a While Loop, which will require you to perform some kind of math function during the course of the loop. In most cases, the math component will be completed when you are configuring the while loop itself by performing some kind of countdown or count up.
Once the Return is performed, control returns back to the main code and the next function is executed.
One very important thing to remember is that a function can only return a single value. That is, it can return a single string, a single Boolean, a single number, or a single array. And once the code hits the return, the flow of the code is returned to the main code. If you have any code after the return, it will not run because control no longer belongs to the function; it has been returned to the main code.
The flow of the Project 2 flowchart continues through the rest of the Predefined Processes and the functions operate similar to the ones already detailed. To leave some of the fun up to you, see if you can figure out how the rest of your code will need to be written in order to follow the flow of the flowcharts.
4