Posted: Mon Oct 24, 2011 9:05 am Post subject: how to write those funtions?
Write these functions
min (a,b,c: int) :int
% takes in 3 integers and returns the smallest
maxletter (s: string) :char
% takes in a string and returns the letter with the highest letter of the alphabet
arithmetic_series (a,d,n : int) : int
% takes in the first term(a), the common difference(d) and the number of terms(n) for an arithmetic series and outputs the total
P/S: help me.... im in grade 11 and i hv to write those in turing
Sponsor Sponsor
Insectoid
Posted: Mon Oct 24, 2011 9:51 am Post subject: RE:how to write those funtions?
Exactly what are you having trouble with? Have you tried solving these yourself?
Beastinonyou
Posted: Mon Oct 24, 2011 2:44 pm Post subject: Re: how to write those funtions?
Before anybody is going to help you solve these problems, You should post some of the Code you already have, and we can help figure out why it doesn't work, and how you can accomplish a certain task.
You need to put in some effort yourself, before anybody else is going to give any.
oanh_goose wrote:
min (a,b,c: int) :int
% takes in 3 integers and returns the smallest
That should be fairly straight-forward. You Use a repetitive structure to go through and compare the numbers, and keep track of the smallest. Very simple.
oanh_goose wrote:
maxletter (s: string) :char
% takes in a string and returns the letter with the highest letter of the alphabet
What exactly do you wish to happen? "Returns the letter with the highest letter of the alphabet."? The way it's worded is a bit confusing. And what is defined as the "Highest" letter of the Alphabet? Do you mean, from Start to Finish, all 26 Letters of the Alphabet, 'A' is the highest and 'Z' is the lowest, or is it the ASCII Values for the alphabet?
oanh_goose wrote:
arithmetic_series (a,d,n : int) : int
% takes in the first term(a), the common difference(d) and the number of terms(n) for an arithmetic series and outputs the total
What exactly do you want to use this for? and what is the Total defined by? It takes (a), common difference (d) = what exactly?, and what do you do to get the Total?
tg851
Posted: Tue Oct 25, 2011 10:36 am Post subject: Re: how to write those funtions?
here,you can have the code for the first one. this can be easily tweaked to make the second one.
be thankful I'm in a good mood or you would have gotten the code in scrambled form,instead it's just undocumented.figure it out for yourself
Turing:
var a,b,c,d,e,f :int
get a
get b
get c
d:=0
e:=0
f:=0
for:1..4
if a>b then
d:=d+1 endif
if a>c then
d:=d+1 endif
if b>a then
e:=e+1 endif
if b>c then
e:=e+1 endif
if c>a then
f:=f+1 endif
if c>b then
f:=f+1 endif endfor
for:1..5
if d=0thenlocate(4,1)put a, " is the lowest" endif
if e=0thenlocate(4,1)put b," is the lowest" endif
if f=0thenlocate(4,1)put c," is the lowest" endif locate(1,60) put"coded by tomas gaines" endfor
Insectoid
Posted: Tue Oct 25, 2011 10:40 am Post subject: RE:how to write those funtions?
tg851, here at compsci.ca we don't like giving full answers for assignments. I'm not a mod, but we'd appreciate it if you'd refrain in future.
Tony
Posted: Tue Oct 25, 2011 11:00 am Post subject: RE:how to write those funtions?
Posted: Tue Oct 25, 2011 11:04 am Post subject: Re: RE:how to write those funtions?
Tony @ Tue Oct 25, 2011 11:00 am wrote:
Not sure if serious...
My bad; I didn't actually look at the code.
Nick
Posted: Tue Oct 25, 2011 11:05 am Post subject: RE:how to write those funtions?
@tg851: either you're a bad programmer or a troll... either way lololol
Sponsor Sponsor
QED
Posted: Tue Oct 25, 2011 11:06 am Post subject: RE:how to write those funtions?
Flag variables are a bad idea. They're confusing, difficult to maintain, and unnecessary. You can almost always avoid them entirely by taking a little bit of time to re-design your procedure.
Secondly, the less-than operator forms a transitive relation. That is,
if min(a,b) = b
and min(b,c) = c
then min(a,c) = c is a certainty
How can you take advantage of this property to succinctly produce a 3-argument min() function? Think about it on paper first, then commit your solution to code.
Beastinonyou
Posted: Tue Oct 25, 2011 2:29 pm Post subject: Re: how to write those funtions?
tg851 @ Tue Oct 25, 2011 10:36 am wrote:
be thankful I'm in a good mood or you would have gotten the code in scrambled form,instead it's just undocumented.figure it out for yourself
Turing:
for:1..5 if d=0thenlocate(4,1)put a, " is the lowest" endif
if e=0thenlocate(4,1)put b," is the lowest" endif
if f=0thenlocate(4,1)put c," is the lowest" endif locate(1,60) put"coded by tomas gaines" endfor
Holy Eggs!... You hear that people? That's code in Non-Scrambled form.... What would that be then? Poached, or Hard-Boiled? because it's definitely not Sunny-side or Over-Easy.
That entire code sequence was like having someone tell me the easiest way to Draw a Square, was to Draw a Diamond with in-equivalent sides, then look at it sideways, then fix those sides.
I'm glad our brain's aren't programmed using that logic. =P
The day one is, someone call George A. Romero, we'll have a real-life zombie at hand.
crossley7
Posted: Tue Oct 25, 2011 4:47 pm Post subject: RE:how to write those funtions?
Ok, that code made me sick. If you are going to post help code, don't code in the ugliest, least efficient way possible. (I don't care about comments as it is something I have never learned how to do properly at the expense of many hours of debugging)
mirhagk
Posted: Tue Oct 25, 2011 5:11 pm Post subject: RE:how to write those funtions?
*shudder* I seriously hope that it was a troll, and it must be.
Tony
Posted: Tue Oct 25, 2011 5:22 pm Post subject: Re: RE:how to write those funtions?
crossley7 @ Tue Oct 25, 2011 4:47 pm wrote:
least efficient way possible
he could have looped through it a few more times, "just to make sure"
Posted: Tue Oct 25, 2011 6:35 pm Post subject: Re: how to write those funtions?
its suppose to be inefficient,that way if the tries blatantly ripping it off for a project he doesnt profit from it.It gives an idea of how to do it,but not the BEST way to do it.thats up to him to figure out
and imaen by scrmbld is in no working order whatsoever(its there but every part is out of working order,something my teacher LOVE to do)
mirhagk
Posted: Tue Oct 25, 2011 7:50 pm Post subject: RE:how to write those funtions?
Okay good, I'm glad. Actually this gave me an idea for the course in school, give students fuddled code, and tell them to fix it.