Question

Calculator Project

Assignment

You will be designing a calculator complete with user interface to take input from the user, process a response, and produce the output.

Step 1: Present a menu

First thing you should do is present a menu to the user when your program is first ran. Make sure that the operations match the numbers presented below, otherwise the graders won't be able to grade your program.

1. Cartesian distance
2. Vector x matrix
3. Normalize
4. Quit
Enter command:

You will present the menu and wait for the user to input their desired calculation.

It will be easier if you break this up into 6 separate print statements:

print("1. Cartesian distance")
print("2. Vector x matrix")

Recall that print writes the string followed by a newline character to the user and input can take input from the user. For the final prompt, you will want the user to write just to the right of the : followed by a space. Recall that input() can take a string parameter, which will be the prompt to be specified, such as input("Enter command: "). Notice I put a space between the : and the ". This is so that the user writes just to the right of the prompt.

Keep in mind that you need to present this menu every time the user completes a calculation until they select quit.

Step 2: Ask the user for further input

Presenting the menu and letting the user choose is just the first step. However, each calculation will be different, so if you need further input, ask for it. DO NOT CHANGE THE ORDER OF THE VARIABLES FROM BELOW. If you do, then the grader will have a difficult time grading your project since they are expecting the inputs to be specified in a particular order.

For cartesian distance: You need to have four floating point inputs: x1, y1 and x2, y2.

For vector x matrix: You will need 3 floating point inputs for the vector followed by 9 row-major, floating point inputs for the matrix, for a total of 12 floating point. Row major means that m11, m12, and m13 will be the first three floats for the matrix input (i.e., the row is specified first) followed by m21, m22, m23, m31, m32, and m33.

For normalize: You will need 3 floating point inputs for the vector. Normalize will transform a vector into a "unit length" where every value is a fraction of its original value from 0.0 to 1.0.

Ask for input from the user all on one line. This will require you to use input(). Recall that input() will return to you the entire line. However, you will separate the user's input by spaces. You can transform one large string into many segments using input().split(" "). This will create a list of strings. For example, if the user types: 1.0 2.0 3.0, your input() will create a string as "1.0 2.0 3.0". That doesn't help us since we need to be able to get three individual floats. So, we can do: values = input().split(" "). This will now create a list as: ["1.0", "2.0", "3.0"]. We now have converted the large string into three smaller strings. However, recall that we want these to be floats. We can do this several ways, but we can do something like:

for i in range(len(values)):
   values[i] = float(values[i])

This will transform each string into its floating point equivalent. Take note that this will not double check the user's work.

Step 3: Process the result

Now that you have the chosen operation and the operands, produce the result.

Cartesian distance. You may need the math import for this, in particular for the square root function. However, you can also produce the square root by using the ** (power) operator with 0.5. Recall that raising a power to 1/2 means to take the square root of it. However, to make your code more readable, I would suggest using the math module and in particular, the sqrt function inside of it.

the_sqrt = math.sqrt(value)

The cartesian distance is given as the following formula: LaTeX: \sqrt{(x_2-x_1)^2+(y_2-y_1)^2}( x 2  x 1 ) 2 + ( y 2  y 1 ) 2

Vector x matrix: You will multiply a 3x3 matrix by a 3-value vector. Notice the pattern of the formula below and use a loop to solve this. Do not hard code all of the calculations. 

LaTeX: \begin{bmatrix}
    m_{11} & m_{12} & m_{13} \\
    m_{21} & m_{22} & m_{23} \\
    m_{31} & m_{32} & m_{33} \\
\end{bmatrix}
\times
\begin{bmatrix}
v_1 \\
v_2 \\
v_3
\end{bmatrix}
=
\begin{bmatrix}
m_{11} \times v_1 + m_{12} \times v_2 + m_{13} \times v_3 \\
m_{21} \times v_1 + m_{22} \times v_2 + m_{23} \times v_3 \\
m_{31} \times v_1 + m_{32} \times v_2 + m_{33} \times v_3
\end{bmatrix}[ m 11 m 12 m 13 m 21 m 22 m 23 m 31 m 32 m 33 ] × [ v 1 v 2 v 3 ] = [ m 11 × v 1 + m 12 × v 2 + m 13 × v 3 m 21 × v 1 + m 22 × v 2 + m 23 × v 3 m 31 × v 1 + m 32 × v 2 + m 33 × v 3 ]

Normalize will take a 3-value vector and shrink it to unit length. To do this, use the following formula:

LaTeX: \text{length}=\sqrt{(v_1)^2+(v_2)^2+(v_3)^2} length = ( v 1 ) 2 + ( v 2 ) 2 + ( v 3 ) 2

After you calculate the length, you divide each element of the vector by length:

LaTeX: \text{normal vector} = [\frac{v_1}{\text{length}}, \frac{v_2}{\text{length}}, \frac{v_3}{\text{length}}]normal vector = [ v 1 length , v 2 length , v 3 length ]

