Psuedo Code Problem!!! Urgent!!!
Collapse
X
-
Yeah, I don't know anything about what you're talking about, but I was wondering about your name. Pharcyde as in the group? I just listened to their remix of Doin' Time, it rocks.Comment
-
arrays
can you put the values into an array?
do you have icq? im 19631307, if you do
i know....read it left to right, keep concatenating it into a string...(the highest order digit will be put in first)
then process the string first 0/1 gets the value of 2 to the 0th power (= 1), second 0/1 gets 2 to the 1st power (=2), third 0/1 gets 2 to the 2nd power (=4), just accumulate it till you reach the end of the string
will that work for ya?
-alfComment
-
a.
1.
(turn the date into YYYYMMDD format. YYYY carries most weight, so it is put in front. In this way you can directly compare it to other dates using < > =, etc.)
todayDate = yearToday * 1000 + (monthToday) * 100 + dayToday
otherDate = yearOther * 1000 + (monthOther) * 100 + dayOther
if todayDate == otherDate
present
if todayDate > otherDate
past
else
future
2.
(Easier to understand, but not as efficient and harder to code)
if yearToday > yearOther
past
else if yearToday < yearOther
future
else
if monthToday > monthOther...
pattern continues...
b.
main
repeat until end of file
read letter
if y read in
yFoundProcedure
end if
end repeat
end main
yFoundProcedure
read letter
if end of file, quit
else
if y read in
yFoundProcedure (call itself, takes the 'yyy' case into consideration)
else if . or , or (space) read in
increment wordsEndInY
end if
end yFoundProcedure
c. (are you sure it's left-most digit? or right?)
The left-most digits is way harder... I'm working on it now...
Comment
-
Re: arrays
A string is an array of characters. If he can't use an array, he can't use a string.Originally posted by alf
can you put the values into an array?
i know....read it left to right, keep concatenating it into a string...
Going right to left there is a super simple formula... left to right... a pain. I can't see why your teacher would ask you to do it that way...
Comment
-
i think i got it...miscue, whatcha think?
alright...
i wont do the pseudo code for you but here is the theory
for every new digit, you will add 1 or 0 (since it is the least significant bit)...before you do that, you have to shift the others left...do to this, just multiply by 2
(do some examples)
111=7
promote 111 to 1110 and that is 14, then add 1 or 0
11011 = 27
promote (shift left) to 110110 and that is 54, then add 0 or 1
will that work?Comment
-
c. Here goes...
main
getBinary
convertToDec
end main
begin getBinary
digit=0
accumulator=0
repeat until end
accumulator = accumulator * 10 // move digit over
read digit
if not end
accumulator = accumulator + digit // tack on next dig
end if
digit = digit+1
end repeat
end getBinary
begin convertToDec
currExp = 0
decimalAnswer = 0
repeat until digit = 0
decimalAnswer = decimalAnswer + (accumulator modulo 10) * 2^(currExp)
digit = digit - 1
currExp = currExp + 1
accumulator = accumulator div 10
end repeat
end convertToDec
I did not double check this for three reasons.... It's probably right... close enough for pseudocode... and it does you no good if I just give you the answer and you don't understand it. You need to go through it and see how it works. If you catch an error, great.Last edited by Miscue; 09-18-2001, 10:10 PM.
Comment


Comment