comp.lang.ada
 help / color / mirror / Atom feed
* Need help for a Calculator program
@ 2002-02-01 12:06 Jim
  2002-02-01 12:41 ` John English
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Jim @ 2002-02-01 12:06 UTC (permalink / raw)


ive been reading that online book
http://www.it.bton.ac.uk/staff/je/adacraft/


it tell you how to program a calculator throughout the book, starting
with basic adding and then going on to operator procedence(well i
havent reached this stage yet) but the second part of the calculator
program (chapter  ) you enter an expression eg 1 + 2 + 3 * 4.  but you
have to end the expression with a full stop.  Is there a way where you
dont have to enter a full stop.

the program itself is in the link:
http://www.it.bton.ac.uk/staff/je/adacraft/ch03.htm#3.8


th full stop is used for a condition, if you put a full stop there it
will end a loop for 'getting' operators and then the program will
continue with calculating the expression.

could someone have a look at it for me plz ?



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Need help for a Calculator program
  2002-02-01 12:06 Need help for a Calculator program Jim
@ 2002-02-01 12:41 ` John English
  2002-02-01 14:07 ` Preben Randhol
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 14+ messages in thread
From: John English @ 2002-02-01 12:41 UTC (permalink / raw)


Jim wrote:
> 
> ive been reading that online book
> http://www.it.bton.ac.uk/staff/je/adacraft/
> 
> it tell you how to program a calculator throughout the book, starting
> with basic adding and then going on to operator procedence(well i
> havent reached this stage yet) but the second part of the calculator
> program (chapter  ) you enter an expression eg 1 + 2 + 3 * 4.  but you
> have to end the expression with a full stop.  Is there a way where you
> dont have to enter a full stop.

You can always use Ada.Text_IO.End_Of_Line to test for the end of
the line, or read a line into a string using Ada.Text_IO.Get_Line
and then process the string, stopping when you reach the end of it.
The implementation details I leave as an exercise for the reader... :-)

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Need help for a Calculator program
  2002-02-01 12:06 Need help for a Calculator program Jim
  2002-02-01 12:41 ` John English
@ 2002-02-01 14:07 ` Preben Randhol
  2002-02-01 18:17 ` Stephen Leake
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 14+ messages in thread
From: Preben Randhol @ 2002-02-01 14:07 UTC (permalink / raw)


On 1 Feb 2002 04:06:27 -0800, Jim wrote:
> it tell you how to program a calculator throughout the book, starting
> with basic adding and then going on to operator procedence(well i
> havent reached this stage yet) but the second part of the calculator
> program (chapter  ) you enter an expression eg 1 + 2 + 3 * 4.  but you
> have to end the expression with a full stop.  Is there a way where you
> dont have to enter a full stop.

Yes. If you were to use a comma instead what would you do with the
code to do that?

-- 
Preben Randhol         �For me, Ada95 puts back the joy in programming.�



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Need help for a Calculator program
  2002-02-01 12:06 Need help for a Calculator program Jim
  2002-02-01 12:41 ` John English
  2002-02-01 14:07 ` Preben Randhol
@ 2002-02-01 18:17 ` Stephen Leake
  2002-02-01 18:57   ` Jim
  2002-02-01 23:20   ` Jeffrey Carter
  2002-02-01 23:46 ` Jim
  2002-02-03 15:41 ` Jim
  4 siblings, 2 replies; 14+ messages in thread
From: Stephen Leake @ 2002-02-01 18:17 UTC (permalink / raw)


genx54321@hotmail.com (Jim) writes:

> ive been reading that online book
> http://www.it.bton.ac.uk/staff/je/adacraft/
> 
> 
> it tell you how to program a calculator throughout the book, starting
> with basic adding and then going on to operator procedence(well i
> havent reached this stage yet) but the second part of the calculator
> program (chapter  ) you enter an expression eg 1 + 2 + 3 * 4.  but you
> have to end the expression with a full stop.  Is there a way where you
> dont have to enter a full stop.
> 
> the program itself is in the link:
> http://www.it.bton.ac.uk/staff/je/adacraft/ch03.htm#3.8
> 
> 
> th full stop is used for a condition, if you put a full stop there it
> will end a loop for 'getting' operators and then the program will
> continue with calculating the expression.
> 
> could someone have a look at it for me plz ?

This sounds like homework; please say "it's not homework" if it isn't
:).

I'm not clear what you are asking for. I guess "full stop" means "hit
the return key" or "generate end of line" or something. Why do you
want to get rid of that?

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Need help for a Calculator program
  2002-02-01 18:17 ` Stephen Leake
@ 2002-02-01 18:57   ` Jim
  2002-02-01 23:20   ` Jeffrey Carter
  1 sibling, 0 replies; 14+ messages in thread
From: Jim @ 2002-02-01 18:57 UTC (permalink / raw)


well if you were given a simple calulator program, would you automatically
put a full stop at the end of the expression ? even though i know i have to
do it, i always forget when testing my program :-)

i just want to press enter at the last operand and get the answer to the
expression.


"Stephen Leake" <stephen.a.leake.1@gsfc.nasa.gov> wrote in message
news:uofj9vzgl.fsf@gsfc.nasa.gov...
> genx54321@hotmail.com (Jim) writes:
>
>
> I'm not clear what you are asking for. I guess "full stop" means "hit
> the return key" or "generate end of line" or something. Why do you
> want to get rid of that?
>
> --
> -- Stephe





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Need help for a Calculator program
  2002-02-01 18:17 ` Stephen Leake
  2002-02-01 18:57   ` Jim
@ 2002-02-01 23:20   ` Jeffrey Carter
  1 sibling, 0 replies; 14+ messages in thread
From: Jeffrey Carter @ 2002-02-01 23:20 UTC (permalink / raw)


Stephen Leake wrote:
> 
> I'm not clear what you are asking for. I guess "full stop" means "hit
> the return key" or "generate end of line" or something. Why do you
> want to get rid of that?

The misunderstanding here is that the original poster is British. The
British use "full stop" to refer to the dot at the end of a sentence
that Americans call a "period".

-- 
Jeffrey Carter



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Need help for a Calculator program
  2002-02-01 12:06 Need help for a Calculator program Jim
                   ` (2 preceding siblings ...)
  2002-02-01 18:17 ` Stephen Leake
@ 2002-02-01 23:46 ` Jim
  2002-02-02  4:12   ` Eric Merritt
  2002-02-02 12:04   ` Preben Randhol
  2002-02-03 15:41 ` Jim
  4 siblings, 2 replies; 14+ messages in thread
From: Jim @ 2002-02-01 23:46 UTC (permalink / raw)


ok, i think im gonna start this program again and try not to follow the book
as im not understang the 'calculator' well enough.

can someone give me some steps in designing a calculator, do i need to use
loops, do i need to use arrays etc that kind of thing.

thx





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Need help for a Calculator program
  2002-02-01 23:46 ` Jim
@ 2002-02-02  4:12   ` Eric Merritt
  2002-02-02 16:22     ` Jim
  2002-02-02 12:04   ` Preben Randhol
  1 sibling, 1 reply; 14+ messages in thread
From: Eric Merritt @ 2002-02-02  4:12 UTC (permalink / raw)


Overall design should be pretty similar regardless of
implementation language. I would suggest you psuedo
code it and once the design is work out in you mind
attempt to implement it in Ada. That way you may
concentrate on each aspect of you projects as it
arrises without worring about the other aspects too
much.

--- Jim <genx54321@hotmail.com> wrote:
> ok, i think im gonna start this program again and
> try not to follow the book
> as im not understang the 'calculator' well enough.
> 
> can someone give me some steps in designing a
> calculator, do i need to use
> loops, do i need to use arrays etc that kind of
> thing.
> 
> thx
> 
> 
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada


__________________________________________________
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions! 
http://auctions.yahoo.com



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Need help for a Calculator program
  2002-02-01 23:46 ` Jim
  2002-02-02  4:12   ` Eric Merritt
@ 2002-02-02 12:04   ` Preben Randhol
  1 sibling, 0 replies; 14+ messages in thread
From: Preben Randhol @ 2002-02-02 12:04 UTC (permalink / raw)


On Fri, 1 Feb 2002 23:46:07 +0000 (UTC), Jim wrote:
> ok, i think im gonna start this program again and try not to follow the book
> as im not understang the 'calculator' well enough.
> 
> can someone give me some steps in designing a calculator, do i need to use
> loops, do i need to use arrays etc that kind of thing.

I don't know how this program works, but if I wanted to make a
calculator I would like to have one that reads what I write until I
press the <RETURN> key like:

   2 + 3 * ( 6 / 7) - log(5)<RETURN>

To get this I would read what the user types by a Get_Line statement.
Get_Line will wait until you hit return. Now you use Get on this string
to find all the operands etc. You can thus keep the old code (you can
just add . to the string the user typed).

Preben



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Need help for a Calculator program
  2002-02-02  4:12   ` Eric Merritt
@ 2002-02-02 16:22     ` Jim
  0 siblings, 0 replies; 14+ messages in thread
From: Jim @ 2002-02-02 16:22 UTC (permalink / raw)


thats my problem i do not know how to design it, i am fairly new to ADA,
heck i am new to programming.

i did some pseudo code for the calculator program from the online book, just
to get my head round it :-

BEGIN
enter expression
get input

    start main loop

         start nested loop
              get operator symbol
                  if there is a 'space' character end the loop
         end nested loop

    if 'full stop' character show answer of expression, exit main loop
    else
    get number
    if + -> result := result + number
    if - -> result := result - number
    if * -> result := result * number
    if / -> result := result / number

    end main loop

end main program


do you think that is alright ?

are there any other ways of designing this calculator program ? maybe use
arrays ?



"Eric Merritt" <cyberlync@yahoo.com> wrote in message
news:mailman.1012623182.24002.comp.lang.ada@ada.eu.org...
> Overall design should be pretty similar regardless of
> implementation language. I would suggest you psuedo
> code it and once the design is work out in you mind
> attempt to implement it in Ada. That way you may
> concentrate on each aspect of you projects as it
> arrises without worring about the other aspects too
> much.
>






^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Need help for a Calculator program
  2002-02-01 12:06 Need help for a Calculator program Jim
                   ` (3 preceding siblings ...)
  2002-02-01 23:46 ` Jim
@ 2002-02-03 15:41 ` Jim
  2002-02-04 13:54   ` Stephen Leake
  4 siblings, 1 reply; 14+ messages in thread
From: Jim @ 2002-02-03 15:41 UTC (permalink / raw)



ive now used "end_of_line" instead of "if operator = '.' then put(result)".

but what happens now, you can put any character after the expression eg 1 +
2 + 3f,  1 + 2 + 3z press enter and get the answer.

if you dont put anything after the last operand it doesnt do anything.  This
is because the loop has the check the next character after the last operand
right ?

how do i make loop exit without it actually reading the next character ?







^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Need help for a Calculator program
  2002-02-03 15:41 ` Jim
@ 2002-02-04 13:54   ` Stephen Leake
  2002-02-12 11:55     ` John English
  0 siblings, 1 reply; 14+ messages in thread
From: Stephen Leake @ 2002-02-04 13:54 UTC (permalink / raw)


"Jim" <genx54321@hotmail.com> writes:

> ive now used "end_of_line" instead of "if operator = '.' then put(result)".
> 
> but what happens now, you can put any character after the expression eg 1 +
> 2 + 3f,  1 + 2 + 3z press enter and get the answer.
> 
> if you dont put anything after the last operand it doesnt do anything.  This
> is because the loop has the check the next character after the last operand
> right ?
> 
> how do i make loop exit without it actually reading the next character ?

Well, I need to see the code to be sure. 

I would read an entire line into a string, using Get_Line (Buffer,
Buffer_Last). Then go thru the string looking for operators and
operands. When you get to the end of the string, you are done.

Or you can require the user to enter a semicolon to terminate a
statement, like Ada does. That makes things simpler for the
programmer, which is ok while you are just learning.

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Need help for a Calculator program
  2002-02-04 13:54   ` Stephen Leake
@ 2002-02-12 11:55     ` John English
  2002-02-12 15:43       ` Pat Rogers
  0 siblings, 1 reply; 14+ messages in thread
From: John English @ 2002-02-12 11:55 UTC (permalink / raw)


Stephen Leake wrote:
> 
> Or you can require the user to enter a semicolon to terminate a
> statement, like Ada does. That makes things simpler for the
> programmer, which is ok while you are just learning.

Which is what the example in the book does, except it uses a full
stop rather than a semicolon. I avoided using Get_Line because
string variables and arrays hadn't been covered at that point
in the book, and End_Of_Line has too many gotchas.

However, what I hadn't realised is that while the Real English term
"full stop" is synonymous with the Real English term "period", the
same is not true in US English :-(

In retrospect, using "semicolon" would have been clearer, and I
now plan to fix the text to do this.

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Need help for a Calculator program
  2002-02-12 11:55     ` John English
@ 2002-02-12 15:43       ` Pat Rogers
  0 siblings, 0 replies; 14+ messages in thread
From: Pat Rogers @ 2002-02-12 15:43 UTC (permalink / raw)


"John English" <je@brighton.ac.uk> wrote in message
news:3C6902CE.22BC150C@brighton.ac.uk...
<snip>
> However, what I hadn't realised is that while the Real English term
<snip>
> same is not true in US English :-(

Real English?

If I may quote Mark Twain on the subject:

"That property has gone into the hands of a joint stock company and we own the
bulk of the shares!"

:-) :-) :-) :-) :-) :-) :-) :-) :-) :-)


---
Patrick Rogers                       Consulting and Training in:
http://www.classwide.com          Real-Time/OO Languages
progers@classwide.com               Hard Deadline Schedulability Analysis
(281)648-3165                                 Software Fault Tolerance





^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2002-02-12 15:43 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-01 12:06 Need help for a Calculator program Jim
2002-02-01 12:41 ` John English
2002-02-01 14:07 ` Preben Randhol
2002-02-01 18:17 ` Stephen Leake
2002-02-01 18:57   ` Jim
2002-02-01 23:20   ` Jeffrey Carter
2002-02-01 23:46 ` Jim
2002-02-02  4:12   ` Eric Merritt
2002-02-02 16:22     ` Jim
2002-02-02 12:04   ` Preben Randhol
2002-02-03 15:41 ` Jim
2002-02-04 13:54   ` Stephen Leake
2002-02-12 11:55     ` John English
2002-02-12 15:43       ` Pat Rogers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox