Thread: Pseudocode - I'm confused

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    104

    Pseudocode - I'm confused

    Basically the teacher wants us to write pseudocode for our whole program ( the shutter , aperture and ISO one ) . The thing is , I have no idea how to do half of the things in pseudocode . For example strcomp() , strtol() ? Also how comprehensive does it need to be ? Let me give you an example :

    Code:
        fgets(guess ,10, stdin);
        p = strchr(guess, '\n'); 
                             if ( p ) 
         			*p = 0;
    The p = strchr(guess, '\n') has no real importance in the actual code , apart from to remove the effect of the new line character , so that fgets() works fine .
    Would I have to include that in the pseudocode ? Thanks a lot for your help

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    104
    Here is some code that I just came up with :
    Code:
    Algorithm_Test
    String Exposure
    Output "Please enter an exposure time"
    Input Exposure
    Output "Please enter an aperture value"
    aperture array={"f1.2","f1.4","f1.8","f2.0","f2.8","f4.0","f5.0","f8.0","f11.0","f16.0","f22.0","f32.0","f2","f4","f5","f8","f11","f22","f32"}
    string guess
    input guess 
    Integer i
    For (i=0;i<19;i++)
    {
    compare strings
    If guess=aperture 
    then
    {
    output "This aperture is on the list of possible values !"
    output " The values you have entered are"
    output "Aperture value is",aperture,"Exposure time is",exposure
    }
    else
    {
    output " You have entered an invalid aperture "
    End Algorithm_Test
    }
    Is this valid pseudocode ?Please comment , I have no idea if I'm doing this right
    Last edited by ICool; 09-15-2007 at 11:30 PM.

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Theres no such thing as vailid pseudo code http://en.wikipedia.org/wiki/Pseudocode

    Quote Originally Posted by http://en.wikipedia.org/wiki/Pseudocode
    As the name suggests, pseudocode generally does not actually obey the syntax rules of any particular language; there is no systematic standard form, although any particular writer will generally borrow the appearance of a particular language.
    Also indent your code, regardless. It's very hard to read.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Would I have to include that in the pseudocode ?
    One way to think about it would be that the pseudo code would become the block comments in the code. So it tells you a little bit more of "why" you're doing something rather than just merely restating "how" you're doing some things.

    Eg where you had
    Output "Please enter an exposure time"
    Input Exposure

    I would just say
    Prompt for and read exposure value

    Which would turn into code as (for example)
    Code:
        /* Prompt for and read exposure value */
        fgets( buff, sizeof buff, stdin );
        sscanf( buff, "%f", &exposure );
    The idea being you could just paste your pseudo code into an empty source file, go through it putting /**/ comments around each line, then start filling in the details with actual code.

    The for loop I would replace with a pseudo code line of say "search predefined apertures for a match", then an indented block of pseudo code to describe the inner detail of "matching apertures".

    > (newline removal... ) Would I have to include that in the pseudocode ?
    No, that would be too detailed IMO.
    You might mention it once as an additional comment the first time you used it, but that's about all.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Sep 2007
    Posts
    104
    Quote Originally Posted by Salem View Post
    > Would I have to include that in the pseudocode ?
    One way to think about it would be that the pseudo code would become the block comments in the code. So it tells you a little bit more of "why" you're doing something rather than just merely restating "how" you're doing some things.

    Eg where you had
    Output "Please enter an exposure time"
    Input Exposure

    I would just say
    Prompt for and read exposure value

    Which would turn into code as (for example)
    Code:
        /* Prompt for and read exposure value */
        fgets( buff, sizeof buff, stdin );
        sscanf( buff, "%f", &exposure );
    The idea being you could just paste your pseudo code into an empty source file, go through it putting /**/ comments around each line, then start filling in the details with actual code.

    The for loop I would replace with a pseudo code line of say "search predefined apertures for a match", then an indented block of pseudo code to describe the inner detail of "matching apertures".

    > (newline removal... ) Would I have to include that in the pseudocode ?
    No, that would be too detailed IMO.
    You might mention it once as an additional comment the first time you used it, but that's about all.
    Interesting , thanks Salem . I agree wiith you , to me pseudocode should be like more descriptive comments , however it seems he wants us to use C style pseudocode , like what I did above. I have just sent him an email to clarify this . Do you know if the pseudocode needs to have comments ? It seems unnecessary , but our tutor mentioned that they are used ( he is a 2nd year student )

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    I guess you're just going to have to go with your locally defined rules then.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New to C++ and confused by boolean and ifs and else
    By jconner in forum C++ Programming
    Replies: 10
    Last Post: 08-02-2006, 03:29 AM
  2. writing the pseudocode........functions
    By bajan in forum C++ Programming
    Replies: 3
    Last Post: 04-15-2005, 12:59 PM
  3. why wont this compile?!? :confused:
    By jdude in forum C++ Programming
    Replies: 5
    Last Post: 11-25-2004, 01:13 AM
  4. So Now Im getting confused?!?!?
    By zergdeath1 in forum C++ Programming
    Replies: 11
    Last Post: 03-06-2004, 05:41 PM
  5. confused.. in selecting my line of deapth
    By jawwadalam in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-04-2003, 01:21 PM