Operating Systems/Programming

Pseudocode & Flowcharts

It can be quite intimidating learning programming. Thankfully, many exercises help simplify everything so that can minimize how many times you want to throw your keyboard against the wall. To begin developing code, creating pseudocode and a flowchart will help visualize and plan what the code will consist of, how it will flow (order of operations), and anticipate any problems that may arise (it is much easier to edit pseudocode than finished program code.

Pseudocode is a method of building computer algorithms using a mix of natural and programming languages. When creating Fortran pseudocode, for example, it is important to remember that while they implement the common Fortran symbols (-, +, *), specific keywords can be used such as WRITE, READ, and PRINT. Also, indentation should be used to identify loops or branches of instruction.

There are also numerous other syntax styles one can follow, such as C, Pascal, and Structured Basic. Pseudocode by itself does not obey any rules for a particular language, it is merely an adoption of multiple languages to give a high-level understanding of the code. To simplify this explanation, imagine you are preparing to write a multiple page paper. One of the first steps to do this is to create an outline consisting of each section of the paper. Pseudocode is exactly like this, a simple step-by-step outline of your code.

In this example, the following question can be answered with a simple code.

• What would a Pseudo Code look like for converting Miles to Kilometers?
1. Prompt the user for the number of kilometers and save in the variable kilometers.
2. Compute kilometers to miles by multiplying kilometers by the conversion constant (0.621) and save it in the variable miles.
3. Display the number in the variable miles.
• Simple program-like pseudocode

Program to convert kilometers to miles.

Variable kilometers is double.

Variable miles is double.

Output “Enter kilometers”

Input kilometers

Compute miles = 0.621 * kilometers

Output kilometers

• Pseudocode Flowchart

Another method for beginning the first steps in designing code is to create a flowchart using the pseudocode. In the question below, retrieved from Data Genetics, is an excellent example of how this can work.

100m Race

Three friends decide to exercise to burn off some calories; they challenge each other to 100m sprints. Alice races against Bob and beats him by 20 meters (as Alice is crossing the finish line, Bob is 20 meters behind). Bob races against Charlie and beats him by 20 meters.

Question: If Alice raced against Charlie, how much would she beat him by?

(If we assume that each person runs at a fixed, consistent, and constant speed on each and every race).

Here are some Pseudocode Flowcharts I created for this problem.

Note: Each shape of the flowchart represents a different function.

For example, an oval indicates the beginning of a program, a parallelogram is a point where there is input to or output from the program, and a diamond is a point where a decision is made.

For a rundown of the information needed to answer this question, the following items need to be addressed.

First, their speeds would need to be calculated. If Alice finished the 100m race while Bob is at 80m, then Bob would run at 80% of Alice’s speed. Additionally, Charlie runs 80% of the speed of Bob. With this information, Charlie runs at 80% x 80% of the speed of Alice, so, 0.80 x 0.80 = 0.64. If Alice was to race against Charlie, then Charlie will be at 64m when Alice finishes. Finally, this means that Alice would beat Charlie by 36m because 100m – 64m = 36m.

The answer would to this question be that Alice will beat Charlie by 36m.

By completing these steps, creating code should be simplified and stress-free due to already understanding the problem you wish to address, the basic strategy for your solution, and the order of operations in which you should follow. Hope it helps!

Source:

Image and Content by Data Genetics. 19 Nov 2018. Retrieved from http://datagenetics.com/blog/december32016/index.html.