\documentclass[12pt]{article} \usepackage{times} \topmargin -0.3truein \headheight 0.3truein \headsep 0.3truein \footskip 0.6in \newcommand{\headerfont}{\fontfamily{phv}\fontseries{b}\fontshape{n}% \fontsize{10}{12pt}\selectfont} \newcommand{\ttb}{\fontfamily{pcr}\fontseries{b}\fontshape{n}% \fontsize{12}{14pt}\selectfont} \newcommand{\largebold}{\fontfamily{ptm}\fontseries{b}\fontshape{n}% \fontsize{15}{17pt}\selectfont} \newcommand{\largeboldital}{\fontfamily{ptm}\fontseries{b}\fontshape{it}% \fontsize{14}{16pt}\selectfont} \newcommand{\Largebold}{\fontfamily{ptm}\fontseries{b}\fontshape{n}% \fontsize{19}{21pt}\selectfont} \newcommand{\Largeboldital}{\fontfamily{ptm}\fontseries{b}\fontshape{it}% \fontsize{19}{21pt}\selectfont} % %%%%%%%%%%%%%%%%%%% My Headings %%%%%%%%%%%%%%%%%%%%% % \makeatletter % Make '@' a letter to allow access to private macros % \def\ps@myheadings{ \def\@oddhead{\framebox[\mywidth]{\headerfont \rule[3.1mm]{0mm}{0mm} \hspace{0.7mm}\lefthead, \today \hfill Page~~\thepage~~of~~\pageref{'thatsall'}~~}} \def\@oddfoot{} \def\@evenhead{} \def\@evenfoot{} } \makeatother % Remove '@' a non-letter to disallow access to pvt macros %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % next line must come after the headings stuff! \pagestyle{myheadings} % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \newcommand{\mywidth}{6.0in} \newcommand{\lefthead}{CS1723: Data Structures, Assignment 2} \newcommand{\st}{\rule[-.8mm]{0mm}{2mm}} \newcommand{\longst}{\rule[-3mm]{0mm}{2mm}} \newcommand{\outerbaselinesep}{14pt} \topmargin 0.0in \oddsidemargin 0.25in \evensidemargin 0.25in \textwidth \mywidth \textheight 8.0in \parindent 0mm %10mm \parskip 3mm \fboxrule=0.3mm \begin{document} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % make everything sloppy \sloppy \begin{center} {\largebold The University of Texas at San Antonio \\ Computer Science Division \\ San Antonio, Texas 78249} \\ \vspace{0.4in} {\Largebold CS 1723, Data Structures \\ Fall Semester, 1998\longst \\ Programming Assignment 2, Due September 11, 1998\longst } \\ {\Largeboldital Reverse Polish Evaluation} \end{center} \baselineskip=\outerbaselinesep \vspace{-0.1in} {\bf The Assignment:} For this assignment you are to write a program, {\tt evaluate}, that will find the value of a reverse Polish expression. The input source (RPN) will be made up of the following elements: \vspace{-0.2in} \begin{itemize} \item single-digit integer constants: {\tt 0}, {\tt 1}, {\tt 2}, {\tt 3}, {\tt 4}, {\tt 5}, {\tt 6}, {\tt 7}, {\tt 8}, or {\tt 9}. \item operators: $\wedge$, {\tt *} {\tt /}, {\tt +}, or {\tt -}. \item special symbol to terminate the input: {\tt \#}. \end{itemize} \vspace{-0.2in} This assignment limits to single-digit integer constants to keep things simpler. For example, here is sample input source, which calculates one root of the equation $y = x^2 + 3x + 2$, with $a = 1, b = 3, c = 2$: \vspace{-0.2in} \begin{verbatim} 32^41*2*-12/^3-21*/# \end{verbatim} {\bf Overall organization:} Your program should be contained in a single directory, say {\tt assign2}. Within this directory there will be several files implementing the the main function and the stack. \vspace{-0.1in} {\bf Details about the program {\ttb evaluate.c}:} Organize this program as (at least) {\em three} files: {\tt evaluate.c}, {\tt estack.h}, and {\tt estack.c}. The evaluation of one of these RPN strings can proceed as described in the text and in class: Use an evaluation stack. Operands are pushed on the stack, and operators pop their arguments off the stack and push the result. When the final \# is encountered, the remainder of the stack is popped and printed. (It should just be a single value.) The arithmetic should be done using {\tt double}s. Thus the output of the second example should be the following: \vspace{-0.2in} \begin{verbatim} -1.000000 \end{verbatim} \vspace{-0.2in} A single character that is a digit can be converted to a {\tt double} with \vspace{-0.2in} \begin{verbatim} #include ... if (isdigit(c)) return (double) (c - '0'); ... \end{verbatim} \vspace{-0.2in} The raise-to-a-power operator can be handled with the built-in function {\tt pow(x, y)} (see the white book, page 251). For this to work you need to include {\tt }, and (on runner) you need to add {\tt -lm} to the compiler options, so that the math library will be searched, as shown in the {\tt makefile} below. The {\tt lint} program also needs this option as shown---without it {\tt lint} will produce 600 lines of warnings. {\bf The new {\ttb makefile} for {\ttb evaluate.c}:} \vspace{-0.1in} \begin{verbatim} # makefile for evaluate program evaluate: evaluate.c estack.c estack.h cc -g -o evaluate evaluate.c estack.c -lm lint: lint -m -u evaluate.c estack.c -lm \end{verbatim} \vspace{-0.1in} {\bf Required Execution:} Your program {\em must} execute the following test data, with the expected output: \hspace{1.0in} \begin{tabular}{|c|c|c|} \hline {\bf Input test data} & {\bf Expected output} \\ \hline\hline \verb.23+4*#. & 20.000000 \\ \hline \verb.234+*#. & 14.000000 \\ \hline \verb.52^34*2^+12/^#. & 13.000000 \\ \hline \verb.55+2^13/^#. & 4.641589 \\ \hline \verb.32^41*2*-12/^3-21*/#. & -1.000000 \\ \hline \end{tabular} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \label{'thatsall'} \end{document}