Please write the codes for 7-15 (functions) ds/HW1.pdf Due September 17th, 2018
ID: 3745632 • Letter: P
Question
Please write the codes for 7-15 (functions)
ds/HW1.pdf Due September 17th, 2018 You will need to submit a written report with part of your codes and your source code via Blackboard. You also need to bring in a hard copy of the report with part of your codes to the class on the day that this is due Name your header file as LastName(3 to 5 letters) FirstNameInitial HW1.h and your implementation file as LastName(3 to 5 letters) FirstNameInitial HW1.cpp Note: You can only use iostream, cassert, cmath, cstdio, and cstdlib Create a class called Point with the following: 1. Private members: x, y and z as double 2. Write a default constructor and set the point to (0. 0, 0) 3. Write a constructor and set the point to user input, if z is not inputted, set it to 0 4. Write a copy constructor 5. Write the set functions for each individual member, x and y together, and x, y, and z together. 6. Write the get functions for each individual member. 7. Write a member function called printO that print out the point Write a member function called distance0 that return the distance between the origin and the point. Write a member function called line(param) that return true if pt2 is on the same line as the origin and the point. Otherwise, return false. Also return false if the origin and the point do NOT make a line. 10. Write a member function called cross(param) that return a point that is the cross product of a pt2 and the point 11. Overload the addition ) and the subtraction -) operators 12. Overload the output () and inputoperators. 13. Write a non-member function called plane(param) that takes an array of three points and a point. Return true if that point is on the plane created by the static array of three points. Otherwise, return false. To find the plane i. Find u and v where u is pt2-ptl and v is pt3-ptl i. Find the normal vector to the plane by using the cross product of u and iii. Using the Point-Normal Form, the normal vector, and any of the three , b, co is the normal vector and P(xo, yo, zo) is one of the three points 14. Write a non-member function called square(param) that takes a static array of unique points, the equation of the plane is ar-xo) + bo-yo t (cz-zo) -0, where Thus, any points P(x, y, z) that satisfy this equation is on the plane. points and the size of the array. Return true if the array of points can create at least one 15. Write a non-member function called centroid(param) that takes a static array of points square. Otherwise return false and the size of the array and return the centroid of the array of pointExplanation / Answer
#include <iostream>
#include<math.h>
using namespace std;
class Point {
private:
int x,y,z,dist;
public:
Point()
{
x = 0;
y = 0;
z = 0;
}
Point (int i, int j, int k)
{
x = i;
y = j;
z = k;
}
void print()
{
cout<<"The point that is entered is:"<<endl;
cout<<"("<<x<<" , "<<y<<" , "<<z<<")"<<endl;
}
void distance(void)
{
dist = sqrt(pow(x - 0, 2) + pow(y - 0, 2)+pow(z-0,2));
cout<<"distance between origin and the point is"<<dist<<endl;
}
void line()
{
int x3,y3,a;
cout<< "enter the previous point again to check collinearity";
cin >> x3;
cin >> y3;
a = 0 * (y - y3) + x * (y3 - 0) + x3 * (0 - y);
if (a == 0)
printf("true");
else
printf("false");
}
Point operator- () {
x = -x;
y = -y;
//return Point(x, y);
cout<<"Overloaded ''-' operator the values become"<<x<<","<<y;
}
Point operator+ () {
x =+1;
y =+1;
//return Point(x, y);
cout<<"Overloaded '+' operator the values become"<<x<<","<<y;
}
};
int main()
{
Point p1;
p1.print();
Point p2 =Point(0, 2, 3);
p2.print();
p2.distance();
p2.line();
p2.operator+();
p2.operator-();
}