CS 2604 Minor Project 1 Summer 2000

Similar documents
CS 2604 Minor Project 1 DRAFT Fall 2000

CS 2604 Minor Project 3 DRAFT Summer 2000

CS 2604 Minor Project 3 Movie Recommender System Fall Braveheart Braveheart. The Patriot

CS 1044 Program 6 Summer I dimension ??????

CS 2704 Project 1 Spring 2001

Fundamental Concepts: array of structures, string objects, searching and sorting. Static Inventory Maintenance Program

Decision Logic: if, if else, switch, Boolean conditions and variables

The Program Specification:

CS 1044 Program 2 Spring 2002

CS 2704 Project 3 Spring 2000

Multiple-Key Indexing

Each line will contain a string ("even" or "odd"), followed by one or more spaces, followed by a nonnegative integer.

CS 1044 Project 1 Fall 2011

CS 1044 Project 2 Spring 2003

Creating a String Data Type in C

gcc o driver std=c99 -Wall driver.c bigmesa.c

A rectangle in the xy-plane, whose sides are parallel to the coordinate axes can be fully specified by giving the coordinates of two opposite corners:

gcc o driver std=c99 -Wall driver.c everynth.c

CS 2704 Project 2: Elevator Simulation Fall 1999

You will provide an implementation for a test driver and for a C function that satisfies the conditions stated in the header comment:

CS 1044 Project 5 Fall 2009

For storage efficiency, longitude and latitude values are often represented in DMS format. For McBryde Hall:

Given that much information about two such rectangles, it is possible to determine whether they intersect.

Pointer Casts and Data Accesses

Accessing Data in Memory

Programming Standards: You must conform to good programming/documentation standards. Some specifics:

Pointer Accesses to Memory and Bitwise Manipulation

CS2304 Spring 2014 Project 3

struct _Rational { int64_t Top; // numerator int64_t Bottom; // denominator }; typedef struct _Rational Rational;

Pointer Accesses to Memory and Bitwise Manipulation

CS 3114 Data Structures and Algorithms DRAFT Project 2: BST Generic

Pointer Accesses to Memory and Bitwise Manipulation

CS3114 (Fall 2013) PROGRAMMING ASSIGNMENT #2 Due Tuesday, October 11:00 PM for 100 points Due Monday, October 11:00 PM for 10 point bonus

// Initially NULL, points to the dynamically allocated array of bytes. uint8_t *data;

3. When you process a largest recent earthquake query, you should print out:

Here is a C function that will print a selected block of bytes from such a memory block, using an array-based view of the necessary logic:

Both parts center on the concept of a "mesa", and make use of the following data type:

CS ) PROGRAMMING ASSIGNMENT 11:00 PM 11:00 PM