There is a module called numpy that performs a lot of these operations. However, I want you to do this manually so that you can see the power of Python while performing legitimate mathematical operations.

Step 4: Output the result

Output the result the user requested.

Step 5: Repeat

Until the user chooses "quit", keep repeating calculations.

One thing to keep in mind is always to error check the user. Don't let them crash your program, and always ask the user to reinput values that were not properly inputted.


0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Calculator Project
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Assignment Input from the user 9, 64-bit, floating-point values as a 3x3, row-major, multi-dimensional array. This...

    Assignment Input from the user 9, 64-bit, floating-point values as a 3x3, row-major, multi-dimensional array. This will be the 3x3 matrix. Then, input 3, 64-bit, floating-point values. This will be a single-dimensional array and is the vector. Your program will simply ask the user to enter matrix values. Remember, there are 9 of these, but they need to be stored into a 3x3 multi-dimensional array (row-major). Then, your program will ask for the vector values, which will be stored into...

  • In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and...

    In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and use recursive functions In this lab, we will write a program that uses three recursive functions. Requirements: Important: You must use the array for this lab, no vectors allowed. First Recursive Function Write a function that recursively prints a string in reverse. The function has ONLY one parameter of type string. It prints the reversed character to the screen followed by a newline character....

  • For Project 02 you’re going to take starter code I’m providing (See in BlackBoard under Projects->Project...

    For Project 02 you’re going to take starter code I’m providing (See in BlackBoard under Projects->Project 02). The zip file contains a P02.java, a HelperClass.java, and an enumeration under Money.java. The only coding you’ll do will be in P02.java. I’ve already provided you with the menu and switch as well as all the methods you’ll need stubbed out. Your assignment is to take the program and complete it without adding any more methods but merely adding code to those stubbed...

  • For this project you will implement a simple calculator. Your calculator is going to parse infix...

    For this project you will implement a simple calculator. Your calculator is going to parse infix algebraic expressions, create the corresponding postfix expressions and then evaluate the postfix expressions. The operators it recognizes are: +, -, * and /. The operands are integers. Your program will either evaluate individual expressions or read from an input file that contains a sequence of infix expressions (one expression per line). When reading from an input file, the output will consist of two files:...

  • The assignment In this assignment you will take the Matrix addition and subtraction code and modify...

    The assignment In this assignment you will take the Matrix addition and subtraction code and modify it to utilize the following 1. Looping user input with menus in an AskUserinput function a. User decides which operation to use (add, subtract) on MatrixA and MatrixB b. User decides what scalar to multiply MatrixC by c. User can complete more than one operation or cancel. Please select the matrix operation 1- Matrix Addition A+ B 2-Matrix Subtraction A-B 3Scalar Multiplication sC 4-Cancel...

  • 23.4 Project 4: Using Pandas for data analysis and practice with error handling Python Please! 23.4...

    23.4 Project 4: Using Pandas for data analysis and practice with error handling Python Please! 23.4 PROJECT 4: Using Pandas for data analysis and practice with error handling Overview In this project, you will use the Pandas module to analyze some data about some 20th century car models, country of origin, miles per gallon, model year, etc. Provided Input Files An input file with nearly 200 rows of data about automobiles. The input file has the following format (the same...

  • /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid...

    /*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid input examples: F00D, 000a, 1010, FFFF, Goodbye, BYE Enter BYE (case insensitive) to exit the program. ****************************************************/ import java.util.Scanner; public class HexUtilitySOLUTION { public static void main(String[] args) { // Maximum length of input string final byte INPUT_LENGTH = 4; String userInput = ""; // Initialize to null string Scanner input = new Scanner(System.in); // Process the inputs until BYE is entered do {...

  • please write C++ code to finish R0,R1,R2 Introduction In this assignment, you are going to develop...

    please write C++ code to finish R0,R1,R2 Introduction In this assignment, you are going to develop a "Schedule Book System that runs in the command line environment. The system stores the schedule of events input by user and allows users to add view or delete events. You can assume that the system can at most store 100 events Each group is required to write a Win32 Console Application program called ScheduleBook.cpp The requirements are listed below. RO When the program...

  • Python GPA calculator: Assume the user has a bunch of courses they took, and need to...

    Python GPA calculator: Assume the user has a bunch of courses they took, and need to calculate the overall GPA. We will need to get the grade and number of units for each course. It is not ideal to ask how many courses they took, as they have to manually count their courses. Programming is about automation and not manual work. We will create a textual menu that shows 3 choices. 1. Input class grade and number of units. 2....

  • Sample Execution – Level 3 Welcome to your Menu Creation system. How many items would you...

    Sample Execution – Level 3 Welcome to your Menu Creation system. How many items would you like to have on your menu? 2 Create your menu! Enter item #1: Coffee Enter the number of toppings: 2 Enter topping #1: Whipped Cream Enter topping #2: Cinnamon Enter item #2: Tea Enter the number of toppings: 2 Enter topping #1: Milk Enter topping #2: Sugar May I take your order? This is the menu: Coffee Tea Pop How many items would you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT