CSE102 – Computer Programming Homework #4 (Solution)

$ 20.99
Category:

Description

Graphing Quadratic Equations

Hand in: A student with number 20180000001 should hand in a ‘c’ file named 20180000001.c for this homework.

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

General Rules:
1. Only stdio.h library is allowed.
2. You can write your own functions for clear coding.
3. Assume that the inputs (coefficients) will be given properly (as integers).
4. Using arrays is not allowed.
5. Make sure that your program can print a graph properly within the given ranges.
7. If you have any questions about this homework, please ask them through the assignment post on the Teams, so that everyone can see the answer.

Reviews

There are no reviews yet.

Be the first to review “CSE102 – Computer Programming Homework #4 (Solution)”

Your email address will not be published. Required fields are marked *