(Solved) : C Assuming Read Input List 1d 2d 3d Points Std Cin Example X 86 X 0 Y 0 X 6x 1 Y 24 Z 3 X Q43970210 . . .
C++
Assuming you can read the input of a list of 1D, 2D and 3Dpoints from std::cin, for example,
x=8.6 x=0 y=0 x=6x=1 y=2.4 z=3 x=3 y=4 x=7 x=5.2 y=5 z=5
where each line denotes one point.
Could you count how many 1D, 2D, and 3D points, respectively?Could you come up with a solution using Polymorphism?
Assuming you have the base class called Point, and the derivedclass Point1D, Point2D, and Point3D, where Point1D derives fromPoint, Point2D derives from Point1D, Point3D derives fromPoint2D.
In the Point class, you need to define a virtual functionvirtual int getDimension() const = 0 which returnsthe dimension.
In the class Point1D, Point2D, and Point3D you need to overwritethe function getDimension() to return the correct dimension. Maybeyou also need to define the x y z coordinates and other necessaryfunctions.
For the example input above, the following program:
int main()
{
Point* points_1[7];
read(points_1,7);
print(points_1,7);
return 0;
}
Will generate the following output:
#1D = 3, #2D = 2, #3D = 3
After modifying the classes stated before, you need to write theread and print functions defined in the functions.h file.
NOTES:
- Your program will use input redirection (you do not need toopen the input file).
- Include the .h files when needed.
- Use inheritance when needed.
- Use abstract classes when needed.
- Use virtual functions when needed.
Requested files functions.h 1 2 #ifndef FUNCTIONS_H #define FUNCTIONS_H void read(Point points[], int n) 4 5 – 6 /* write your code here*/ 9 void print(Point points[], int n) 10-{ 11 /* write your code here*/ 12 ) 13 14 15 #endir Point.h 1 2 #ifndef POINT_H #define POINT_H 4 5 6 #include <iostream> #include <string> #include <sstream> 8 using namespace std; class Point // use the virtual qualifier when needed 10 11- 12 13 public: int getDimension() const; 14 }; 15 16 #endif Point1D.h i 2 #ifndef POINT1D_H #define POINTID_H 4 5 – class Point1D // use inheritance and the virtual qualifier when needed public: int getDimension() const {/* write your code here*/} int getX() const {/* write your code here*/} void setX(int _x) {/* write your code here*/} private: double x = 0; 11 12 }; 14 15 #endif Point2D.h 1 2 #ifndef POINT2D_H #define POINT2D_H 4 5- class Point 2D // use inheritance and the virtual qualifier when needed public: int getDimension() const {/* write your code here*/ }; int getY() const {/* write your code here*/} void setY(int y){ /* write your code here*/} private: double y = 0; 12 }; 14 15 #endif Point3D.h 2 #ifndef POINT3D_H #define POINT3D_H 4 5- 000 class Point3D // use inheritance and the virtual qualifier when needed { public: int getDimension() const {/* write your code here</}; int getz) const {/* write your code here*/} void setz(int 2) {/* write your code here*/} private: double z = @; ); 10 12 15 Fendif Show transcribed image text Requested files functions.h 1 2 #ifndef FUNCTIONS_H #define FUNCTIONS_H void read(Point points[], int n) 4 5 – 6 /* write your code here*/ 9 void print(Point points[], int n) 10-{ 11 /* write your code here*/ 12 ) 13 14 15 #endir Point.h 1 2 #ifndef POINT_H #define POINT_H 4 5 6 #include #include #include 8 using namespace std; class Point // use the virtual qualifier when needed 10 11- 12 13 public: int getDimension() const; 14 }; 15 16 #endif Point1D.h i 2 #ifndef POINT1D_H #define POINTID_H 4 5 – class Point1D // use inheritance and the virtual qualifier when needed public: int getDimension() const {/* write your code here*/} int getX() const {/* write your code here*/} void setX(int _x) {/* write your code here*/} private: double x = 0; 11 12 }; 14 15 #endif
Point2D.h 1 2 #ifndef POINT2D_H #define POINT2D_H 4 5- class Point 2D // use inheritance and the virtual qualifier when needed public: int getDimension() const {/* write your code here*/ }; int getY() const {/* write your code here*/} void setY(int y){ /* write your code here*/} private: double y = 0; 12 }; 14 15 #endif Point3D.h 2 #ifndef POINT3D_H #define POINT3D_H 4 5- 000 class Point3D // use inheritance and the virtual qualifier when needed { public: int getDimension() const {/* write your code here
Expert Answer
Answer to C++ Assuming you can read the input of a list of 1D, 2D and 3D points from std::cin, for example, x=8.6 x=0 y=0 x=6 x=1 …
OR