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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include <iostream>
#include "graph1.h"
using namespace std;
//Function Prototypes Follow
void getNoPoints(int* no_points);
void getPoints(int* x, int* y,int no_points);
void drawPolyLine(int* x, int* y, int no_points,int objects[]);
int main()
{
//Variable Declaration/Initialization
int no_points = 0;
const int MAX_POINTS = 10;
int x[MAX_POINTS];
int y[MAX_POINTS];
int no_circles = 0;
int objects[MAX_POINTS];
//Display Graphics Window
displayGraphics();
//Get the number of points (pass the address of no_points )
getNoPoints(&no_points);
//Get the data for the points
getPoints(x,y,no_points);
//Draw the polyline
drawPolyLine(x,y,no_points,objects);
return 0;
}
//Function Implementation Follows
void getNoPoints(int* no_points)
{
cout<<"Enter # of points: ";
cin>>*no_points;
}
void getPoints(int* x, int* y,int no_points)
{
//Variable Declaration/Initiliation
int i=0;
for(i=0;i<no_points;i++)
{
cout<<"Enter x/y coord for point #"<<(i+1)<<": ";
cin>>x[i]>>y[i];
}
}
void drawPolyLine(int* x, int* y, int no_points,int objects[])
{
int i=0;
for (i = 0; i < no_points;)
{
objects[i] = drawLine(x[i],y[i],x[++i],y[++i],1);
setColor(objects[i],255,255,0);
}
//Display each circle
for (i = 0; i < no_points; i++)
{
objects[i] = drawCircle(5,x[i],y[i]);
setColor(objects[i],255,0,0);
}
}
|