pointer and variables

This program has three syntax errors the program should print the x and y coordinates of the sample points inputed by the user it also,should print if the points are inside or outside the plume.I'm trying to get the program to print in order to make other changes for my assignment.Any feedback is appreciated.
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;

const int LARGE_NUM=1.0E10;
struct Point
{
public:
	double x,y;
};
struct Line_seg
{
public:
	Point endpt1, endpt2;
	double slope, intercept;
};
class Boundary_map
{
private:
	enum {NUM_MAP_PTS=10};
	Point boundary_pts[NUM_MAP_PTS+1];
public:
	Boundary_map();
	void read_boundary_pts();
	void map_wrap_around();
	Point* get_boundary_pts();
	int get_num_boundary_pts();
};
class Probe
{
private:
	Point sample_pt, endpt1, endpt2;
	int num_crosses;
	Point probe_line_intersect (Line_seg);
	int probe_line_seg_intersect (Point, Line_seg);
public:
	Probe();
	void read_sample_pt();
	void check_map_boundary (Point*, int);
};
Boundary_map::Boundary_map()
{
	int i;
	for(i=0; i <NUM_MAP_PTS+1; i++)
	{
		boundary_pts[i].x=0;
		boundary_pts[i].y=0;
	}
}
void Boundary_map::read_boundary_pts()

{
int i;
ifstream infile ("C:\\BNDARY.DAT");
for(i=0; i<NUM_MAP_PTS; i++)
{
	infile>>boundary_pts[i].x;
	infile>>boundary_pts[i].y;
}

}
void Boundary_map::map_wrap_around()
{
	boundary_pts[NUM_MAP_PTS]=boundary_pts[0];
}
Point* Boundary_map::get_boundary_pts();
{
	return (boundary_pts);
}
int Boundary_map:: get_num_boundary_pts()

