Question

Must be C++ programming    The MyPoint class was created to model a point in a...

Must be C++ programming
   The MyPoint class was created to model a point in a two-dimensional space. The MyPoint class has the properties x and y that represent x- and y-coordinates, two get functions for x and y, and the function for returning the distance between two points. Create a class named ThreeDPoint to model a point in a three-dimensional space. Let ThreeDPoint be derived from MyPoint with the following additional features:
A data field named z that represents the z-coordinate.
A no-arg constructor that constructs a point with coordinates(0,0,0).
A constructor that constructs a point with three specified coordinates.
A constant get function that returns the z value.
A constant distance(const ThreeDPoint&) function to return the distance between this point and the other point in the three-dimensional space.
    Implement the classes. Write a test program that creates two points (0,0,0) and (10,30,25.5) and displays the distance between them.

Homework Answers

Answer #1

Here is the answer for your question in C++ Programming Language.

CODE :

#include<iostream>
#include<cmath>
#include<iomanip>

using namespace std;
//MyPoint Class
class MyPoint{
   public:
       //Class member variables
       double x;
       double y;
       //Default constructor that sets point(0,0)
       MyPoint(){
           x = 0;
           y = 0;
       }
       //Parameterised constructor that creates a point with specified co-ordinates
       MyPoint(double X,double Y){
           x = X;
           y = Y;
       }
       //Returns x
       double getX(){   return x; }
       //Returns y
       double getY(){ return y;   }
       //Returns ditance between two points
       double distance(const MyPoint& p1) const{
           return sqrt(((p1.x - x)*(p1.x - x)) + ((p1.y - y)*(p1.y - y)));
       }
};
class ThreeDPoint : public MyPoint{
   //Class variable
   double z;
   public:
       //Default constructor that sets point(0,0,0)
       ThreeDPoint(){
       z = 0;          
       }
       //Parameterised constructor that creates a point with specified co-ordinates
       ThreeDPoint(double X, double Y, double Z) : MyPoint(X,Y){
           z = Z;
       }
       //Returns z
       double getZ() const{ return z; }
       //Returns ditance between two points
       double distance(const ThreeDPoint& p1) const{          
           return sqrt(((p1.x - x)*(p1.x - x)) + ((p1.y - y)*(p1.y - y)) + ((p1.z - z)*(p1.z - z)));
       }
      
};
int main(){
  
   //Creates two points p1 and p2
   ThreeDPoint p1;
   ThreeDPoint p2(10,30,25.5);
  
   //Display output
   cout << "First point (" << p1.getX() << ", " << p1.getY() << ", " << p1.getZ() << ") is created." << endl;
   cout << "Second point (" << p2.getX() << ", " << p2.getY() << ", " << p2.getZ() << ") is created." << endl;  
    cout << "Distance between the two points : " << fixed << setprecision(2) << p1.distance(p2) << endl;
   return 0;
}

SCREENSHOTS :

Please see the screenshots of the code below for the indentations of the code.

OUTPUT :

Any doubts regarding this can be explained with pleasure :)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
To gain coding XP, complete this coding challenge by adding constructors to the Point class you...
To gain coding XP, complete this coding challenge by adding constructors to the Point class you completed for the previous challenge.Point should have three constructors:One that takes no arguments and does nothing (the default constructor).One that takes the x- and y-coordinates for the point to create as arguments. The x- and y-coordinates of a point should be non-negative. If the arguments provided are negative values, use 0 instead as the construction value.A copy constructor
Please create an array of Leg objects, one constructor that takes three parameters as constant C...
Please create an array of Leg objects, one constructor that takes three parameters as constant C string, and one number representing the distance in miles between the two cities Write a code block to create a static array (that is, not dynamic and not a vector) of 3 Leg objects using city names of your choosing. That's THREE objects, each created using THREE parameters. For example, the Leg class declaration looked like, class Leg { const char* const startCity; const...
Java code Problem 1. Create a Point class to hold x and y values for a...
Java code Problem 1. Create a Point class to hold x and y values for a point. Create methods show(), add() and subtract() to display the Point x and y values, and add and subtract point coordinates. Tip: Keep x and y separate in the calculation. Create another class Shape, which will form the basis of a set of shapes. The Shape class will contain default functions to calculate area and circumference of the shape, and provide the coordinates (Points)...
C++ PROGRAMMING Hi! I have to make a program that adds fractions and simplifies them. I...
C++ PROGRAMMING Hi! I have to make a program that adds fractions and simplifies them. I feel like I know how to write that. What I'm having trouble with is implementing two files the professer gave us. I would appreicate any help in understanding their purpose as in if Im supposed to take information from those files or give it information. Thank you! I have attatched the homework instructions and the two files given. Implementation The main program, called calculator.cpp...
In java //Create a New Project called LastNameTicTacToe.// //Write a class (and a client class to...
In java //Create a New Project called LastNameTicTacToe.// //Write a class (and a client class to test it) that encapsulates a tic-tac-toe board. // A tic-tac-toe board looks like a table of three rows and three columns partially or completely filled with the characters X and O. // At any point, a cell of that table could be empty or could contain an X or an O. You should have one instance variable, a two-dimensional array of values representing the...
K 2. Point Source Interference Pattern Consider a two-dimensional x-y space in which there are two...
K 2. Point Source Interference Pattern Consider a two-dimensional x-y space in which there are two identical and synchronized point sources located at y=±D/2 emitting waves of wavelength λ. The sources are said to constructively interfere at any location if the phase difference between waves received from the two sources at that location differ by an integral multiple of 2π. Equivalently, the distances from the location to the two sources differ by an integral number of wavelengths. Derive the complete...
Q) a) create a matrix named as X of evenly spaced values from 0 to 50,...
Q) a) create a matrix named as X of evenly spaced values from 0 to 50, with an increment of 10. b) a) create a matrix named as Y of evenly spaced values from 500 to 1000, with an increment of 3. c)a) create a matrix named as Z, the value of the 1st row is from 1 to 10, 2nd row from 2 to 20 with increment of 2, 3rd row 3 to 12. using subplot divide the window...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop a class, using templates, to provide functionality for a set of recursive functions. The functions specified as recursive must be written recursively (not iterativly). The UML class specifications are provided below. A main will be provided. Additionally, a make file will need to be developed and submitted. ● Recursion Set Class The recursion set template class will implement the template functions. recursionSet -length: int...
The paraboloid z = 3x2 + 2y2 + 1 and the plane 2x – y +...
The paraboloid z = 3x2 + 2y2 + 1 and the plane 2x – y + z = 4 intersect in a curve C. Find the points on C that have a maximum and minimum distance from the origin. The point on C is the maximum distance from the origin is (___ , ____ , ____).    The point on C is the minimum distance from the origin is (____ , ____ , ____). So for this question I get...
1. Find the distance between the point and the line given by the set of parametric...
1. Find the distance between the point and the line given by the set of parametric equations. (Round your answer to three decimal places.) (8, -1, 4); x = 2t, y = t − 3, z = 2t + 2 I had put 6.87 but it shows as it being wrong. 2. Consider the following planes. −6x + y + z = 6 24x − 4y + 6z = 36 Find the angle between the two planes. (Round your answer...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT