Thread: Plotting a graph on C++ console

  1. #1
    Registered User
    Join Date
    Nov 2021
    Posts
    4

    Question 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:
    Plotting a graph on C++ console-po-png.

    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. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    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.
    Last edited by stahta01; 11-14-2021 at 04:09 AM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advise on graph plotting software
    By Mario F. in forum General Discussions
    Replies: 9
    Last Post: 07-13-2013, 12:34 PM
  2. Plotting graph in turbo c++ 2.01,linux
    By suryap.kv1bbsr in forum C Programming
    Replies: 9
    Last Post: 03-25-2011, 06:44 AM
  3. plotting a graph
    By cracker in forum C Programming
    Replies: 4
    Last Post: 09-23-2009, 05:37 AM
  4. Plotting a graph with Koolplot
    By Router in forum C Programming
    Replies: 13
    Last Post: 11-05-2006, 09:07 PM
  5. graph plotting
    By wayne in forum C++ Programming
    Replies: 3
    Last Post: 05-25-2005, 02:47 AM

Tags for this Thread