Reference no: EM133013879
CPSC 231: Introduction to Computer Science
Assignment: Graphing Calculator
Collaboration
Discussing the assignment requirements with others is a reasonable thing to do, and an excellent way to learn. However, the work you hand-in must ultimately be your work. This is essential for you to benefit from the learning experience, and for the instructors and TAs to grade you fairly. Handing in work that is not your original work, but is represented as such, is plagiarism and academic misconduct. Penalties for academic misconduct are outlined in the university calendar.
Here are some tips to avoid plagiarism in your programming assignments.
1. Cite all sources of code that you hand-in that are not your original work. You can put the citation into comments in your program. For example, if you find and use code found on a web site, include a comment that says, for example:
# the following code .
Use the complete URL so that the marker can check the source.
2. Citing sources avoids accusations of plagiarism and penalties for academic misconduct. However, you may still get a low grade if you submit code that is not primarily developed by yourself. Cited material should never be used to complete core assignment specifications. You can and should verify and code you are concerned with your instructor/TA before submit.
3. Discuss and share ideas with other programmers as much as you like, but make sure that when you write your code that it is your own. A good rule of thumb is to wait 20 minutes after talking with somebody before writing your code. If you exchange code with another student, write code while discussing it with a fellow student, or copy code from another person's screen, then this code is not yours.
4. Collaborative coding is strictly prohibited. Your assignment submission must be strictly your code. Discussing anything beyond assignment requirements and ideas is a strictly forbidden form of collaboration. This includes sharing code, discussing code itself, or modelling code after another student's algorithm. You can not use (even with citation) another student's code.
5. Making your code available, even passively, for others to copy, or potentially copy, is also plagiarism.
6. We will be looking for plagiarism in all code submissions, possibly using automated software designed for the task.
Part 1: get_color:
First, complete the colour-determination function get_color. This function takes the counter tracked in the expression input loop and returns one of three different colours: red, green, or blue. You should find the remainder division operator (also called modulus) helpful here because it allows you to change an infinitely increasing integer sequence into a range of integers.
There are 3 sub-functions to this part. Each does not take a lot of code, but needs to be mathematically sound.
First, complete the coordinate conversion function calc_to_screen_coord. This function uses the parameters that the main function obtains user defined pixel coordinate system (x_origin, y_origin, ratio), along with a calculator coordinate system (????, ????) to perform the conversion. The (x_origin, y_origin) is the pixel coordinates of where (0, 0) in the calculator should be located on screen, and ratio is how many pixels are equal to 1 in the calculator coordinate system. calc_to_screen_coord returns the (x, y) coordinate as a pixel screen coordinate (screen_x, screen_y) following the math described previously in the example. Use this function in your code any time you want to convert and draw a calculator location. You will lose marks if you duplicate the math/code functionality of this function somewhere else instead of using this function designed for that purpose.
Part 4: draw_expression
Finally, you will draw the actual expression that the user inputted. Python can evaluate a string using its eval function. Your code does not need to be capable of anything more than the eval function can do. For example, the following 3-line program is a simple calculator that works for input like "1+1":
expression = input("Enter an arithmetic expression: ") result = eval(expression)
print("The result of that expression is", result)
Python is also able to evaluate expressions which include a single variable x. The implementation of this function can be surprising at first. When the eval function is called, it uses whatever value is stored in the variable called x to evaluate the given expression.
To make things easier a calc function has already been completed that will take an expression and an x and return the y value. (Ex. y = calc(expression, x)). You will use the eval() method to do all of your math for you for the calculator. You will notice that we have the import at the top from math import * which allows eval() to use things like cos/sin.
As a result, your program will need to include a variable named x, which represents the x coordinate in the calculator coordinate system. The value of x will change in a loop. Call calc inside of the loop so that you can compute the value of y for many different x values. For example, the following program evaluates an expression that includes the variable x for each integer value of x from 0 up to and including 5:
expr = input("Enter an arithmetic expression: ") for x in range(0, 6):
y = calc(expr, x)
print("When x is", x, "the value of the expression is", y)
You can use a similar technique to compute the y position of the curve for many different values of x. Those x and y values are what you need to draw short lines with turtle that will visually emulate the expression's lines and possible curvature.
You cannot complete this function correctly unless the previous functions are operational. In particular, it will be useful to use calc_minmax_x to determine which values of x you want to draw a line between. You will need to pick a delta that makes the curve smooth. A delta of 0.1 or 0.2 should provide sufficient smoothness. Note that, once you are using floating point values for your steps size, you will be unable to use a for-range() loop to loop through them but instead should use a while loop.
Attachment:- Graphing Calculator.rar