Starting from:

$25

CSE102 - Computer Programming - Homework 4 - Graphing Quadratic Equations  - Solved

In this assignment, you are asked to write a program that draws the graph of a given quadratic equation. The program should consist of 3 parts as described below.   

Part 0: The program should have an infinite loop that asks the user to select the operation and this loop should stop running only when the user chooses to exit. It should also warn the user if an improper input is given.

Expected output 

  

 

Part 1 (10pts): The program gets the coefficients of the equation as input. Since there are three coefficient in a quadratic equation, user should enter three integers. These 3 integers should be written line by line to a .txt file called “coefficients.txt” which has been created during this part of the program.   P.S. Since the program will print the graph line by line, the variable in the equation should be y coordinates instead of x as following:   𝑥  =  𝑎 ⋅ 𝑦2  +  𝑏 ⋅ 𝑦  +  𝑐

Expected outputs

Terminal:                              

  

 

 

Txt file: 

  

Part 2 (80 pts): In this part, the program should draw the graph of the equation on the 2D cartesian plane. First, it should read the “coefficients.txt” file and get the coefficients (if the file is not present, it should warn the user), and then draw the graph of it.  

Drawing the graph:  

-          The program should draw a graph in a range of [-55, 55] for x values and [15,-15] for y values (to see the graph properly in the terminal).  

        -       

-          The graph should be written line by line. For instance, it should print P1(-55,15) first. And then P2(-54,15) next to it. Once it prints P3(55,15) it should go to the next line and start again with the point (-55,14). To understand it better, check the following picture (the picture is not correlated with the expected output of the program).

  

-          When printing a point on the cartesian plane: o If the point is not on the graph of the equation, and it is not on the x or y-axis, a space should be printed for that point.  

o   If the point is on the graph of the equation, it should be printed as #.

o   If the point is on the x-axis or y-axis, the program should use “-” and “|” characters to draw a horizontal or a vertical line.   

-          On the x-axis, print a number for every 10 units to empathize the coordinates of the graph. The numbers should be under the x-axis. Make sure these numbers don’t overwrite the points of the graph of the equation (i.e. # characters).  

-          The program should repeat the last step for the y-axis as well. But the numbers should be printed every 5 units and they should be at the left side of the y-axis.  

-          Use different colors to draw a more understandable graph. Check this page to see the code block (which consists of only 3 lines).

 

 

Expected outputs: 

The graph of 𝑥  =  𝑦2 

  

The graph of 𝑥  =  𝑦 + 5  

  

The graph of 𝑥  =   − 10  

  

 

Part 3 (10 pts): The program should print the same graph to the “graph.txt” file. In this part, the program should follow the same steps as in Part2 (without colors and printing numbers).

Expected outputs: 

The graph of 𝑥  =  𝑦2 

  

  

The graph of 𝑥  =   − 10  

More products