HW2, Programming Part

Due July 17

70 Points

Objectives: Help Student understand linked lists, stacks and their applications.

Overview: Students will write a programmable calculator. The calculator will have an assign function which takes a string. This string is composed of a variable name and an assignment: either an integer or postfix expression. The calculator will also have an evaluate function which takes a string representing a postfix expression and converts it into an integer, and then returns that integer. Postfix expressions will consist of single character variables, arithmetic operations, and integers between 0 and 9 inclusive. You may test your calculator with this code.

//Example: (Given a calculator object c)

c.assign(“x=5”);

c.assign(“y=x7+”);

int first = c.evaluate(“xy*”);

c.assign(“z=57*”);

c.assign(“x=x8+y *”);

int sec = c.evaluate(“xy+”);

int third = c.evaluate(“z”);

//This code will set first to 60, then it will set sec to 168, and third to 35.

DESIGN AND COMPILATION:

[10 Points] Students will receive 10 points for code that compiles. Be sure to name your files exactly as instructed when the name is specified. Be sure that you submit any additional classes you may have used in your design.

LINKED LISTS:

[15 Points] Students will create a linked list data structure to store variables. The linked list will consist of variable nodes; these will contain the variable name as a char and its value as an int. Students should create this structure in a separate class named VList.

STACK:

[15 Points] Students will create a stack to evaluate postfix expressions.

The stack will be completely dynamic, that is the underlying data structure will be

a linked list. Students should only need one stack to perform an evaluation. The

stack should also be its own class named CStack.

CALCULATOR:

[30 Points] Calculator – Students will create a calculator class named Calculator which should contain a constructor and two public methods void assign(string assgnmnt) and int evaluate(string expr) as described above. Students may use any additional methods they feel will help the functionality of the calculator.

 

SUBMISSIONS:

Students will submit all files necessary for compilation, it should contain at least the files named above and any additional files needed for the creation of the underlying data structures. Students do not need to submit a test file.