code should be established in a functional way

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 15PE
icon
Related questions
Question

So form code should be established in a functional way and outcome also. 

 

Implement the class Point3D. Put the class definition in the header p1.h and the implementation in the p1.cpp file. You may not have any
inline functions defined in the header file. Use the file xercise.cpp to check if your implementation is syntactically correct.
• The class has three data members: x, y, and z, which are double.
• The default constructor initializes the Point3D to the origin (0, 0, 0), while the working constructor supplies values for x, y, and 2:
all doubles in that order.
• Create accessors getX(), getY() and getZ(). There are no mutators. (The class is immutable)
•
Write a member function distance() that returns the distance between the current Point3D (the implicit parameter which will be
the left-hand side of an expression) and a second Point3D passed as an explicit parameter (which will be the right-hand-side of the
expression). Here is the distance formula for a 3D point:
(x₁-x2)² + (y₁ - y₂)² + (Z₁-Z2)²
You must both define and implement a feature for the tests to run. For instance, if you define getX() but fail to implement it, then your
code will not compile. If your code fails to compile, comment out both the definition and the implementation of the feature that fails.
Exam C++ Quick Reference
1.cpp
1
#include <math>
2
#include <string>
3 #include <iostream>
4 #include <sstream>
5 #include <iomanip>
6
7 #include "p1.h"
8
9 // Implement your member functions in this file
SENAZAS=28=AAZAAZA
10 Point3D Point3D()
11 {
12
13 }
14
17
15 Point3D:: Point3D(double xx, double yy, double zz)
16 {
18
19
29
21
using namespace std;
24
23 {
22 double Point3D :: getX()
return x;
26
25 }
29
}
30
31
27 double Point3D :: getY()
34
{
x=y=z= 0;
}
33 {
X = XX;
y = yy:
z = 22;
32 double Point3D::get()
35 }
return y;
return z;
Transcribed Image Text:Implement the class Point3D. Put the class definition in the header p1.h and the implementation in the p1.cpp file. You may not have any inline functions defined in the header file. Use the file xercise.cpp to check if your implementation is syntactically correct. • The class has three data members: x, y, and z, which are double. • The default constructor initializes the Point3D to the origin (0, 0, 0), while the working constructor supplies values for x, y, and 2: all doubles in that order. • Create accessors getX(), getY() and getZ(). There are no mutators. (The class is immutable) • Write a member function distance() that returns the distance between the current Point3D (the implicit parameter which will be the left-hand side of an expression) and a second Point3D passed as an explicit parameter (which will be the right-hand-side of the expression). Here is the distance formula for a 3D point: (x₁-x2)² + (y₁ - y₂)² + (Z₁-Z2)² You must both define and implement a feature for the tests to run. For instance, if you define getX() but fail to implement it, then your code will not compile. If your code fails to compile, comment out both the definition and the implementation of the feature that fails. Exam C++ Quick Reference 1.cpp 1 #include <math> 2 #include <string> 3 #include <iostream> 4 #include <sstream> 5 #include <iomanip> 6 7 #include "p1.h" 8 9 // Implement your member functions in this file SENAZAS=28=AAZAAZA 10 Point3D Point3D() 11 { 12 13 } 14 17 15 Point3D:: Point3D(double xx, double yy, double zz) 16 { 18 19 29 21 using namespace std; 24 23 { 22 double Point3D :: getX() return x; 26 25 } 29 } 30 31 27 double Point3D :: getY() 34 { x=y=z= 0; } 33 { X = XX; y = yy: z = 22; 32 double Point3D::get() 35 } return y; return z;
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning