New

Learn smart - Learn online. Upto 88% off on courses for a limited time. View Courses

Securing Higher Grades Costing Your Pocket? Book Your Assignment at The Lowest Price Now!
loader
Add File

Error goes here

Files Missing!

Please upload all relevant files for quick & complete assistance.

Guaranteed Higher Grade!

Stuck on Your Question?

Get 24x7 live help from our Top Tutors. All subjects covered.

loader
250 words

Error goes here

Files Missing!

Please upload all relevant files for quick & complete assistance.

Students Who Viewed This Also Studied

7 Pages
ISBS202 Programming Concepts

Question: You in groups of 3 will develop a program design using a number of methodologies and produce a report. The report worth 20% will include defining diagram, control structures required, ps ...

Course

ISBS202

Type

Programming

Subject

Programing

University

Canterbury Institute of Management

0 Page
Virtual Image

...

Course

ENTD200

Subject

Programing

University

American Military university

Season

Fall

0 Page
OWASP Vulnerabilities

...

Course

MOD006363

Subject

Programing

University

Anglia Ruskin University

Season

Spring

0 Page
Measures to Injection Attacks

...

Course

MOD006363

Subject

Programing

University

Anglia Ruskin University

Season

Spring

CPSC 231 - Introduction to Computer Science for Computer Science

Question

Answered

Charting Expressions (Graphing Calculator) You will be creating a small graphical Python 3 program. This program will use the turtle library to draw based on information taken from the user. You should already have all the experience you need with this library from Assignment 1. The assignment requires an additional understanding of converting between Cartesian coordinate systems, using loops, and completing functions as outlined by someone else. You will be provided with a starter code that already implements the basic interaction with the user (something you learned in the previous assignment). This code consists of a completed main function, which sets up the window using a setup function. Neither of these functions should be changed. The main function makes use of several incomplete functions. Your assignment is to complete these functions so that the main function can use them to draw what the user requests. All your code should be written within the incomplete functions. You are allowed to create constants and new functions as long as they are not redundant to existing ones. There should be no global variables in your code (except if you are doing the bonus). There is a bonus that involves identify local minima/maxima and labelling them described at the end of the assignment. Your program will be drawing in an 800-pixel by 600-pixel window with (0,0) as the bottom left corner and (800,600) as the top right corner. The starter code has a setup() function, which setups up the window and returns the turtle drawing object pointer so you can use it. This pointer is passed into the existing starter code functions for you to use. The included starter code already prompts the user for the pixel coordinates for where the chart origin should be placed in the window. The code then prompts the user for a ratio of how many pixels are 1 step of the chart. For example, an origin of = (400,300) should be the centre of the screen. If the ratio of pixels per single step is 100 pixels per step. Then a position one step up from the origin point to (????, ????) = (0,1) in the charting coordinate system is (400 + 100 ? 0,300 + 100 ? 1) = (400,300 + 100) = (400,400). Below is an image of 3 curves drawn for a chart with an origin at 400,300 and a ratio of 30. The existing starter code uses the included (but incomplete) functions to draw the x and y axes in black, and then loops to get expressions from the user. The colour used to draw an expression is determined based on the number of previously drawn expressions. So, you must track this number using a counter variable. Your task is to complete the included functions, so they function in the way that the comments and assignment description require. You will likely find the visual examples of operation included in the assignment description helpful. I recommend approaching the functions in stages: Part 1: screenCoor: First, complete the coordinate conversion function screenCoor. This function uses the parameters that the main function obtains from the user, along with an (x,y) coordinate to perform the conversion. It returns this coordinate as a pixel screen coordinate following the math described above in the example. Use this function in your code any time you want to plot a chart location. You will lose marks if you duplicate the code functionality of this function somewhere else instead of calling it. Part 2: getColor: Second, complete the colour-determination function getColor. 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 operator (also called modulus) helpful here because it allows you to change an infinitely increasing integer sequence into a range of integers. Part 3: drawXAxis, drawYAxis Third, complete the two functions that draw the x and y axes. These two functions are structurally similar, so complete one of them first then you can easily complete the other function. If you choose the x-axis, initially you can ignore updating the return values for xmin and xmax. You should be able to add these in later once you have the drawing working. When first drawing your axes, you can ignore the tick marks and labels. These can also be added in once you have the lines drawn successfully. My advice is to use two loops. Start at the chart origin (0,0) and use a loop to move 1 chart step away. Convert this point from a chart location into a screen location. Draw a line from the previous point to the current point. Once you draw to a location outside the screen, then stop looping. Go back to the origin and draw in the other direction. Once you can draw this line step by step, you should notice that you are stopping at each label/tick location. Make a call to the associated label/tick draw function included in the assignment. Then fill in the code of this function to draw the tick/labels. Once you complete the drawing part of the drawXAxis function, you will want to ensure the xmin and xmax hold the correct values when the function completes. These two values start at 0,0 for the chart origin location. You should update these values any time you draw at a chart x-location when drawing the axis. If the x-location is less than xmin update it, if it is greater than xmax then update it. You can use the min(),max() functions to do this, or simply use conditional statements if you desire. Part 4: drawExpr Finally, you will draw the actual expression that the user inputted. Python can evaluate a string using its eval function. For example, the following 3-line program is a simple calculator: 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. As a result, your program will need to include a variable named x, which represents the x coordinate in the Cartesian coordinate system. The value of x will change in a loop. Call eval 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 = eval(expr) 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 the curve. You cannot complete this function correctly unless the previous functions are operational. Use the xmin and xmax that were determined in your previous function to loop through x-coordinates of the curve. You will need to pick a delta that makes the curve smooth. A delta of 0.1 or 0.2 should provide sufficient smoothness. Since you will be stepping through floating-point numbers, you will need to use a while loop instead of a for loop. Note: Two challenges you may have as you implement expression drawing are: (1) parts of the expression that exist outside the visible drawing window and, (2) discontinuities in expressions (Ex. tan(x)). For expressions outside the draw window, you are free to draw these parts of the expression, or implement conditionals that will avoid drawing them. For expressions with discontinuities, or undefined points, you can write your code under the knowledge they will either not be considered valid input, or if they are given as input, then the discontinuity does not have to be drawn. Ex. tan(x) will be drawn with a line connecting across the vertical discontinuity that exists at every odd multiple of ? ? .

