plotting graph

Hi ,
I have an array like this
6,5
12,9
18,11
I need to plot 'B' at all the co-ordinates mentioned above, for all other co-ordinates I need to plot'z'. could anyone help me in writing code for this?
Do you want to do this in console? If no, it very much depends on what you intend to use. If yes, I suggest having an array filled with spaces, plotting things on it, and only the printing the whole array. You could do it more efficiently, but do you really need to?
this is my complete requirement,
I have one array, say x[] and got following values 0,6,12,18,24,30,36,42,48,54,60,66,72,78,84,90
an another array of values as y[] with the following values 0,7,11,14,11,10,9,9,9,10,10,11,11,10,9,9

x array need to take as x axis and y array need to take as y axis and plot '$' symbol in the point of (x,y) for eg
$ symbol at the co-ordinates (0,0),(6,5), (12,9),(18,11),(24,11) and all other remaing co-ordinates will be left blank.
there also a line need to be drawn using ' _' at x axis and in y axis values like 1,2,3,4,5,6,7,8,9,10,11,12,13,14 need to be printed because in the array of y it has got maximum value of 14 only.

for the above requirement i need to write a c++ program........can anyone help me.
Do you want to do this in console?
Here is a program that does some of what you require, to get you started. I didn't know where you were acquiring your coordinates, like {6,5} and {12,9}, since those are not in the x,y arrays. so I just used the first 14 values to plot the '$'. ( I compiled this with MS VC++ 2008 Express Edition. )
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Plotting.cpp : Defines the entry point for the console application.
//

#include <stdafx.h>
#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <string>
#include <windows.h>

using namespace std;

HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD CursorPosition;

void gotoXY(int x, int y) 
{ 
CursorPosition.X = x; 
CursorPosition.Y = y; 
SetConsoleCursorPosition(console,CursorPosition); 
}

void gotoXY(int x, int y, string text) 
{ 

CursorPosition.X = x; 
CursorPosition.Y = y; 
SetConsoleCursorPosition(console,CursorPosition);
cout << text;
}

void WaitKey()
{
while (_kbhit()) _getch(); // Empty the input buffer
_getch();                             // Wait for a key
while (_kbhit()) _getch(); // Empty the input buffer 
                                             // ( some keys sends two messages)
}

int main(int)
{
	int x[] = {0,6,12,18,24,30,36,42,48,54,60,66,72,78,84,90};
	int y[] = {0,7,11,14,11,10, 9, 9, 9,10,10,11,11,10, 9, 9};
	string line(80,'_');
	for ( int a = 0; a < 14; a++)
	{
		gotoXY(x[a],y[a],"$");
		gotoXY(x[a],16);
		cout << a+1;
	}
	gotoXY(0,15,line);
	gotoXY(0,25);
	WaitKey();
	return 0;
}


EDIT: To add a line across the whole screen, instead of just under the '$' symbols.
Last edited on
Topic archived. No new replies allowed.