
HW1: Postfix Calculator
Get flash to fully experience Pearltrees
ECS 40 Homework 1: Postfix Calculator
Due : Thursday, January 19 at 2200 hours. Check out : git clone metastasis@cancer.cs.ucdavis.edu:user/{username}/1/1 Hand out : Reference program: postfix ( SHA-1 : 955dc54f30c2e85215122ade7c75f8001d2f768a ). Example input: postfix.test . Note: the reference program runs on only x86-64 Linux, where the command uname -m should output x86_64 .Reverse Polish notation ( RPN ) is a mathematical notation in which every operator follows all of its operands , in contrast to Polish notation , which puts the operator in the prefix position. It is also known as postfix notation and is parenthesis-free as long as operator arities are fixed. The description "Polish" refers to the nationality of logician Jan Łukasiewicz , who invented (prefix) Polish notation in the 1920s.
Reverse Polish notation
Postfix Calculator
This calculator uses postfix notation. To use the calculator your browser requires JavaScript support. The calculator works a little differently from other calculators you may have used. Suppose you want to add two numbers. Enter the first number. Press "Enter."Postfix Evaluation
Example : Let us see how the above algorithm will be imlemented using an example. Postfix String : 123*+4- Initially the Stack is empty. Now, the first three characters scanned are 1,2 and 3, which are operands.In computer science , a linked list is a data structure consisting of a group of nodes which together represent a sequence. Under the simplest form, each node is composed of a datum and a reference (in other words, a link ) to the next node in the sequence; more complex variants add additional links. This structure allows for efficient insertion or removal of elements from any position in the sequence. A linked list whose nodes contain two fields: an integer value and a link to the next node. The last node is linked to a terminator used to signify the end of the list.
Linked list
Stack (abstract data type)
Classes (I)
Introduction to C++ Classes
Contents An Example C++ Class C++ classes are similar to Java classes in many ways, but there are also important differences. Below is an example of a C++ class named IntList to be used to represent a list of integers; operations to add a value to the end of the list and to print the list are provided. The implementation uses a dynamically allocated array to store the integers; when the array is full, a new array of twice the size is allocated. In Java, the class definition would all be in a single file.C++ classes
The C++ programming language allows programmers to separate program-specific data types through the use of classes . Classes define types of data structures and the functions that operate on those data structures. Instances of these data types are known as objects and can contain member variables , constants , member functions , and overloaded operators defined by the programmer. Syntactically, classes are extensions of the C struct , which cannot contain functions or overloaded operators.Friend functions In principle, private and protected members of a class cannot be accessed from outside the same class in which they are declared. However, this rule does not affect friends . Friends are functions or classes declared with the friend keyword. If we want to declare an external function as friend of a class, thus allowing this function to have access to the private and protected members of this class, we do it by declaring a prototype of this external function within the class, and preceding it with the keyword friend :
Friendship and inheritance
Classes (II)
Overloading operators C++ incorporates the option to use standard operators to perform operations with classes in addition to with fundamental types. For example: This is obviously valid code in C++, since the different variables of the addition are all fundamental types. Nevertheless, it is not so obvious that we could perform an operation similar to the following one: In fact, this will cause a compilation error, since we have not defined the behavior our class should have with addition operations.Arrays
An array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier.A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose, C++ provides control structures that serve to specify what has to be done by our program, when and under which circumstances. With the introduction of control structures we are going to have to introduce a new concept: the compound-statement or block . A block is a group of statements which are separated by semicolons (;) like all C++ statements, but grouped together in a block enclosed in braces: { } : { statement1; statement2; statement3; } Most of the control structures that we will see in this section require a generic statement as part of its syntax.
Control Structures
The logical OR operator ( || ) returns the boolean value true if either or both operands is true and returns false otherwise. The operands are implicitly converted to type bool prior to evaluation, and the result is of type bool . Logical OR has left-to-right associativity. The operands to the logical OR operator need not be of the same type, but they must be of integral or pointer type.