CPSC 231 - Introduction to Computer Science for Computer Science

Answer in Detail

Solved by qualified expert

Get Access to This Answer

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Hac habitasse platea dictumst vestibulum rhoncus est pellentesque. Amet dictum sit amet justo donec enim diam vulputate ut. Neque convallis a cras semper auctor neque vitae. Elit at imperdiet dui accumsan. Nisl condimentum id venenatis a condimentum vitae sapien pellentesque. Imperdiet massa tincidunt nunc pulvinar sapien et ligula. Malesuada fames ac turpis egestas maecenas pharetra convallis posuere. Et ultrices neque ornare aenean euismod. Suscipit tellus mauris a diam maecenas sed enim. Potenti nullam ac tortor vitae purus faucibus ornare. Morbi tristique senectus et netus et malesuada. Morbi tristique senectus et netus et malesuada. Tellus pellentesque eu tincidunt tortor aliquam. Sit amet purus gravida quis blandit. Nec feugiat in fermentum posuere urna. Vel orci porta non pulvinar neque laoreet suspendisse interdum. Ultricies tristique nulla aliquet enim tortor at auctor urna. Orci sagittis eu volutpat odio facilisis mauris sit amet.

Tellus molestie nunc non blandit massa enim nec dui. Tellus molestie nunc non blandit massa enim nec dui. Ac tortor vitae purus faucibus ornare suspendisse sed nisi. Pharetra et ultrices neque ornare aenean euismod. Pretium viverra suspendisse potenti nullam ac tortor vitae. Morbi quis commodo odio aenean sed. At consectetur lorem donec massa sapien faucibus et. Nisi quis eleifend quam adipiscing vitae proin sagittis nisl rhoncus. Duis at tellus at urna condimentum mattis pellentesque. Vivamus at augue eget arcu dictum varius duis at. Justo donec enim diam vulputate ut. Blandit libero volutpat sed cras ornare arcu. Ac felis donec et odio pellentesque diam volutpat commodo. Convallis a cras semper auctor neque. Tempus iaculis urna id volutpat lacus. Tortor consequat id porta nibh.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Hac habitasse platea dictumst vestibulum rhoncus est pellentesque. Amet dictum sit amet justo donec enim diam vulputate ut. Neque convallis a cras semper auctor neque vitae. Elit at imperdiet dui accumsan. Nisl condimentum id venenatis a condimentum vitae sapien pellentesque. Imperdiet massa tincidunt nunc pulvinar sapien et ligula. Malesuada fames ac turpis egestas maecenas pharetra convallis posuere. Et ultrices neque ornare aenean euismod. Suscipit tellus mauris a diam maecenas sed enim. Potenti nullam ac tortor vitae purus faucibus ornare. Morbi tristique senectus et netus et malesuada. Morbi tristique senectus et netus et malesuada. Tellus pellentesque eu tincidunt tortor aliquam. Sit amet purus gravida quis blandit. Nec feugiat in fermentum posuere urna. Vel orci porta non pulvinar neque laoreet suspendisse interdum. Ultricies tristique nulla aliquet enim tortor at auctor urna. Orci sagittis eu volutpat odio facilisis mauris sit amet.

