Difference between revisions of "CISC220 F2023 Lab3"

From class_wiki
Jump to: navigation, search
(Submission)
(Requirements)
 
(15 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
'''(5 points)''' Using the [https://cplusplus.com/reference/stack/stack/ STL stack class], implement a ''postfix expression evaluator'' as discussed in class on 9/12.  Your program should take a single input filename on the command line, which will contain a single expression on the first line of the file.  Ignore anything and everything after this first line.  Expressions consist of decimal numbers (doubles) and any of 8 symbols/strings representing operators, all separated by whitespace.   
 
'''(5 points)''' Using the [https://cplusplus.com/reference/stack/stack/ STL stack class], implement a ''postfix expression evaluator'' as discussed in class on 9/12.  Your program should take a single input filename on the command line, which will contain a single expression on the first line of the file.  Ignore anything and everything after this first line.  Expressions consist of decimal numbers (doubles) and any of 8 symbols/strings representing operators, all separated by whitespace.   
  
5 symbols are <tt>+</tt>, <tt>-</tt>, <tt>*</tt>, <tt>/</tt>, and <tt>^</tt> for ''binary'' addition, subtraction, multiplication, division, and exponentiation, respectively.  3 strings represent ''unary'' operators: <tt>sqrt</tt>, <tt>log</tt>, and <tt>log10</tt>, for the square root operation, natural log, and log base 10, respectively.   
+
Of the 8 operators, 5 are symbols: <tt>+</tt>, <tt>-</tt>, <tt>*</tt>, <tt>/</tt>, and <tt>^</tt> for ''binary'' addition, subtraction, multiplication, division, and exponentiation, respectively.  3 are strings representing ''unary'' (1-argument) operators: <tt>sqrt</tt>, <tt>log</tt>, and <tt>log10</tt>, for the square root operation, natural log, and log base 10, respectively.   
  
 
You will evaluate these expressions with double precision using the stack-based approach below, and output your final answer rounded to the nearest integer with cout.  Print your result number in fixed precision with no decimal (i.e., it should look like an integer).
 
You will evaluate these expressions with double precision using the stack-based approach below, and output your final answer rounded to the nearest integer with cout.  Print your result number in fixed precision with no decimal (i.e., it should look like an integer).
Line 14: Line 14:
 
** Attempting to pop when the stack is empty  
 
** Attempting to pop when the stack is empty  
 
** Not having exactly one number in the stack at the end of evaluation
 
** Not having exactly one number in the stack at the end of evaluation
** An input which is neither a number nor from the symbol set
+
** An input which is neither a number nor from the operator symbol/string set
 
** A number which is too large to represent as double
 
** A number which is too large to represent as double
** An operation which results in something that is either infinite or "not a number."
+
** An operation which results in something that is either infinite or "not a number"
  
* A handful of test input files and correct output for them are providedYou should create many more of your own to thoroughly test your solution. '''The Gradescope autograder tests will not be available until at least Sunday'''
+
Some example inputs and outputs:
* The required functions above are the minimum -- you may create additional "helper" functions and/or member variables as needed. No STL or outside libraries may be referenced in your <tt>SL_List</tt> class.
+
{| class="wikitable" style="margin-left:5px"
* You may optionally work with a partner on this assignment.  Any late days used will be subtracted from both of your balances.
+
|-
 +
! Input !! Output
 +
|-
 +
| 3 4 + || 7
 +
|-
 +
| 4 5 2 - * || 12
 +
|-
 +
| 2 8 ^ || 256
 +
|-
 +
| 7 1.3 - || 6
 +
|-
 +
| 19 1.95 / || 10
 +
|-
 +
| 1 0 / || ERROR
 +
|-
 +
| 4 sqrt || 2
 +
|-
 +
| 2.718 log || 1
 +
|-
 +
| 2.718 log10 || 0
 +
|}
 +
 
 +
No official starter code is provided, but feel free to copy from the provided code for Lab #1 or #2.
 +
Your code file should be called <tt>stl_stack_postfix.cpp</tt>.  Your main function should return 1.
 +
 
 +
No partner is allowed on this assignment, but '''you may use AI tools for any and all of it'''If you do, I expect a detailed report in your README on what you did, comments and citations in your code, and a discussion of the pros and cons of the whole experience.
  
 
==Submission==
 
==Submission==
  
* Once again, you will submit two files completely through Gradescope: (1) "README" and (2) <tt>stl_stack_postfix.cpp</tt>.  As before, the README should contain any AI tool citations/explanations, notes on any limitations or issues with your code, your interpretation of any ambiguities in the assignment instructions, and the names of yourself and your partner if you had one.  The code file should also have your name(s) and AI citations per the syllabus.
+
* Once again, you will submit two files completely through Gradescope: (1) <tt>README</tt> and (2) <tt>stl_stack_postfix.cpp</tt>.  As before, the README should contain your name, any AI tool citations/explanations, notes on any limitations or issues with your code, and your interpretation of any ambiguities in the assignment instructions.  The code file should also have your name and AI citations per the syllabus.
 
* Resubmit as many times as you like until the deadline, but be aware that the submission window is kept open for some students to use late days, so a resubmission 2 days after the deadline is not free.
 
* Resubmit as many times as you like until the deadline, but be aware that the submission window is kept open for some students to use late days, so a resubmission 2 days after the deadline is not free.
 
* The 5 possible points assigned by the autograder are provisional.  They are not final until published and they may be revised if we determine that your code and/or README do not satisfy the assignment requirements even though they pass the tests.  In rare cases, we may also revise your grade upward if we believe that the score you received does not reflect the work you put into the assignment.
 
* The 5 possible points assigned by the autograder are provisional.  They are not final until published and they may be revised if we determine that your code and/or README do not satisfy the assignment requirements even though they pass the tests.  In rare cases, we may also revise your grade upward if we believe that the score you received does not reflect the work you put into the assignment.

Latest revision as of 10:51, 14 September 2023

Requirements

(5 points) Using the STL stack class, implement a postfix expression evaluator as discussed in class on 9/12. Your program should take a single input filename on the command line, which will contain a single expression on the first line of the file. Ignore anything and everything after this first line. Expressions consist of decimal numbers (doubles) and any of 8 symbols/strings representing operators, all separated by whitespace.

Of the 8 operators, 5 are symbols: +, -, *, /, and ^ for binary addition, subtraction, multiplication, division, and exponentiation, respectively. 3 are strings representing unary (1-argument) operators: sqrt, log, and log10, for the square root operation, natural log, and log base 10, respectively.

You will evaluate these expressions with double precision using the stack-based approach below, and output your final answer rounded to the nearest integer with cout. Print your result number in fixed precision with no decimal (i.e., it should look like an integer).

  • If a number is read, push it on the stack
  • If an operator is read...
    • If binary, pop the top two numbers on the stack, apply the operator, and push the result
    • If unary, pop the top number on the stack, apply the operator, and push the result
  • If any of the below errors are detected, print "ERROR":
    • Attempting to pop when the stack is empty
    • Not having exactly one number in the stack at the end of evaluation
    • An input which is neither a number nor from the operator symbol/string set
    • A number which is too large to represent as double
    • An operation which results in something that is either infinite or "not a number"

Some example inputs and outputs:

Input Output
3 4 + 7
4 5 2 - * 12
2 8 ^ 256
7 1.3 - 6
19 1.95 / 10
1 0 / ERROR
4 sqrt 2
2.718 log 1
2.718 log10 0

No official starter code is provided, but feel free to copy from the provided code for Lab #1 or #2. Your code file should be called stl_stack_postfix.cpp. Your main function should return 1.

No partner is allowed on this assignment, but you may use AI tools for any and all of it. If you do, I expect a detailed report in your README on what you did, comments and citations in your code, and a discussion of the pros and cons of the whole experience.

Submission

  • Once again, you will submit two files completely through Gradescope: (1) README and (2) stl_stack_postfix.cpp. As before, the README should contain your name, any AI tool citations/explanations, notes on any limitations or issues with your code, and your interpretation of any ambiguities in the assignment instructions. The code file should also have your name and AI citations per the syllabus.
  • Resubmit as many times as you like until the deadline, but be aware that the submission window is kept open for some students to use late days, so a resubmission 2 days after the deadline is not free.
  • The 5 possible points assigned by the autograder are provisional. They are not final until published and they may be revised if we determine that your code and/or README do not satisfy the assignment requirements even though they pass the tests. In rare cases, we may also revise your grade upward if we believe that the score you received does not reflect the work you put into the assignment.