Solved–Homework 2– Solution

$30.00 $19.00

Name 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: Private members: x, y and z as double. Write a default constructor and set the point to (0, 0, 0). Write a constructor and set the point…

You’ll get a: . zip file solution

 

 
Categorys:
Tags:

Description

5/5 – (2 votes)

Name 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.

  1. Write the set functions for each individual member, x and y together, and x, y, and z together.

  1. Write the get functions for each individual member.

  2. Write a member function called print() that print out the point as (x, y, z)\n.

  1. Write a member function called distance() that return the distance between the origin and the point.

  1. Write a member function called distance(param) that return the distance between a pt2 and the point.

  1. Write a member function called origin() that return true if the point is the origin.

  1. 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.

  1. Write a member function called cross(param) that return a point that is the cross product of a pt2 and the point.

  1. Overload the addition (+) and the subtraction (-) operators.

  2. Overload the output (<<) and input (>>) operators. The output should be (x, y, z)\n.

  1. Write a non-member function called plane(param) that takes an array of exactly three points and a target point. Return true if the target point is on the plane created by the static array of three points. Otherwise, return false.

To find the plane

    1. Find u and v where u is pt2-pt1 and v is pt3-pt1.

    2. Find the normal vector to the plane by using the cross product of u and v.

    1. Using the Point-Normal Form, the normal vector, and any of the three points, the equation of the plane is a(x-x0) + b(y-y0) + (cz-z0) = 0, where <a, b, c> is the normal vector and P(x0, y0, z0) is one of the three points. Thus, any points P(x, y, z) that satisfy this equation is on the plane.

  1. Write a non-member function called square(param) that takes a static array of unique points and the size of the array. Return true if the array of points can create at least one square. Otherwise return false.

  1. Write a non-member function called centroid(param) that takes a static array of points and the size of the array and return the centroid of the array of points. If there is no center, return the origins.