[CSUSB]
>> [CNS]
>> [Comp Sci Dept]
>> [R J Botting]
>> [CSci202]
>>
lab09
Stack.h. If
this file is #included in your program the compiler
can create a stack of any type of object by filling in the blanks.
The blank is called T in this code.
The T template parameter can be replaced by any type name:
double, int, float, short, long, char,string,
or even a class that you have created yourself.
You will also need the reverse.cpp and exprEval.cpp programs from the last lab. You probably won't need the makefile.
Note member function implementations are included in this file. This is because the file defines templates. It is difficult for normal loaders to link compiled code correctly when the original source code defines a template. The sizes of all objects are needed to generate a linkable *.o file. This is not possible with all templates because the size of the objects often depend on the actual data type used in place of T.
reverse.cpp program
to #include "tstack.h"
instead of #include "stack.h". You will then need to
change one declaration to declare a Stack<char>
(a stack of chars) instead
of a "Stack".
Note I have removed the word 'template' from
somewhere in tstack.h.
Use the compiler to find where and fix it. A simple compilation like
g++ -o reverse reverse.cppshould work because program because
tstack.h uses inline code.
Use the command above to
correct your program and tstack.h. You can then test the
program with this command
with
./reverse
1 / 2 =gives the answer 0.5.
Start by copying Evalexpr.cpp to a new file
called ev.cpp by using this UNIX command:
cp evalExpr.cpp ev.cpp
ev.cpp program from
lab08 so that it uses tstack.h
to do double-length floating point calculations. It
will need a Stack of double operands and a stack of
intoperators. A simple
compilation command like
g++ -o ev ev.cppcan be used.
Hint. We used a function atoi
to convert a char* into an int.
There is a similar function in the same library called
atof which converts
ASCII into floating point numbers. You will find it very helpful in
this lab.