2d graph for sin values

Hi,

I have a formula to calculate sin values , after the calculation. I get two array of values.
x[] = {0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60}
y[] = {0,5,10,10,13,18,20,20,25,0,-5,-10,-12,-16,-20}

Now I need to find the maximum and minumum value from y[] array and plot those values in y axis. And also need to plot '$' at the (x,y) co ordinates for eg '$' at (0,0),(4,5),(8,10),(12,10)......(60,-20).

This is not plotting using console application, Seriously I dont have any idea to achieve this....Could anyone please help me in plotting this 2d graph....

regards.
This is how you can do it even within the console:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <algorithm> // for min_element and max_element
#include <iostream> // cout, endl
#include <set>
#include <vector>
#include <utility> // pair and make_pair

using namespace std;

int main()
{
	const int size = 15;
	int x[size] = {0,4,8,12,16,20,24,28,32,36,40,44,48,52,56};
	int y[size] = {0,5,10,10,13,18,20,20,25,0,-5,-10,-12,-16,-20};

	// calculate minima and maxima.
	int minx = *min_element( x, x+size );
	int maxx = *max_element( x, x+size );
	int miny = *min_element( y, y+size );
	int maxy = *max_element( y, y+size );

	// create an empty set of points
	set<pair<int,int>> points;

	// insert the points given be the above arrays
	for ( size_t i = 0; i < size; ++i )
		points.insert( make_pair( x[i], y[i] ) );

	// display the points with stars.
	for ( int iy = maxy; iy >= miny; --iy )
	{
		for ( int ix = minx; ix <= maxx; ++ix )
			cout << ( points.count( make_pair( ix, iy ) ) ? '$' : ' ' );
		cout << endl;
	}
}

By the way, the arrays you gave have 16 and 15 elements. I erased the last element of the array x, so the sizes match.
Last edited on
Topic archived. No new replies allowed.