Please Help This. 1 Change the <tt>Point</tt> class to represent points in three
ID: 667657 • Letter: P
Question
Please Help This.
1 Change the <tt>Point</tt> class to represent points in three dimensions. Make sure to update the comments to match this change!
2. Add a new member function to <tt>Point</tt> called <tt>distanceTo</tt>. This member function should accept as an argument a <u><tt>Point &</tt></u> (a reference to a <tt>Point</tt>), and it should return a <tt>double</tt> that approximates the distance between the two points.
You will probably find a square-root function useful for this! The C standard library has one, called <tt>sqrt()</tt>. The function takes a double and returns another double.
3. Create a new source file <tt>pa1.cpp</tt> and implement two functions:
* <tt>double computeArea(Point &a, Point &b, Point &c)</tt>
which takes by reference three <tt>Point</tt> objects, computes the area within the triangle defined by these points (hint: use [Heron's Formula](http://en.wikipedia.org/wiki/Heron%27s_formula)), and returns it as a double-precision floating point number.
* <tt>int main()</tt>
which requests three points (nine coordinates) from the user, determines the area inside the triangle described by the three points using the aforementioned function, and displays the result.
In C++, you don't have to declare all variables at the top of a block; you can intermingle variable declarations and statements of code. So, you should only need to use three <tt>double</tt> variables to input the coordinates, and then create each <tt>Point</tt> along the way.
Compile these sources together
/////Point.h////////
// A 2-dimentional point class
// Coordinates are double-precision floating point
#ifndef point_h
#define point_h
class Point {
private:
double x;
double y;
public:
// Constructions
Point(); // default constructor
Point (double x, double y); // two argument constructor
// Destructor
~Point();
// Mutator methods
void setX(double newX);
void setY(double newY);
// Accessor methods
double getX();
double getY();
};
#endif // point.h
///// Point.cpp//////
#include "Point.h"
// Default constructor
// Initializes the point to (0.0, 0.0)
Point::Point(){
x = 0.0;
y = 0.0;
}
// Constructor
// Initializes the point to (initX, initY)
Point::Point (double initX, double initY){
x = initX;
y = initY;
}
// Destructor
// No dynamic allocation, so nothing to do; if omotted, generated automatically
Point::~Point(){
// no-op
}
// Mutator methds
// Change the values of private member variables
void Point::setX(double newX) {
x = newX;
}
void Point::setY(double newY) {
y = newY;
}
//Accessors
//Return the current values of private member variables
double Point::getX() {
return x;
}
double Point::getY() {
return y;
}
/////pa.cpp//////
#include "Point.h"
int main(void) {
Point p;
return 0;
}
Explanation / Answer
point.cc
Point.hh
lab1.cc