The teacher asks for the Impossible

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Pardon me, I think I seemed to have misplaced this topic. Has anyone seen where it went? :wink:

Seriously, this thread has been derailed a bit, wouldn't you all agree. The original poster asked how one would go about writing a PHP calculator for a shool project. He mentioned that he was given very little training in PHP and that this is pretty much his first experience with it.

I would agree that we should not be writing this code for him, regardless of our position on the decay of education in our countries or how we feel about what teachers are asking students to do. The OP asked a question, we all pitched in a little bit, threw out ideas and suggestions. Shouldn't we now let the student try some of the things we suggested and see if he can't come up with something on his own... the way it was intended for his project?

This is just a thought of mine. I don't mean to be a killjoy, party-pooping, fuddy-duddy.
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

If I remember correctly when an assignment is made stating you have to use a php html solution you are stuck with php and html. So javascript is not an option.

So the solution sould be:

1. Assign the used numbers to a form linked to php self.
2. Store the numbers in a session array. Numbers stay in the uneven array indexes and operators in the even ones. Display it at the page
3. Once an operator is pressed the index is incremented.
4. check if the operator was = if so make the end calculation if not increment the index again
5. for the end calculation just check the operators and process them by mathematical standarts. */ > +-
6. Display the result.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Here's a way to implement a calculator

http://en.wikipedia.org/wiki/Reverse_Polish_Notation :)
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Everah wrote:I would agree that we should not be writing this code for him, regardless of our position on the decay of education in our countries or how we feel about what teachers are asking students to do.
Well, if he just takes one of the solutions from this thread and hands it in as his own work I imagine he'll fail. It's not like his teacher can't look at this forum.. All my university tutors would Google key phrases from our assignments as a simple plagarism check, and that was 6 years ago..
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post by aerodromoi »

onion2k wrote: Well, if he just takes one of the solutions from this thread and hands it in as his own work I imagine he'll fail. It's not like his teacher can't look at this forum.. All my university tutors would Google key phrases from our assignments as a simple plagarism check, and that was 6 years ago..
That's up to him, I suppose. Right now I we've got two php-only approaches, one using eval and forms, the other a cumbersome switch statement and no forms. The third is an ajax version.

It's safe to say that there's scope for improvement for all of them (eg. error handling, input validation), which makes it raptor's call now. If he cooks up something based on the examples and puts some effort in it, I seriously doubt that his teacher will say anything.

aerodromoi

ps: Ok, might be a bit unrealistic for the ajax version ;)
SpiderMonkey
Forum Commoner
Posts: 85
Joined: Fri May 05, 2006 4:48 am

Post by SpiderMonkey »

OK, on the surface of it a calculator in php doesn't sound such a good idea, but I'm assuming that is half the assignment - figuring out that having it reload the page every button press is a Bad Thing.

Heres how I would do it (I'm guessing this might have already been suggested, I've not read the entire thread):

* A javascript function that updates a textbox which is your calculator display. A single function can do this, as long as the buttons pass themselves as a parameter using 'this'

* The '=' set up to submit the form. The page should target itself, so you stay in the calculator when you get a result

* The php code should parse anything it was passed then place the result in the same text box. Reverse polish notation might help for this.
Raptor Cardel
Forum Newbie
Posts: 7
Joined: Mon Jun 05, 2006 10:58 am

Post by Raptor Cardel »

My appologies folk! Im only able to access to computer for this at the school, My home internet exploded, more ro less. Aeros code works near flawlessly, However it gives several errors until numbers are entered. This being said, Leave it to me to figure out. So I can say I have done some learning of some sort. Like I said, I wont submit this code like this however, since it is not mine. I will use it as a teaching tool so I can fully understand how it works.

You guys have been alot of help! Thank you so much
benslayton
Forum Newbie
Posts: 12
Joined: Tue Jun 06, 2006 3:08 pm

Post by benslayton »

Ive just read the first post only. Too lazy to read the rest. But look at this.......
http://dynamicdrive.com/dynamicindex11/cal.htm

*View in IE
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post by aerodromoi »

benslayton wrote:Ive just read the first post only. Too lazy to read the rest. But look at this.......
http://dynamicdrive.com/dynamicindex11/cal.htm

*View in IE
ehmmmmm ;)

@raptor: What kind of errors?

aerodromoi
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

benslayton wrote:Ive just read the first post only. Too lazy to read the rest. But look at this.......
http://dynamicdrive.com/dynamicindex11/cal.htm

*View in IE
Works only on IE!!! :(
Post Reply