Military Institute of Science & Technology

Dept of Computer Science & Engineering Object Oriented Programming Language Sessional CSE – 12, Level – 2, Term – I Course Code – CSE 206 LAB – 03 Date – 12 Feb 2013
Problem 2: Implement the following class point class point{ double x, y; public: //add default constructor which will initialize x, y by 0 point(double a, double b); //initialize x, y by a, b void setx(double a); //set x by a void sety(double b); //set y by b void setxy(double a, double b); //set x, y by a, b double getx(); //return x double gety(); //return y double disOrigin(); double distance(point P) ; double PolarAngle(); point centroid(point p, point q); bool onXaxis(); bool onYaxis(); }; int main() { point p, q(7, 14), r, s; p.setx(1); p.sety(2); r.setxy(18, 36); cout << q.getx() << " " << q.gety() << endl; cout << s.getx() << " " << s.gety() << endl; cout << r.disOrigin() << endl; cout << q.PolarAngle() << endl; cout << q.distance(p) << endl; cout << q.onXaxis() << " " << s.onYaxis() << endl; s = p.centroid(q, r); cout << s.getx() << " " << s.gety() << endl; return 0; } Output: 7 14 00 40.2492 63.4409 13.4164 0 1 8.66667 17.3333 //return distance with origin //return distance with point p //return polar angle of the point //return centroid of a triangle //return true if the point is on X axis //return true if the point is on Y axis

Page 1 of 2

G = where (x1. P (x. (x2. G Centroid Diagram Distance between two points. (x3. y2). y) Page 2 of 2 .Centroid of a triangle Definition: The point through which all the three medians of a triangle pass is called centroid of the triangle and it divides each median in the ratio 2:1. y3) be the coordinates of the vertices of the triangle. Centroid Formula: Centroid. Polar Angle. y1).

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.