Thread: Plotting a graph on C++ console

1. Plotting a graph on C++ console

Hi! I'm making a C++ program in which i have to take two coordinate input from the user on x-y plane and plot a simple graph joining those two coordinates. Now there are few problems that i am facing

1)the X and Y axis have to extend or increase their length in accordance with the users input (what I thought was to make a fixed X-Y axis of length 5 but if any of the input co-ordinates is 10 the line will exceed the out of the graph.)

2)another problem is of over lapping that if the line is completely over X or Y axis or even some point of that line crosses X and Y axis from a point at that point the character I'm using for representing the line e.g(*) should be displayed not the character im making my X(-) and Y(|) with.

(exact question for the Code):
Write a C++ code that takes as input two coordinates (x,y). The program then calculates an approximate linear equation (gradient and intercept are integers) and plots it onto the console. If the line interacts with x or y axis, make sure that axis is visible. Assume that the line cannot be vertical
examples of program output:
.

P.S I'm a beginner at programming so the things I'm supposed to use are basic (while, for, pre-defined functions, if, if else).THANKS.

2. Step 1: Do the input and output the approximate linear equation for the given input.
Step 2a: Use variables to save the min X and the max X value from the given input
Step 2b: Use variables to save the min Y and the max Y value from the given input
Step 2c: Print the min x and max y values followed by the max x and min y values and think about what they mean related to the example input shown to you.

Step3: Draw the X and Y axis ignore the idea of drawing the line.

Step4: Think about how to draw the points where the line crosses the X and Y axis and do it.

Note: This problem requires doing nested loops

Tim S.