6 Replies - 23408 Views - Last Post: 15 October 2011 - 08:14 PM Rate Topic: -----

#1 KBoogle  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 98
  • Joined: 15-April 10

Writing pseudo-code tips?

Posted 15 October 2011 - 10:46 AM

Hey there,

I've just started learning C++ recently and learned about pseudo-code, but the book I'm using doesn't go into much detail how to effectively use pseudo-code to help write programs. I was wondering if there were any resources available for that, or some tips?

Thanks for any help.
Is This A Good Question/Topic? 0
  • +

Replies To: Writing pseudo-code tips?

#2 AdamSpeight2008  Icon User is online

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: Writing pseudo-code tips?

Posted 15 October 2011 - 11:30 AM

PseudoCode is not more than Written English Step.

Write out the step to do the Washing Up.

1. Turn Hot tap on
2. Squirt Washing Up liquid into bowl.
3. When bowl is fill of water( and soap bubble), turn off hot tap.
4. Take item of dirty kitchenware,
5. Put in bowl of water.
6. Clean
7. Put item on drainer to dry.
8. If there are more items to be cleaned, goto step 4
9. Empty and clean bowl.
10. Wash up done.
Was This Post Helpful? 2
  • +
  • -

#3 KBoogle  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 98
  • Joined: 15-April 10

Re: Writing pseudo-code tips?

Posted 15 October 2011 - 12:31 PM

Yeah, that is about the same thing that the book mentioned, but I'm wondering if there's more to pseudo-code. I mean, how detailed do I write out the steps? At what point does it become too detailed? And if I'm not writing out enough details is it going to be too abstract when I start rewriting it as actual code?

Hm, I guess what I'm really asking for is some examples I can refer to. Not washing dishes or something like that, but for an actual program... if that's possible to share.
Was This Post Helpful? 0
  • +
  • -

#4 Bench  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 857
  • View blog
  • Posts: 2,343
  • Joined: 20-August 07

Re: Writing pseudo-code tips?

Posted 15 October 2011 - 12:57 PM

View PostKBoogle, on 15 October 2011 - 08:31 PM, said:

Yeah, that is about the same thing that the book mentioned, but I'm wondering if there's more to pseudo-code. I mean, how detailed do I write out the steps? At what point does it become too detailed? And if I'm not writing out enough details is it going to be too abstract when I start rewriting it as actual code?

Hm, I guess what I'm really asking for is some examples I can refer to. Not washing dishes or something like that, but for an actual program... if that's possible to share.
No, there really isn't anything more to psuedocode; it's not a formal language, it's just a way to express your ideas to human readers - the good thing about it is that you can make it up in any way that you like. Usually programmers write psuedocode with a "dialect" based upon the programming language that they're most familiar with; but all turing-complete programming languages basically come down to 3 different basic constructs: Sequence, Selection, Repetition; therefore at the most basic level, that is all you need to worry about.
e.g. With selection you might use words such as "Select case" or "If", and for repetition you'll probably use words such as "Repeat", "While", "Until", "For Each", etc. Many people also like to "END" their pseudocode-blocks too with "End If" or "End Repeat", but you don't have to do that.

Of course, people will sometimes add other things as needed such as calling functions, objects, etc, and this is usually where programming dialects come into play, e.g.using language such as "DO SomeProcedure(arg1, arg2)" resembling the way that a lot of programming languages use functions/procedures/subroutines/methods.

People generally don't write pseudocode for entire programs; that's not what its for. It's usually used to describe specific procedures or algorithms within a program (for example, sorting a set of data). Remember that the reason behind pseudocode is to be able to express ideas and concepts to a human reader without all of the additional "noise" which you need for a compiler to understand it (e.g. you don't need to declare variables, worry about various symbols, can omit error handling, etc) - therefore you need to use your own judgement when deciding whether or not your pseudocode is sufficiently detailed.


You can find loads of examples and also pseudocode standards on google, so that would be a good place to start.


edit: This page seems to have a pretty good psuedocode standard with some decent examples http://users.csc.cal...WE/pdl_std.html

This post has been edited by Bench: 15 October 2011 - 01:09 PM

Was This Post Helpful? 3
  • +
  • -

#5 KBoogle  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 98
  • Joined: 15-April 10

Re: Writing pseudo-code tips?

Posted 15 October 2011 - 01:18 PM

Thank you, that was very helpful :)
Was This Post Helpful? 0
  • +
  • -

#6 Gungnir  Icon User is offline

  • Your Imaginary Friend

Reputation: 152
  • View blog
  • Posts: 527
  • Joined: 21-May 11

Re: Writing pseudo-code tips?

Posted 15 October 2011 - 08:06 PM

Pseudo-code can't be compiled, it won't make a program, it consists solely of a spoken language interpretation of the logic within your program.

It's so that other programmers can follow your logical train of thought throughout your program. It's an alternative to a flow-chart that focuses more on the actual structure of the code than the series of events. Most programmers that intend their code to be read by other programmers will use //comments containing pseudo-code so that their logic can be read by others. However in the early stages of a group project it can be necessary to write pseudo-code.

I hope that makes sense, but just incase, I'll write a few examples.

Pseudo-code
for(integer that equals zero; whilst the integer is less than 5; shift the integer positively)
    count to 5




Commented Pseudo-code
class DoorOBJ //Door Objects
{
    bool locked; //Can be either locked or unlocked
    public:
        DoorObj(bool _locked, int x, int y); //Object initializer
        bool Open(); //Function to check whether or not it's locked
};
bool DoorOBJ::Open()
{
    std::string _Action;
    std::cout << "\nThis door is locked, would you like to open it?"; //Output to introduce the situation
    for(i(0); i < 5; i++) //Give the user 5 tries
    {
        std::cout << "\n >> "; //Obvious prompt for input is obvious.
        std::cin >> _Action; //Get user input, funnel it into "_Action"
        if(_Action == "Yes") //If the user input is equal to "Yes"
        {
            locked = false; //Set the door state to unlocked.
            return true; //Door.Open() returns true;
        }
        else if(_Action == "No") //If the user input is equal to "No"
        {
            locked = true; //Set the door state to locked.
            return false; //Door.Open() returns false;
        }
        else
        {
            std::cout << "\nNot a valid ('Yes'/'No') answer"; //Output to the user that their answer wasn't valid and loop again.
        }
    }
}

//etc, you get the idea


This post has been edited by Gungnir: 15 October 2011 - 08:08 PM

Was This Post Helpful? 1
  • +
  • -

#7 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5406
  • View blog
  • Posts: 27,405
  • Joined: 10-May 07

Re: Writing pseudo-code tips?

Posted 15 October 2011 - 08:14 PM

I've always considered pseudo-code to be the verbal flow chart.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1