Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Pseudocode problems - Help!

    Hi,

    I am not sure if there is a good section to post this but I will anyway!

    I am looking to create pseudocode to calculate the mean, mode, median, standard deviation and mean deviation of random integers which are generated at random.

    Could anyone maybe step me in the right direction as to how to set out this pseudocode as I am inexperienced in this form.

    This might be totally the wrong forum, if anyone has any good forums to post this in, please reply back,

    Cheers

  • #2
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Psuedo code form is easy, just write it like it should be done!
    How/When do you want to do these mathematical operations? eg; after user decides, or do all of them at once and ouput?
    Omnis mico antequam dominus Spookster!

  • #3
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yep pseudocode is english, or any other language you might speak for that matter!

    Here's an example of mean:
    Code:
    mean (list of numbers : list)
     sum = sum of list
     num = number of items in list
    
     return sum / num
    And that's it. At least that's the way I would write it..

    Hope that helps,
    Sadiq.

  • #4
    Regular Coder
    Join Date
    Feb 2004
    Location
    WA
    Posts
    213
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool

    The beauty of pseudo code is that there are no syntactic limitations to it. If you can express some task in words, you can write pseudo code for it.

    It follows that the same idea can be expressed in different words

    for example, you can easily replace parts of the code listing above to be more detailed.
    Code:
    mean (list of numbers)
    1. sum<-0
    2. num<-0
    3. for each number in the input
            sum <- sum + number
            num <- num + 1
    4. mean <- sum/num
    5. return mean
    As you can see the amount of detail can vary a lot.

    These are the factors I consider when writing pseudo code
    - The target audience. This almost always dictates the amount of detail that is required. For example, for presenting a piece of pseudo code to a financial group, you can often omit the implementation details of several financial details. you can say things like the following without having to explain the exact procedure to compute an expression.
    Code:
    a <- compound interest on a principal of X with interest Y for a term of Z
    on the other hand, if you are presenting this to a scientific community, you might want to elaborate on how it is computed for the extra insight it might provide.

    - The stage of the project. This also dictates the detail for a certain extent.
    For example, when you are coming up with design prototypes, its often helpful to ignore a lot of details. a rough sketch will do. On the other hand, if you are doing maintenance work and are trying to replace a well used module, you might want to include every small detail you can find just to make sure that every dependency on other modules is shown and the interactions carefully scrutinized.

    - The purpose of the project. This is mostly academic in nature. If you are preparing material explaining how something works to students in their early stages of learning, you would want every important detail, but at the same time you would want to skip every thing that might confuse them. A lot of datastructures text books achieve this by building up on previously worked out pseudo code in small increments to facilitate faster learning and to avoid confusion.

    Hmm.. looks like I made my longest post with this. Hopefully you guys find it useful.
    Nobody is Perfect. I am Nobody.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •