Navbar

  Elite Fitness Bodybuilding, Anabolics, Diet, Life Extension, Wellness, Supplements, and Training Boards
  Chat & Conversation
  Anyone know how to use TURBO PASCAL?

Post New Topic  
profile | register | preferences | faq | search

Author Topic:   Anyone know how to use TURBO PASCAL?
aky

Pro Bodybuilder

Posts: 501
From:Canada, BC
Registered: Sep 2000

posted January 28, 2001 08:39 PM

Staff Use Only: IP: Logged


if you do please email me

[email protected]

or reply to this message, thanks!

------------------


Click Here to See the Profile for aky   Click Here to Email aky     Edit/Delete Message    UIN: 45428686   Reply w/Quote
HappyScrappy

Pro Bodybuilder

Posts: 367
From:Boston
Registered: Dec 2000

posted January 28, 2001 09:14 PM

Staff Use Only: IP: Logged


what do you need to do?

------------------
The Downside Of Being Better Than Everyone Else Is That People Tend To Assume You're Pretentious.


Click Here to See the Profile for HappyScrappy   Click Here to Email HappyScrappy     Edit/Delete Message      Reply w/Quote
aky

Pro Bodybuilder

Posts: 501
From:Canada, BC
Registered: Sep 2000

posted January 28, 2001 10:30 PM

Staff Use Only: IP: Logged


i need to write a program that asks the user to input in a number and the computer should display if the number is a prime numbr (a number that can only be divided by 1 or itself)

aky

------------------


Click Here to See the Profile for aky   Click Here to Email aky     Edit/Delete Message    UIN: 45428686   Reply w/Quote
HappyScrappy

Pro Bodybuilder

Posts: 367
From:Boston
Registered: Dec 2000

posted January 28, 2001 11:26 PM

Staff Use Only: IP: Logged


I could write out the whole program for you, but then you wouldn't have learned a thing.

So what part of what you just said don't you understand how to do - and is it b/c you don't get the math, the idea, or you don't know how to do it in TP?

If you give me the specifics of what you need, but not the whole problem, then I can tell you how to do that.

Have you written any code yet (prior to this - or also have you started writing code for this problem)?
Even pseudocode?

------------------
The Downside Of Being Better Than Everyone Else Is That People Tend To Assume You're Pretentious.


Click Here to See the Profile for HappyScrappy   Click Here to Email HappyScrappy     Edit/Delete Message      Reply w/Quote
aky

Pro Bodybuilder

Posts: 501
From:Canada, BC
Registered: Sep 2000

posted January 28, 2001 11:53 PM

Staff Use Only: IP: Logged


i've been in this class for 3 weeks and before this class i was in a class called Programming concepts, and yes i've written pseudocode.

Ok i'll be more specific.. my question is i dont know how to use the function. I am suppose to use a function to determine if a # is prime or not. I just need help getting started... a kick start!

aky

------------------


Click Here to See the Profile for aky   Click Here to Email aky     Edit/Delete Message    UIN: 45428686   Reply w/Quote
HappyScrappy

Pro Bodybuilder

Posts: 367
From:Boston
Registered: Dec 2000

posted January 29, 2001 12:06 AM

Staff Use Only: IP: Logged


So are you saying the teacher provides you with a function that will report if it is prime or not?
If that is the case, then you are practically done.

Here is thought process I would go through on writing such a thing:

I need to talk to the user of this program, I need output text to the screen that will let them know they need to perform an action in order for this to work. I then need to take ina value, and then store it in a variable. I then need to take this stored value and look at it and do a calculation on it. Once I've determined if this is prime or not, then I need to, one last time, write to the screen and let the user know to which side the outcome resulted in - prime or not.
so:
1) learn how to write to the screen in TP. in javascript you might use the write(x) function, where x is the string you want output to wherever you are dumping it (usually to the document object or a div) - in TP there is an equivalent.
2) then figure out how to take a value in. in C++, if I recall correctly, there was cin and cout - cout was anything you were writing to the screen, and cin were values you were pulling in.
3) dump that value into a variable.
4) pass that variable into your prime function and that would presumable return true or false.
5) then, based on what is returned, you will the again call the TP function that allows you to output text to the screen and let the user know the outcome.

do you have a textbook or manual for the class?

------------------
The Downside Of Being Better Than Everyone Else Is That People Tend To Assume You're Pretentious.


Click Here to See the Profile for HappyScrappy   Click Here to Email HappyScrappy     Edit/Delete Message      Reply w/Quote
aky

Pro Bodybuilder

Posts: 501
From:Canada, BC
Registered: Sep 2000

posted January 29, 2001 12:11 AM

Staff Use Only: IP: Logged


you have mail

they dont provide us with the function... they just tell us that we have to use one...

also i know how to do everything you mentioned except how to write the function and how to calculate if the number is prime or not.

aky

------------------


Click Here to See the Profile for aky   Click Here to Email aky     Edit/Delete Message    UIN: 45428686   Reply w/Quote
aky

Pro Bodybuilder

Posts: 501
From:Canada, BC
Registered: Sep 2000

posted January 29, 2001 01:32 AM

Staff Use Only: IP: Logged


bump

------------------


Click Here to See the Profile for aky   Click Here to Email aky     Edit/Delete Message    UIN: 45428686   Reply w/Quote
HappyScrappy

Pro Bodybuilder

Posts: 367
From:Boston
Registered: Dec 2000

posted January 29, 2001 08:37 AM

Staff Use Only: IP: Logged


I'll check my mail and get back to you.

------------------
The Downside Of Being Better Than Everyone Else Is That People Tend To Assume You're Pretentious.


Click Here to See the Profile for HappyScrappy   Click Here to Email HappyScrappy     Edit/Delete Message      Reply w/Quote
HappyScrappy

Pro Bodybuilder

Posts: 367
From:Boston
Registered: Dec 2000

posted January 29, 2001 09:00 AM

Staff Use Only: IP: Logged


quote:
Originally posted by aky:
you have mail

they dont provide us with the function... they just tell us that we have to use one...

also i know how to do everything you mentioned except how to write the function and how to calculate if the number is prime or not.


I checked my e-mail but something went wrong and hushmail wouldn't let me open the letter.

okay, well a function is just a chunk of code that doesn't get run unless you call it - and when you call it, you can pass it things, it will then do stuff, and it can then return suff back to you.

It has been awhile since I wrote anything in TP (it sucks), but I think it is called a procedure in TP - so look that up in your book and/or for the class.

pretty much you are going to have a funtion like so - with the working parts between
isPrime(i:interger);
end;

for the working parts you will want to make use of a built in math function called "mod" - modular arithmatic outputs the remainder of division. so if I said 4 mod 2 - that would output 0. if I said 7 mod 2 - that would output 1.
think this through and you can then do a loop and figure out the primes.
(hint: you are taking in an integer. loop through 1 all the way up to you integer and do a mod against it. if you ever get 0 returned, then you know that it is evenly divisible by something, and therefore not prime - so you can then exit your function and return to the screen that you aren't prime. if you get all the way through the loop and no 0's returned from mod - then you know it is prime.)

------------------
The Downside Of Being Better Than Everyone Else Is That People Tend To Assume You're Pretentious.


Click Here to See the Profile for HappyScrappy   Click Here to Email HappyScrappy     Edit/Delete Message      Reply w/Quote
aky

Pro Bodybuilder

Posts: 501
From:Canada, BC
Registered: Sep 2000

posted January 29, 2001 12:05 PM

Staff Use Only: IP: Logged


i know all about the procedures... all i am stuck with is how do i make TP determine if a number is a prime or not??? You said to use a math function (mod) i know how this works and all but not sure how to set it up to try any # that is inputted???

please help, you seem like the only one who knows about TP!!!

aky

------------------


Click Here to See the Profile for aky   Click Here to Email aky     Edit/Delete Message    UIN: 45428686   Reply w/Quote
HappyScrappy

Pro Bodybuilder

Posts: 367
From:Boston
Registered: Dec 2000

posted January 29, 2001 12:49 PM

Staff Use Only: IP: Logged


Okay. You said you know how to get a value in from the screen. That value that comes in is what you want to check to be prime.
Fantastic.
You said you know about procedures, so this is where you will put the pirme figuring code.
Fantastic.
You say you know how to use mod - perfect.

Now look up how to do loops - a for loop is probably what you want.

I'll write this in pseudocode here - if you want I can write it in some other language (even can be easily done in javascript - which might as well be pseudocode it is so easy) for you too - I just don't feel that I should write out the code in TP for you b/c that is just doing your work for you.

