Pseudo code help?

For my assignment i have to produce Pseudo Code for the different programs that i have done in C#. I have no real idea on how to start Pseudo code as i have no real knowledge or experience of using it.

If anybody could give me any tips on Pseudo code that would be appreciated.

Comments

  • Yah psuedo code is just like english.

    As you know comments are started of by // and they end when you go to next line

    heres an example

    //begin

    //This bunch of code initializes integer to 0

    int a=0;

    //end

    It is just a bunch of comments in the code that tell you what to do in english before you actualy start coding.

    Tips:

    //Keep your code and psuedo code organized-

    For instance, space out your code in sections and use the psuedocode to explain the section of code.

    //Write your Psuedocode on the top of the section of code.-

    just like how im doing for your tips.

    //Eplain anything that my be confusing to the one reading your

    // code-

    The only reason you are doing this is so that your reader will know exactly whats going on in your code as they read it. It gives them a english alternative. Of course psuedocode really is usually only used for you and is written before you program and you write in english how to work your prog.

    //Lastly, comment on where your loops, classes, main, etc. end.

  • Pseudocode is a concise unambiguous way of describing what a computer program or algorithm will do. Each line of pseudocode may map onto one or more lines of code (or even just one part of a line) but should only do one thing.

    E.g. The pseudo code to take two user inputted values (length and height) and calculate from these the area and perimeter of the resulting rectangle, might look like this:

    Input length

    Input height

    Area = length x height

    Perimeter = length + length + height + height

    Output Area

    Output Perimeter

    Usually you write pseudocode before coding a solution but writing it afterwards should be pretty straight forward. Go though the code and think about the intention of each line. Avoid using language-specific syntax e.g. sqrt(a) but instead use natural language e.g. calculate the square root of the value in a. To call functions I would suggest something like the following...

    Pass the value in a to the function "doMagic" and store the answer in b.

    Hope that helps :)

Sign In or Register to comment.