Tellus molestie nunc non blandit massa enim nec dui. Tellus molestie nunc non blandit massa enim nec dui. Ac tortor vitae purus faucibus ornare suspendisse sed nisi. Pharetra et ultrices neque ornare aenean euismod. Pretium viverra suspendisse potenti nullam ac tortor vitae. Morbi quis commodo odio aenean sed. At consectetur lorem donec massa sapien faucibus et. Nisi quis eleifend quam adipiscing vitae proin sagittis nisl rhoncus. Duis at tellus at urna condimentum mattis pellentesque. Vivamus at augue eget arcu dictum varius duis at. Justo donec enim diam vulputate ut. Blandit libero volutpat sed cras ornare arcu. Ac felis donec et odio pellentesque diam volutpat commodo. Convallis a cras semper auctor neque. Tempus iaculis urna id volutpat lacus. Tortor consequat id porta nibh.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Hac habitasse platea dictumst vestibulum rhoncus est pellentesque. Amet dictum sit amet justo donec enim diam vulputate ut. Neque convallis a cras semper auctor neque vitae. Elit at imperdiet dui accumsan. Nisl condimentum id venenatis a condimentum vitae sapien pellentesque. Imperdiet massa tincidunt nunc pulvinar sapien et ligula. Malesuada fames ac turpis egestas maecenas pharetra convallis posuere. Et ultrices neque ornare aenean euismod. Suscipit tellus mauris a diam maecenas sed enim. Potenti nullam ac tortor vitae purus faucibus ornare. Morbi tristique senectus et netus et malesuada. Morbi tristique senectus et netus et malesuada. Tellus pellentesque eu tincidunt tortor aliquam. Sit amet purus gravida quis blandit. Nec feugiat in fermentum posuere urna. Vel orci porta non pulvinar neque laoreet suspendisse interdum. Ultricies tristique nulla aliquet enim tortor at auctor urna. Orci sagittis eu volutpat odio facilisis mauris sit amet.

Tellus molestie nunc non blandit massa enim nec dui. Tellus molestie nunc non blandit massa enim nec dui. Ac tortor vitae purus faucibus ornare suspendisse sed nisi. Pharetra et ultrices neque ornare aenean euismod. Pretium viverra suspendisse potenti nullam ac tortor vitae. Morbi quis commodo odio aenean sed. At consectetur lorem donec massa sapien faucibus et. Nisi quis eleifend quam adipiscing vitae proin sagittis nisl rhoncus. Duis at tellus at urna condimentum mattis pellentesque. Vivamus at augue eget arcu dictum varius duis at. Justo donec enim diam vulputate ut. Blandit libero volutpat sed cras ornare arcu. Ac felis donec et odio pellentesque diam volutpat commodo. Convallis a cras semper auctor neque. Tempus iaculis urna id volutpat lacus. Tortor consequat id porta nibh.

31 More Pages to Come in This Document. Get access to the complete answer.

MyAssignmenthelp.com possesses the expertise of providing affordable homework help while keeping the quality of papers intact. Hence, students prefer to buy homework assignments from us as they get highest quality help at cheap prices. Our online homework makers are trained to accomplish any homework perfectly within any short deadline. MyAssignmenthelp.com has proved to be the best solution to all those who often request, I need help with homework assignments.

More CPSC 231 - Introduction to Computer Science for Computer Science : Questions & Answers

Q
icon

We aren't endorsed by this University

ISBS202 Programming Concepts

Question: You in groups of 3 will develop a program design using a number of methodologies and produce a report. The report worth 20% will include defining diagram, control structures required, pseudocode of the proposed algorithm, and desk checking based on addressing issues with a traditional ...

View Answer
Q
icon

We aren't endorsed by this University

Virtual Image

...

View Answer
Q
icon

We aren't endorsed by this University

OWASP Vulnerabilities

...

View Answer
Q
icon

We aren't endorsed by this University

Measures to Injection Attacks

...

View Answer

Content Removal Request

If you are the original writer of this content and no longer wish to have your work published on Myassignmenthelp.com then please raise the content removal request.

Choose Our Best Expert to Help You

icon

5% Cashback

On APP - grab it while it lasts!

Download app now (or) Scan the QR code

*Offer eligible for first 3 orders ordered through app!

screener
ribbon
callback request mobile
Have any Query?