Dec 052017

Program and source for beginners to learn stacks in pPASCAL. simple. documentation incl. | |||
---|---|---|---|

File Name | File Size | Zip Size | Zip Type |

OPSTACK.EXE | 6272 | 4557 | deflated |

OPSTACK.PAS | 4156 | 1685 | deflated |

OPSTACK.TXT | 4729 | 1867 | deflated |

# Download File OPSTACK.ZIP Here

## Contents of the OPSTACK.TXT file

OPSTACK! (C)1995 by Matt Hum

aka. Matt's Mathematical Gizmo Solver

All Rights Reserved

INTRODUCTION:

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

This program is distributed to the Public Domain for use by people learning

PASCAL as a language. This is an example on usage of stacks. You may do

anything you wish to this piece of code, as long as I am not held responsible

for any damages that can occur from this piece of software or any modifications

made to the source by the user, or any virii in the software, as this software

is distributed VIRUS-FREE.

FULLY PARENTHIZED EXPRESSIONS:

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

This program solves fully parenthisized mathematical equations. It will

understand the four basic mathematical operations:

+ Addition

- Subtraction

* Multiplcation

/ Division

NOTE: this program will not work with floating point real values, so the values

returned in the division, will be the whole number answer. for example:

7/3=2

4/3=1

1/2=0

the equation does have to be parenthized. this is

(a+b)

through this equation, an equation can be added upon to make it seem fairly

complex. one way of expansion is:

((a+b)*c)

this way there is no doubt of how the equation is to be solved (disregarding the

order of operations). For this matter:

(((((5+3)-(2*2))+6)*3)/2)

this equation will be solved in the following operation:

(((((8)-(4))+6)*3)/2)

((((4)+6)*3)/2)

(((10)*3)/2)

((30)/2)

15

your final answer is 15. this is an explanation of a fully parenthized

equation.

HOW IT WORKS:

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

this program uses stacks. it has 2 seperate stacks. one stores numbers, and

the other stores operations. for information on stacks, see below. the program

reads in the characters, and it pushes them onto the number stack. if it comes

upon a operation, it pushes that onto the operation stack. when a closed, or

right parenthesis ")" is reached, it pops off the last 2 numbers, the last

operation, calculates the 2 numbers in memory with the operation it poped, and

pushes the answer onto the number stack. this way, the open, or left parentheses

"(" can almost be ignored! that's it. simple isn't it?

example: number operation

equation: ((((3+4)-(4-2))*3) stack stack

read in the data

3

3 +

4 3 +

on a ")" calculate the last 2

and push it 7

continue reading data 7 -

4 7 -

4 7 - -

2 4 7 - -

calculate 4-2 2 7 -

5

5 *

3 5 *

And at the end of the string

you have your answer -------------------> 15

STACKS:

------

a stack is a way of storing data. in a stack you can push(add) data, or

pop(remove) data from the stack. for stacks you push data onto the top of a

stack, and pop of the top of a stack. example:

current number current stack:

add to stack:

3 5 7 2

push stack 5 3

push stack 7 5 3

push stack 2 7 5 3

pop stack 7(in memory)

2(to push on stack) 5 3

push stack nil 2 5 3

that's the basics of a stack. one way to do this is to build this into a object.

some guidelines to follow:

1. don't get too complicated-complicated programs can often confuse the

programmer that wrote it, especially, if the programmer is inexperienced

2. if it doesn't work the first time, try, try again. this can be a little

frustrating, but i'll pay off, when you finally get it.

3. if it still doesn't work, try rewriting it. this can become monotonous,

but often this happens a lot in programming.

4. Enjoy programming. Have fun doing it.

Umm, that's all for now, look for other programs I release for beginners. Often

they will be written by either me, or in cooperation with Wavelength Software

Inc.

For any questions, comments, compliments (I hope)

you can reach me at the BioInsanity BBS

@(301)942-0504 between the hrs of 5pm-7am

or e-mail me on the internet at [email protected]

aka. Matt's Mathematical Gizmo Solver

All Rights Reserved

INTRODUCTION:

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

This program is distributed to the Public Domain for use by people learning

PASCAL as a language. This is an example on usage of stacks. You may do

anything you wish to this piece of code, as long as I am not held responsible

for any damages that can occur from this piece of software or any modifications

made to the source by the user, or any virii in the software, as this software

is distributed VIRUS-FREE.

FULLY PARENTHIZED EXPRESSIONS:

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

This program solves fully parenthisized mathematical equations. It will

understand the four basic mathematical operations:

+ Addition

- Subtraction

* Multiplcation

/ Division

NOTE: this program will not work with floating point real values, so the values

returned in the division, will be the whole number answer. for example:

7/3=2

4/3=1

1/2=0

the equation does have to be parenthized. this is

(a+b)

through this equation, an equation can be added upon to make it seem fairly

complex. one way of expansion is:

((a+b)*c)

this way there is no doubt of how the equation is to be solved (disregarding the

order of operations). For this matter:

(((((5+3)-(2*2))+6)*3)/2)

this equation will be solved in the following operation:

(((((8)-(4))+6)*3)/2)

((((4)+6)*3)/2)

(((10)*3)/2)

((30)/2)

15

your final answer is 15. this is an explanation of a fully parenthized

equation.

HOW IT WORKS:

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

this program uses stacks. it has 2 seperate stacks. one stores numbers, and

the other stores operations. for information on stacks, see below. the program

reads in the characters, and it pushes them onto the number stack. if it comes

upon a operation, it pushes that onto the operation stack. when a closed, or

right parenthesis ")" is reached, it pops off the last 2 numbers, the last

operation, calculates the 2 numbers in memory with the operation it poped, and

pushes the answer onto the number stack. this way, the open, or left parentheses

"(" can almost be ignored! that's it. simple isn't it?

example: number operation

equation: ((((3+4)-(4-2))*3) stack stack

read in the data

3

3 +

4 3 +

on a ")" calculate the last 2

and push it 7

continue reading data 7 -

4 7 -

4 7 - -

2 4 7 - -

calculate 4-2 2 7 -

5

5 *

3 5 *

And at the end of the string

you have your answer -------------------> 15

STACKS:

------

a stack is a way of storing data. in a stack you can push(add) data, or

pop(remove) data from the stack. for stacks you push data onto the top of a

stack, and pop of the top of a stack. example:

current number current stack:

add to stack:

3 5 7 2

push stack 5 3

push stack 7 5 3

push stack 2 7 5 3

pop stack 7(in memory)

2(to push on stack) 5 3

push stack nil 2 5 3

that's the basics of a stack. one way to do this is to build this into a object.

some guidelines to follow:

1. don't get too complicated-complicated programs can often confuse the

programmer that wrote it, especially, if the programmer is inexperienced

2. if it doesn't work the first time, try, try again. this can be a little

frustrating, but i'll pay off, when you finally get it.

3. if it still doesn't work, try rewriting it. this can become monotonous,

but often this happens a lot in programming.

4. Enjoy programming. Have fun doing it.

Umm, that's all for now, look for other programs I release for beginners. Often

they will be written by either me, or in cooperation with Wavelength Software

Inc.

For any questions, comments, compliments (I hope)

you can reach me at the BioInsanity BBS

@(301)942-0504 between the hrs of 5pm-7am

or e-mail me on the internet at [email protected]

December 5, 2017
Add comments