Jump to content

HELP Needed with pseudo code Java

- - - - -

  • Please log in to reply
8 replies to this topic

#1
Gman

Gman

    Learning Programmer

  • Members
  • PipPipPip
  • 49 posts
Hi All

As you may know by now i am new to java ( 1st year student ). Can some please help and explain pseudo code or tell me where i can find some tutorial so i can learn it... i had a look at a few pass paper exam and found this question on it. At this moment i would not know how to do it never mine start it. :confused:

Hopefully the answers will help someone else in the near future!!!!

Quote

Imagine that you have been asked to write a program that will
input a noon day temperature for each day in each month of the
year and output the average temperature for each month and the
average of the year. Develop a pseudo code solution to this problem.
You should show the stages of the development process and state
any assumptions that you make.

Thanks in Advance

Gman

Edited by Gman, 09 November 2011 - 08:04 AM.
Spelling in title.


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Things to think about:
1) how many readings will you need to make?
2) how do you need to group the readings?
3) think about doing this by hand. What would you do to perform this with pencil and paper, in such a way that you could hand the results to someone else?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
There is no such thing as a formal specification on pseudocode. Pseudocode is merely well-formed non-ambiguous English statements describing exactly which steps your algorithm will follow. There's nothing to learn in order to write pseudocode.

EDIT:
Here's an example of pseudocode:


Routine: Buy Milk.

Fetch Wallet.

Fetch Car Keys.

Look Outside.

If it looks like rain:

    Fetch Umbrella.

End if.

Go Outside.

If it is raining:

    Open Umbrella.

End If.

Get in Car.

Drive to Store.

Enter Store.

Fetch Milk.

Go to Checkout Station.

Pay Cashier.

Leave Store.

Get in Car.

Drive Home.

... (continued)


You can be as detailed as you like, and as thorough as you like.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#4
Gman

Gman

    Learning Programmer

  • Members
  • PipPipPip
  • 49 posts
Thanks i will give that a go, so just write out each step by step.

WingedPanther said:

Things to think about:
1) how many readings will you need to make?
2) how do you need to group the readings?
3) think about doing this by hand. What would you do to perform this with pencil and paper, in such a way that you could hand the results to someone else?


---------- Post added at 12:51 PM ---------- Previous post was at 12:47 PM ----------

gregwarner said:

There is no such thing as a formal specification on pseudocode. Pseudocode is merely well-formed non-ambiguous English statements describing exactly which steps your algorithm will follow. There's nothing to learn in order to write pseudocode.

EDIT:
Here's an example of pseudocode:


Routine: Buy Milk.

Fetch Wallet.

Fetch Car Keys.

Look Outside.

If it looks like rain:

    Fetch Umbrella.

End if.

Go Outside.

If it is raining:

    Open Umbrella.

End If.

Get in Car.

Drive to Store.

Enter Store.

Fetch Milk.

Go to Checkout Station.

Pay Cashier.

Leave Store.

Get in Car.

Drive Home.

... (continued)


You can be as detailed as you like, and as thorough as you like.

Thanks for that gregwarner, i defo have a bit more knowledge of Pseudocode.

Gman:)

#5
Gman

Gman

    Learning Programmer

  • Members
  • PipPipPip
  • 49 posts

WingedPanther said:

Things to think about:
1) how many readings will you need to make?
2) how do you need to group the readings?
3) think about doing this by hand. What would you do to perform this with pencil and paper, in such a way that you could hand the results to someone else?

Ok i tried to tackle it and no joy , i think i need 3 readings temp, day, month, after that i dont know what way to go about it.

Help :confused::confused:

#6
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
Hint: Decide on how you are going to store the data. Take note of the amount of data you need to store.
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:

#7
Gman

Gman

    Learning Programmer

  • Members
  • PipPipPip
  • 49 posts
here is what i have come up with, would you be able to do the same program by reading this.:confused:

get Temperature
store temperature for each day in each month
calculate how many days in each month
calculate average temperature for each month
find how many months in year and
calculate average temperature for each year

Display average temperature for each month and the average of the year.



Gman

#8
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
You are probably missing some of the mechanics. Like, get Temperature; that suggest a method to get all the different temperature values. Then you say store temperature. But are those two lines working together? Mechanics and details of the pseudo code depend on interpretation. Looking at the problem, and the code I could get enough to produce language specific code to solve the problem, others may not. To be safe you should include a bit more detail in terms of which lines goes before the other. Also I think it is safe to say a year is 12 months. A good pseudo code should leave a clear picture of what needs to be done and in what order it should be done in the mind of the reader, without getting into to much technical stuff.
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:

#9
Gman

Gman

    Learning Programmer

  • Members
  • PipPipPip
  • 49 posts

fread said:

You are probably missing some of the mechanics. Like, get Temperature; that suggest a method to get all the different temperature values. Then you say store temperature. But are those two lines working together? Mechanics and details of the pseudo code depend on interpretation. Looking at the problem, and the code I could get enough to produce language specific code to solve the problem, others may not. To be safe you should include a bit more detail in terms of which lines goes before the other. Also I think it is safe to say a year is 12 months. A good pseudo code should leave a clear picture of what needs to be done and in what order it should be done in the mind of the reader, without getting into to much technical stuff.

Thanks fread i will add a bit more them and post later, just need to stop thinking about java when writing pseudo code and put it in english.:confused:

gman




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users