Showing posts with label computer program design. Show all posts
Showing posts with label computer program design. Show all posts

Tuesday, September 7, 2010

Introduction to Pseudocode

First off, what is pseudocode? It is merely a combination of: pseudo (meaning almost, approaching, or trying to be) and code (the language you are writing in; the set of instructions in a program). It is an informal written representation of your program. In pseudocode you don't need to follow syntax requirements, and really as long as it makes sense to you it doesn't matter how you do it. Here are a few guidelines you can follow however to get the most use out of your pseudocode:

  1. Begin and end your code with terminal statements (i.e. begin,end,start,stop).
  2. Don't use terminal statements if you don't like them.
  3. Use indentation freely to increase readability.
  4. Don't overuse indentation.
  5. Make it make sense to you.
Basically it all boils down to, how do you want to do it? As you learn more about if then, while, do while, statements it becomes more clear what to do. Here is a short example using the same program in my Flowchart introduction.

             start
               input phoneNumber
               call phoneNumber
               if phoneAnswered = no
                 call phoneNumber
               else output "Hello"
             end


Does anyone else have some tips or pointers when using pseudocode?

    Monday, September 6, 2010

    Flowchart

    Flowchart Example
    Here is a simplified example of a flowchart for a program that calls a number for you until someone answers and says "Hello" for you. You'll notice at the beginning and the end there is the racetrack shaped symbol:

    Terminal Symbol


    This is called the terminal symbol and denotes the beginning and end of a program.



    After the terminal symbol you should notice the parallelogram shape:



    Input/Ouput Symbol

    This is the input/ouput symbol. Anytime a new constant or variable needs to be input or output, use this symbol. Here we use it to input phoneNumber and ouput the phrase "Hello".




    Next in the flowchart is the plain rectangle shape:


    Processing Symbol

    Here is the processing symbol. This is where something is done, input is used, and/or data is manipulated. Here we use it to call the input phoneNumber.


    The final shape looks like a diamond:

    Decision Symbol

    The diamond shape denotes the decision symbol. Here the computer checks to see if a statement is true or false and acts on that truth value as you have determined. Here we have said if the phone is not answered then call again. If it is, then the program finishes by saying "Hello" and ending.

    Note: The does not equal could have also been written as !=, <>, or simply "does not equal". This is your preference. Sometimes using does not equal makes it easier to understand what the program, rather than using "= no."

    Note 2: Yes and no can be denoted as 1 and 0 respectively.

    Thursday, September 2, 2010

    Structured Programming

    Structured programming states that any program can be created through the use of three procedures: sequence, selection, and repetition.

    1. Sequence: One thing happens, then another, then another... Get bowl, Place bowl, fill bowl with 1 cup cereal, put 1/4 cup milk in bowl, scoop cereal, eat cereal. To make this work each process must be done in order, else you may be eating your cereal off of the table.

    2. Selection: Selection is the decision portion of your program. If you don't have a bowl in front of you, then grab a bowl. If you have a bowl to put on the table, then put it on the table. If there is no cereal in your bowl, then put cereal in the bowl... by now I'm sure you get the gist.

    3. Repetition: Repetition tells the program to do something again and again as needed (or specified by you, the programmer). At the end you can add a selection, if hungry repeat. You already have a bowl, so the program continues to the next step. The bowl is filled (because you have only taken one bite), you continue until you are either no longer hungry or the bowl is empty, in which case the bowl would refill and you would eat until no longer hungry.

    Anything else you want to do can be done by placing one or more of these within themselves (i.e. nesting statements) but every programming element is a composition of one or more of these three.

    The examples given are not necessarily complete, there are practically an infinite number of steps that could be inserted (breathing between bites, wait time between bites, chewing, swallowing, etc. etc. etc.), but you should have a general understanding of structured programming.

    Tuesday, August 31, 2010

    An introduction to Computer Program Design

    The computer program design life cycle is simple, yet probably not something one would think of when first learning programming. Remember, major programming is done in teams of people working to create a product for an end user.

    1. Understand:
       -You must understand what is required of you, where the program is going and what your part in all of this is.

    2. Plan:
       -Write it down! Whether you use flowcharts or psuedocode you need to have a plan before you start programming.

    3. Code:
       -This is where most people want to start, but it is important to follow through with the first steps. This is true in more than just programming. Planning will save you headaches here!

    4. Compile:
       - Here is where you use a compiler to translate your code to machine language. If you have followed proper programming protocol (syntax) you now have a working computer program!

    5. Test:
       - You thought you were done there??? Not quite yet! Now it's time to test the product, fix any bugs, and if necessary go back through the previous steps until you have a workable bug free (to the greatest extent possible, all sizable programs will have bugs) program.
     
    6. Launch:
       - Your program finally gets an audience. Months of staring at a screen and 4 cases of Red Bull later and you have the satisfaction of watching your program in action. Ahhh yesss....

    7. Maintain:
       - If only that were it. Many customers will want support, updates will have to be put out as new bugs are found. This step lasts as long as there is a reasonable need and as long as the program's design is still reasonably usable. As new technology emerges your program may (will) become obsolete and need to be brought into the new generation. And the cycle begins anew...