• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

How do I create a graph and plot coordinates in C++?

Uconn411

Member
I wrote the following code based on y=ax+b. It will ask a user to input 2 values (a and b), and show them the values of (x,y). Also, the user is asked to input a char marker, in which the line of the graph will be drawn. Problem is, I don't know how to draw a graph (with x and y axis), and then to plot the values. Here is what I have so far:

#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>



int main()
{


{
double slope, intercept, y;
char graph_char;

cout << "Enter a and b from the equation y = ax + b:\n";
cout << "a: ";
cin >> slope;
cout << "b: ";
cin >> intercept;

cout << "\nY: ";

for (int x=0;x<21;x++)

{
y = (slope * x) + intercept;
cout << "(" << x << "," << y << ") ";
}

cout<< "\nEnter the character marker for the graph: ";
cin>> graph_char;

}

return 0;
}


Thanks for any advice....
 
You need some sort of graphics library.
Hit google and look up Dislin. It's the simplist thing I've found for basic plotting.
 
Back
Top