Project 0: Pocket Calculator (Intro to C++)

Released September 1, 2023 at 4:30 PM

Due September 22, 2023 at 11:59 PM.

Table of Contents

  1. Project Description
  2. Getting the Code
  3. Grading Breakdown
  4. Advanced Extensions
  5. Checking Your Work

Project Description

The project description is available on the Robotics 102 main website: Project 0: Pocket Calculator

Getting the Code

We will use Replit for Project 0. To accept the assignment, navigate to the ROB 102 Replit team and open Project 0: Pocket Calculator.

Follow the Replit Instructions to learn how to write, run, test, and submit your code.

Grading Breakdown

Grades will be assigned based on the following features for analyzing the peformance of your C++ program.

  • P0.0 (1 point): In the file LICENSE.txt included in the project template, replace <COPYRIGHT HOLDER> with your name. Replace <YEAR> with the current year.

  • P0.1 (3 points): Perform arithmetic operations in C++ that can add, subtract, multiply, and divide for two floating point operands and print these operands, the operation, and operation result to the screen in infix notation.

  • P0.2 (3 points): Prompt the user for inputs into the calculator. The program should take as input real valued numbers for the operands, and characters for operators, and store these values in variables.

  • P0.3 (3 points): Executes a function in C++ that performs an arbitrary single arithmetic operation. The function must be given at least three parameters: two of which are two floating point operands for the operation, one of which is a character that specifies the operation to be performed. The function must provide the result of the operation after it is called for execution. This function should output an error message if a division by zero could be performed.

  • P0.4 (3 points): Iterate over an execution loop that performs an infinite number of subsequent arithmetic operations given from user input, until the user specifies the operator ‘q’ for quit. Output the result accumulated over subsequently performed operations. This output must conform to the tests provided in the template.

  • P0.5 (2 points): Check whether the user has provided valid input for the operator. If the input is invalid, display an error message and request the input again.

Advanced Extensions

Advanced extensions are optional features which you may complete to explore this assignment further.

UPDATE: Implementing some of the advanced extensions will break the behavior required for the standard project. Because of this we will ask you to implement advanced extension, demo to a staff member for points, and then return your code to the state that passes the standard tests to be be graded for the project.

  • Advanced Extension P0.i (0.4 Points): Enable the user to clear the calculator by specifying ‘c’ as the operator.

  • Advanced Extension P0.ii (0.4 Points): Enable the user to undo their last operation by specifying ‘u’ as the operator.

  • Advanced Extension P0.iii (0.4 Points): Output the result of the user arithmetic expression with parentheses corresponding to the order of operations used by the calculator. The calculaor uses sequential order of operations, for example 4 + 2 * 3 = 18. Write out parentheses corresponding to this order of operations, for example ((4 + 2) * 3)) = 18.

  • Advanced Extension P0.iv (0.4 Points): Compute the final result of the user specified arithmetic expression using the PEMDAS Order of Operations. This requires using a different order of operations such that, for example 4 + 2 * 3 = 10. No parentheses need to be output for this project.

  • Advanced Extension P0.v (0.4 Points): Enable the user to store and load their current set of operations through a file named “resultcalc.txt” such that this equation can be used across multiple program executions.

Checking Your Work

You can test your code using the tests provided for the project on replit as shown below. Go to the replit page and expand the “Tools” dropdown in the bottom left. Scroll in this panel until you see “Tests”.

You should see a menu pop up on the right side of your screen as shown below. Click “Run Tests” to test your code.

Notice that these tests don’t cover the whole rubric. They are intended to help you check your work, but they won’t catch everything. Be sure to reference the grading breakdown as you work on your project.

We will use these tests as well as other tests and manual inspection to grade your project. It is possible to write code to only target these tests without actually adhering to the specification. Please don’t do this, we will read every submission!