04-23-2004, 03:49 PM
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,
04-23-2004, 05:44 PM
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?
04-23-2004, 06:26 PM
Yep pseudocode is english, or any other language you might speak for that matter!
Here's an example of mean:
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,
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.
mean (list of numbers)
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.
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.