PR quadtree. public class prquadtree< T extends Compare2D<? super T> > {

Simple C Dynamic Data Structure

Assessment of Programming Skills of First Year CS Students: Problem Set

1 Lexical Considerations

The assignment requires solving a matrix access problem using only pointers to access the array elements, and introduces the use of struct data types.

File Navigation and Text Parsing in Java

Project 3: RPN Calculator

Invoice Program with Arrays and Structures

Special Section: Building Your Own Compiler

Here is a C function that will print a selected block of bytes from such a memory block, using an array-based view of the necessary logic:

CS2383 Programming Assignment 3

Assignment 4 Publication date: 27/12/2015 Submission date: 17/01/ :59 People in-charge: R. Mairon and Y. Twitto

19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd

CSE 131 Introduction to Computer Science Fall Exam II

Stating the obvious, people and computers do not speak the same language.

Project 3 Due October 21, 2015, 11:59:59pm

CS 206 Introduction to Computer Science II

CS52 - Assignment 8. Due Friday 4/15 at 5:00pm.

CS 6353 Compiler Construction Project Assignments

Question Points Score

CMPSC 111 Introduction to Computer Science I Fall 2016 Lab 8 Assigned: October 26, 2016 Due: November 2, 2016 by 2:30pm

a f b e c d Figure 1 Figure 2 Figure 3

Full file at

Stacks. stacks of dishes or trays in a cafeteria. Last In First Out discipline (LIFO)

09 STACK APPLICATION DATA STRUCTURES AND ALGORITHMS REVERSE POLISH NOTATION

CS 6353 Compiler Construction Project Assignments

CSE 131S Introduction to Computer Science Summer SON Exam I

CS143 Handout 05 Summer 2011 June 22, 2011 Programming Project 1: Lexical Analysis

In this chapter you ll learn:

Draw a diagram of an empty circular queue and describe it to the reader.

CS 206 Introduction to Computer Science II

Computer Programming C++ (wg) CCOs

File Navigation and Text Parsing in Java

CS 3114 Data Structures and Algorithms Test 1 READ THIS NOW!

flex is not a bad tool to use for doing modest text transformations and for programs that collect statistics on input.

CS 211. Project 5 Infix Expression Evaluation

Full file at C How to Program, 6/e Multiple Choice Test Bank

Gradebook - Grades Tab Create Assignment

Jim Lambers ENERGY 211 / CME 211 Autumn Quarter Programming Project 2

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Additional Guidelines and Suggestions for Project Milestone 1 CS161 Computer Security, Spring 2008

Assignment 4. Overview. Prof. Stewart Weiss. CSci 335 Software Design and Analysis III Assignment 4

Lexical Considerations

CS 211 Programming Practicum Fall 2018

CS 2505 Computer Organization I

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

Microsoft Excel 2010 Handout

15-122: Principles of Imperative Computation, Fall 2015

Absolute C++ Walter Savitch

SimpleCalc. which can be entered into a TI calculator, like the one on the right, like this:

UNIT-II. Part-2: CENTRAL PROCESSING UNIT

2.8. Decision Making: Equality and Relational Operators

Chapter 2 THE STRUCTURE OF C LANGUAGE

The Stack and Queue Types

CS 374 Fall 2014 Homework 2 Due Tuesday, September 16, 2014 at noon

CS 111X - Fall Test 1 - KEY KEY KEY KEY KEY KEY KEY

CIS 162 Project 4 Farkle (a dice game)

CSE 214 Computer Science II Stack

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION

This homework is due by 11:59:59 PM on Thursday, October 12, 2017.

Programming Assignment 3

Transcription:

RPN Calculator For this project, you will design and implement a simple integer calculator, which interprets reverse Polish notation (RPN) expressions. There is no graphical interface. Calculator input will be provided in an input script file and feedback from the calculator application will be written to an output file. The RPN Calculator will use an internal stack to manage parsing RPN expressions. Parsing RPN is described in detail in Kruse/Ryba. The RPN Calculator will also contain a number of locations that are user-accessible, for storing results for later use. These locations will be referred to by sequential integer labels, beginning with zero. The RPN Calculator will also have an internal register ( location), called the Accumulator, which will be used to store the value of the current expression. When the Calculator is turned on, the Accumulator and internal locations will store zeros, and its internal stack will be empty. The Calculator may have any additional internal features you find useful or necessary. RPN expressions are also described in detail in Kruse/Ryba. For our purposes, an RPN expression will contain only operands and operators, in valid RPN sequence, where: an operand is a sequence of one or more decimal digits, optionally preceded by a plus or minus sign, and containing no embedded spaces or tabs. an operator is one of the characters +, -, *, or /. Data Structures: The primary data structures element of this project is the stack used to parse the RPN expressions. Your implementation is under the following specific requirements: You must use a stack, encapsulated as a C++ class (or template if you prefer). The underlying stack structure may be either an array or linked; however, if you use an array, its size must be managed dynamically. It is NOT acceptable to simply declare a huge statically sized array. The stack must protect against overflow and underflow, with some sensible means for the user to detect when such an error has occurred. Kruse/Ryba make good use of an internal error state data member for this, whereas my implementation uses exceptions. You may use either approach, or another. The internal locations maintained by the calculator must be allocated dynamically; again whether an array or a linked structure is used is a design decision you must make. (However, in this case, one alternative is clearly superior.) Your design must make appropriate use of classes. The specification implies the existence of additional classes besides those involved in the implementation of the stack. Without exception, data members of classes should be private. Your design should incorporate some degree of error handling. As noted below, the input file will be syntactically correct, so syntax checking of input is not required. On the other hand, stack errors may occur (although only if there s a flaw in the input or in your implementation), and illegal numerical operations (division by zero) could be specified. Your program must deal with those situations without crashing. If an error occurs during the evaluation of an RPN expression, that will mean that there s an error in your code. However, your program should still attempt to recover, by flushing the current calculation and proceeding to the next input command. If an illegal numeric operation is encountered, your program should print out an error message (see input samples for this), flush the current expression, and proceed to the next input command. Due: 23:59:59 Monday, July 10 Page 1 of 5

Driver File Description: Your program must read its input from a file named RPN.in use of another input file name will almost certainly result in a score of 0. Lines beginning with a semicolon ( ; ) character are comments; your program will ignore comments. An arbitrary number of comment lines may occur in the input file. The first non-comment line will consist of a text label, followed by a tab character and then a positive integer value which specifies how many user-accessible locations the RPN calculator will have, such as: 5 Each remaining line of the input file will specify one of the commands described below. Each line consists of a sequence of tokens which will be separated by single tab characters. A newline character will immediately follow the final token on each line. rpn <RPN Expresion> This will cause the given RPN expression to be passed to the Calculator (probably as a string, but that s your decision). The Calculator will parse the RPN expression and evaluate it, storing the result in its Accumulator. The RPN expression will be syntactically valid, so you are not required to check it for errors; however, a robust implementation would detect an error during parsing, generate a useful error message, and flush the expression. The tokens that make up the RPN expression will be tab-separated. This will cause the Calculator to display the current value in the Accumulator to the output file. See the output section for formatting instructions. This will cause the Calculator to display a list of the values that are currently stored in locations to the output file. See the output section for formatting instructions. store <index> If index is a logically valid location, this will cause the Calculator to store a copy of the current Accumulator value to the specified location. If the specified location is invalid, the command has no effect. recall <index> If index is a logically valid location, this will cause the Calculator to push a copy of value at that location onto the top of the Calculator s internal stack. If the specified location is invalid, the command has no effect. clear This resets the Accumulator and locations to zero, and clears the Calculator s internal stack. exit This causes the Calculator application to terminate. The input file is guaranteed to end with an exit command. Due: 23:59:59 Monday, July 10 Page 2 of 5

Legend: in the commands above: <RPN expression> <index> a string representing a logically valid RPN expression (as described in Kruse/Ryba and above). a non-negative integer You may assume that the input file will conform to the given syntax, so syntactic error checking is not required. However, you should be careful about logical errors, such as division by zero, in the RPN evaluation. Here is a sample input file: ; CS 2604 Summer 2000 ; Minor Project 1 ; Sample Input File 0 ; 5 ; Evaluate a trivial RPN expression: rpn 4-7 + ;... and show it: ;... and save it: store 3 ; Evaluate a more complex RPN expression: rpn 5 3 * 2 4 + / ;... and show it: ;...and save it: store 1 ;... and display the state: ; Put the first result back on the stack: recall 3 ;... and multiply it by 14: rpn 14 * ;...and show it: ;...and save it: store 0 ;... and display the state: ;... and clear the calculator clear ;...and exit: exit Due: 23:59:59 Monday, July 10 Page 3 of 5

Output File Description: Your program must write its output to a file named RPN.out use of another output file name will undoubtedly result in a score of 0. Since your output for this assignment will be graded automatically, you must adhere to the specified format exactly. The first two lines should contain your name, course and project title, followed by a blank line, as shown: William D McQuain CS 2604 RPN Calculator -3 2 1: 2 3: -3-42 0: -42 1: 2 3: -3 The output above was produced by my solution, executed on the sample input file given earlier. Accumulator and displays should be labeled, as shown, with the text labels on a line preceding the numerical value. The locations should also be labeled, as shown, with the correct index. Note that in this case, the final display shows no values because the clear command has erased all the stored values. You are not required to use this exact horizontal spacing, but your output must satisfy the following requirements: = = You must arrange your output in neatly aligned columns, with a label identifying the contents of each column. Use spaces, not tabs to align your output. Note that while the Curator doesn t deduct points for horizontal alignment, the ability to properly align output data in a tabular format will be required for some of the programming projects in this course. You must print a newline character at the end of each line. Submitting Your Program: You will submit this assignment to the Curator System (read the Student Guide), and it will be graded automatically. Instructions for submitting, and a description of how the grading is done, are contained in the Student Guide. Note that the automated grading system requires that your program be submitted as a single source file. For this project you should develop your implementation using separate compilation, and then manually concatenate the code into a single.cpp file, being careful to get the order right and remove obsolete #include directives. You will be allowed up to five submissions for this assignment. Use them wisely. Test your program thoroughly before submitting it. If you do not get a perfect score, analyze the problem carefully and test your fix before submitting again. The highest score you achieve will be counted. The submission client can be found at: http:spasm.cs.vt.edu:8080/curator/ Due: 23:59:59 Monday, July 10 Page 4 of 5

Evaluation: Your submitted program will be assigned a score based upon the runtime testing performed by the Curator System. After that, your program will be given a brief evaluation by one of the GTAs, who will consider: whether your implementation makes appropriate use of data structures (in particular, the use of a well-designed stack for the RPN parsing), and whether the internal documentation of your code is acceptable. This evaluation will produce a deduction (possibly zero, of course) that will be applied to your runtime testing score to produce your final score for the project. Programming Standards: While we won t be carefully evaluating your source code on this assignment for programming style, you should still observe good practice. See the Programming Standards page on the course website for specific requirements that should be observed in this course. Pledge: Each of your program submissions must be pledged to conform to the Honor Code requirements for this course. Specifically, you must include the following pledge statement in the header comment for your program: On my honor: - I have not discussed the C++ language code in my program with anyone other than my instructor or the teaching assistants assigned to this course. - I have not used C++ language code obtained from another student, or any other unauthorized source, either modified or unmodified. - If any C++ language code or documentation used in my program was obtained from another source, such as a text book or course notes, that has been clearly noted with a proper citation in the comments of my program. - I have not designed this program in such a way as to defeat or interfere with the normal operation of the Curator System. <Student Name> Failure to include this pledge in a submission is a violation of the Honor Code. Due: 23:59:59 Monday, July 10 Page 5 of 5