• Congratulations to the Class of 2024 on your results!
    Let us know how you went here
    Got a question about your uni preferences? Ask us here

need help with Pseudocode (1 Viewer)

jamickey

New Member
Joined
Sep 23, 2009
Messages
18
Gender
Male
HSC
2008
hey. who here knows how to use Pseudocode? i got an assessment task and i dont no how to start it. can anyone give me some ideas and some tips on how i can start this because i have no clue.ive attached a copy of the assignment for you. thanks :)
 

Azamakumar

bannèd
Joined
Mar 30, 2006
Messages
2,748
Location
the gun show
Gender
Male
HSC
2007
lol omg
you're meant to write a rough outline of what you want the code to do
it's a planning stage, ie you don't actually need to write the code out

ie
Code:
int main{
ask user to type in their name

save users name to string x

tell em they're a faggot
as opposed to

Code:
int main{
char name;
printf("enter your name: ");
scanf("%s", &name);
printf("%s is a faggot", name);

return 0;
 

LordPc

Active Member
Joined
May 17, 2007
Messages
1,370
Location
Western Sydney
Gender
Male
HSC
2008
to put what Azamakumar said into a form that is a little more computer-sciencey, pseudocode is the algorithm that you will use to complete a task. ideally it should read a bit like english and understandable to your average joe. another way to think about it is this, if you were to do the task by hand, what steps would you go through?

if you want some examples they are all over wikipedia, like here is the pseudocode for bubble sort.
Code:
 [B]procedure[/B] bubbleSort( A [B]:[/B] list of sortable items ) [B]defined as:[/B]
  [B]do[/B]
    swapped := false
    [B]for each[/B] i [B]in[/B] 0 [B]to[/B] length(A) - 2 [B]inclusive do:[/B]
      [B]if[/B] A[i] > A[i+1] [B]then[/B]
        swap( A[i], A[i+1] )
        swapped := true
      [B]end if[/B]
    [B]end for[/B]
  [B]while[/B] swapped
[B]end procedure[/B]
the reason they use pseudocode on wikipedia is that its not specific to any particular programming language, so it is understandable to everyone. (if you want proof, compare a haskell implementation of quicksort to a C implementation)
 
Last edited:

Ben1220

Member
Joined
Jun 3, 2009
Messages
147
Gender
Male
HSC
2008
What LordPc said is completely true. There's a lot of variance between how different people write psuedocode, and it doesn't really matter what exact syntax you choose, so long as it is simple enough, doesn't go into any implementation details, doesn't contain any error checking ect... Psuedocode is never actually compiled and run on a computer, so you don't need to learn "how to write it" Take a look at a few books on algorithms if you want to see more examples of how psuedocode is generally used.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top