function isPrime(i)
for x=2 to i-1 do
y = i mod x
if y equals 0 then
isPrime returns false
exit function
end if
loop for
return true
end function

inputValue = readValue(X)
outputValue = isPrime(inputValue)
writeValue(outoutValue)


The general concept here is the same as what I covered in the hint in my last post.
you want to take in a number. then do a mod on it for all numbers from 2 up to itself minus one (1 and itself are obviously going to return 0) - if anything in there also returns 0, then you can end right then b/c it isn't prime. if it never returns 0, then you know it is prime. (mod will only return zero if it goes in evenly - like 2 goes into 4 twice with no remainder, 3 goes into 7 twice with a remainder of 1.)

That really should do it there. I'm not going to write the TP code for you... you should learn... I a frickin hate TP.

------------------
The Downside Of Being Better Than Everyone Else Is That People Tend To Assume You're Pretentious.


Click Here to See the Profile for HappyScrappy   Click Here to Email HappyScrappy     Edit/Delete Message      Reply w/Quote
aky

Pro Bodybuilder

Posts: 501
From:Canada, BC
Registered: Sep 2000

posted January 29, 2001 01:27 PM

Staff Use Only: IP: Logged


Thanks for all you help... i'll try to write it out and see how it goes.... well i'm going to class right now, and i'll put a post later on tonite to let you know... ya i know what you mean... i hate this shit too

aky

------------------


Click Here to See the Profile for aky   Click Here to Email aky     Edit/Delete Message    UIN: 45428686   Reply w/Quote
aky

Pro Bodybuilder

Posts: 501
From:Canada, BC
Registered: Sep 2000

posted January 30, 2001 03:53 AM

Staff Use Only: IP: Logged


well bro i've tried all week and cant figure it out....

i just cant get it.... if you can help me further that would be awesome. But if not that's ok too... i just need an example to look at then i can refer to it... i'm not going to copy it because then i'll flunk the exam... the best way to learn (for me) is from similar examples.... hope you can help...

but thanks for everything so far....

aky

------------------


Click Here to See the Profile for aky   Click Here to Email aky     Edit/Delete Message    UIN: 45428686   Reply w/Quote
HappyScrappy

Pro Bodybuilder

Posts: 367
From:Boston
Registered: Dec 2000

posted January 30, 2001 08:35 AM

Staff Use Only: IP: Logged


okay - read in the value.
I think that is readln in TP.
Then dump that value to your function.
have that value work on it.
have that value return an answer.
output that answer.
so (it has been awhile since I've used TP so I'm not positive on the syntax - but you have a book on it):

procedure isPrime(i:integer);
for x=2 to i-1;
modValue = i mod x;
if modValue equals 0 then;
return false;
exit procedure;
end;
end;
return true;
end;

writeln("Enter a number:");
readln(sPassedNum);
outputValue = isPrime(sPassedNum);
writeline(outputValue);


like I said, I haven't done the TP in a long time, so I don't know the syntax to exit a function, and I don't remember how the for loops, or the if statements are formed - but it is a lot like what I have above.
do you not have a book - look in the back at the index and you will find that it will point to the section of what you want. look in the back for "if" and it should tell you where the pages that discuss if statements are and the proper syntax.

that really should do it.

so it would look like this to the user:

Enter a number: (they enter 5)
true

or

Enter a number: (they enter 6)
false


you could also look at the boolean (the true or false) and do a check on it, if it is t or f, then output a certain string so that the user gets more info than just t or f.

good luck - that is all I can do for you.

------------------
The Downside Of Being Better Than Everyone Else Is That People Tend To Assume You're Pretentious.


Click Here to See the Profile for HappyScrappy   Click Here to Email HappyScrappy     Edit/Delete Message      Reply w/Quote
aky

Pro Bodybuilder

Posts: 501
From:Canada, BC
Registered: Sep 2000

posted January 30, 2001 10:53 AM

Staff Use Only: IP: Logged


thank you, this will be awesome...

aky

------------------


Click Here to See the Profile for aky   Click Here to Email aky     Edit/Delete Message    UIN: 45428686   Reply w/Quote

All times are ET (US)

Post New Topic  
Hop to:

Contact Us | Back to Elite Fitness | Privacy Statement

Powered by Infopop www.infopop.com © 2000
Ultimate Bulletin Board 5.45c



HomeArticlesDiscussion BoardsFeatured SitesContact Us� ReportsSupplementsShopping