{
	return (NUM_MAP_PTS+1);
}
Probe::Probe()
{
	sample_pt.x=0;
	sample_pt.y=0;
	endpt1.x=0;
	endpt1.y=0;
	endpt2.x=LARGE_NUM;
	endpt2.y=0;
	num_crosses=0;
}
void Probe::read_sample_pt()
{
	cout<<"Enter the x and y coordinates of the sample point"<<endl;
	cin>>sample_pt.x>>sample_pt.y;
	endpt1=sample_pt;
	endpt2.y=sample_pt.y;
}
Point Probe::probe_line_intersect (Line_seg map_line_seg)
{
	Point intersect_pt;
	double probe_slope, probe_intercept;
	if(fabs(map_line_seg.endpt2.x-map_line_seg.endpt1.x)<1.0E-20)
	{
		intersect_pt.x=map_line_seg.endpt1.x;
		intersect_pt.y=endpt1.y;
	}
	else
	{
		map_line_seg.slope=(map_line_seg.slope=(map_line_seg.endpt2.y
			-map_line_seg.endpt1.y)/(map_line_seg.endpt2.x
			-map_line_seg.endpt1.x);
		map_line_seg.intercept=map_line_seg.endpt2.y
			-map_line_seg.slope*map_line_seg.endpt2.x;
		probe_slope=0.0;
		probe_intercept=sample_pt.y;
		if(fabs(map_line_seg.slope)<1.0E-20)
		{
			intersect_pt.x=LARGE_NUM;
			intersect_pt.y=LARGE_NUM;
		}
		intersect_pt.x=(probe_intercept-map_line_seg.intercept)/(map_line_seg.slope-probe_slope);
		intersect_pt.y=map_line_seg.slope*intersect_pt.x+map_line_seg.intercept;
	}
	return (intersect_pt);
}
	int Probe::probe_line_seg_intersect(Point intersect_pt, Line_seg seg2)
	{
		Line_seg seg1;
		double x_low_1, x_high_1, x_low_2, x_high_2;
		double y_low_1, y_high_1, y_low_2, y_high_2;
		seg1.endpt1=endpt1;
		seg1.endpt2=endpt2;
		x_low_1=(seg1.endpt1.x<seg1.endpt2.x)?
			seg1.endpt1.x:seg1.endpt2.x;
		x_high_1=(seg1.endpt1.x>seg1.endpt2.x)?
			seg1.endpt1.x:seg1.endpt2.x;
		x_low_2=(seg2.endpt1.x<seg2.endpt2.x)?
			seg2.endpt1.x:seg2.endpt2.x;
		x_high_2=(seg2.endpt1.x>seg2.endpt2.x)?
			seg2.endpt1.x:seg2.endpt2.x;
		y_low_1=(seg1.endpt1.y<seg1.endpt2.y)?
			seg1.endpt1.y:seg1.endpt2.y;
		y_high_1=(seg1.endpt1.y>seg1.endpt2.y)?
			seg1.endpt1.y:seg1.endpt2.y;
		y_low_2=(seg2.endpt1.y<seg2.endpt2.y)?
			seg2.endpt1.y:seg2.endpt2.y;
		y_high_2=(seg2.endpt1.y>seg2.endpt2.y)?
			seg2.endpt1.y:seg2.endpt2.y;
		if((x_low_1<=intersect_pt.x && intersect_pt.x<=x_high_1) && (x_low_2<=intersect_pt.x &&
			intersect_pt.x<=x_high_2) && (y_low_1<= intersect_pt.y && intersect_pt.y<=y_high_1) && 
			(y_low_2<=intersect_pt.y && intersect_pt.y<=y_high_2))
		{
			return(1);
		}
		else
		{
			return(0);
		}
	}
		void Probe:: check_map_boundary(Point* bnd_pt, int num_pts)
		{
			int i, does_cross, even_odd;
			Point intersect_pt;
			Line_seg map_line_seg;
			for(i=0;i<num_pts-1;i++)
			{
				map_line_seg.endpt1=bnd_pt[i];
				map_line_seg.endpt2=bnd_pt[i+1];
				intersect_pt=probe_line_intersect(map_line_seg);
				does_cross=probe_line_seg_intersect(intersect_pt, map_line_seg);
				num_crosses+=does_cross;
			}
			even_odd=num_crosses % 2;
			if(even_odd==0) cout << "The sample point is outside the " "plume. " <<endl;
			if(even_odd==1) cout << "The sample point is inside the " "plume. " <<endl;
		}
		int main ()
		{
			Boundary_map plume_map;
			Probe        probe_from_water_sample;
			
			plume_map.read_boundary_pts();
			plume_map.map_wrap_around();

			probe_from_water_sample.read_sample_pt();

			probe_from_water_sample.check_map_boundary
				(plume_map.get_boundary_pts(),
				plume_map.get_num_boundary_pts());
		}

1
2
3
4
5
6
7
8
9
10
Compiling...
wk4assignment.cpp
.\wk4assignment.cpp(6) : warning C4244: 'initializing' : conversion from 'double' to 'const int', possible loss of data
.\wk4assignment.cpp(6) : warning C4309: 'initializing' : truncation of constant value
.\wk4assignment.cpp(67) : error C2761: 'Point *Boundary_map::get_boundary_pts(void)' : member function redeclaration not allowed
.\wk4assignment.cpp(68) : error C2447: '{' : missing function header (old-style formal list?)
.\wk4assignment.cpp(106) : error C2143: syntax error : missing ')' before ';'
Build log was saved at "file://c:\Users\Martin\Documents\Visual Studio 2008\Projects\wk4assignment\wk4assignment\Debug\BuildLog.htm"
wk4assignment - 3 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========




Line 67 has a ; after it, remove it.
Line 106 is missing a ')' at the end, count your parentheses.
Thank you for your feedback your instructions helped me fix the errors. is there anything i can do to read syntax error better than i'm?
You can learn to read your compiler's errors and warnings. :)

Try messing around, deliberately inserting syntax errors and see how your compiler reacts.

-Albatross
Thank you thats a great way to read syntax errors. I'm trying to to get this program to print 10 x and y sample points and determine which are inside the plume boundary. I changed some values and I get no results. what can i do to get this print out any feedback at is appreciated.
Topic archived. No new replies allowed.