Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 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 derived class Point1D, Point2D, and Point3D, where Point1D derives from Point, Point2D derives from Point1D, Point3D derives from Point2D.

In the Point class, you need to define a virtual function virtual int getDimension() const = 0 which returns the dimension.

In the class Point1D, Point2D, and Point3D you need to overwrite the function getDimension() to return the correct dimension. Maybe you also need to define the x y z coordinates and other necessary functions.

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 the read and print functions defined in the functions.h file.

NOTES:

  1. Your program will use input redirection (you do not need to open the input file).
  2. Include the .h files when needed.
  3. Use inheritance when needed.
  4. Use abstract classes when needed.
  5. Use virtual functions when needed.

image text in transcribed

image text in transcribed

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}; int getz) const {/* write your code here*/} void setz(int 2) {/* write your code here*/} private: double z = @; ); 10 12 15 Fendif

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions