The stackmachine class should have eight member functions


Problem:

Part 1 will be implemented in Python. Program 1 (called prog4_1.py)

-will take a single command line argument. The command line argument will be the name of a text file.

-Your program should then read that file line by line and tokenize each input line, using a space as a delimiter.

-For each tokenized input line, print a single line to stdout each of the tokens separated with a comma. Multiple spaces, and leading/trailing spaces should be ignored.

Part 1 will be run like so: python3 prog4_1.py filename.txt

Part 2. In Python, Implement the class StackMachine in the StackMachine.py file.

-The StackMachine class should have eight member functions: push, pop, add, sub, mul, div, mod and the constructor.

-The push function should be the only member function that takes more than one argument.

-The pop function will be the only member function to return anything. (Each of the functions should take the self reference).

-If an operation is called, but not enough operands are available on the stack, nothing should occur. You can use any built in packages to implement the StackMachine class. You will probably only need a single member variable to implement this.

-push - Takes two arguments, the second argument should be pushed onto to internal data structure. pop - Removes and returns the top element of the internal data structure.

-If nothing is avalible, return None. (None is a valid data type in python). The math functions take only the self reference, if two (or more) elements exist on the internal data structure pop the top two elements off, perform the operations and push the answer onto the top of the internal data structure.

Program 2 will be written in Python. It will be called prog4_2.py

-This program will take a single command line argument which will be the name of a text file.

-The program will tokenize each line of the text file by a space (as performed in prog4_1.py). After tokenization, if the there are two tokens, and the first token is the string "push" and the second token is a number (real numbers are ok) it should push the number onto a StackMachine.

If there is a single token, and it is the string: pop, add, sub, mul, div or mod, the correct function on the StackMachine should be called. In the event of a pop, the returned value should be printed to the stdout. Any other input should be ignored.

You must ensure that your code can be run on a standard Debian based linux distribution using the shell tools of your choice. You may develop your solution on any machine you desire, as long as the final solution works on a standard linux distrubtion.

Request for Solution File

Ask an Expert for Answer!!
Python Programming: The stackmachine class should have eight member functions
Reference No:- TGS02898495

Expected delivery within 24 Hours