This is a test of your C++ design and programming skills. 1) Make an inheritance hierarchy with at least two classes which can represent the coordinate points given below. Each class should provide a method (or methods) which will return the name and the coordinates of the point. Include any other methods you find appropriate or necessary to solve the rest of the test or to make the classes useful in practice. Two coordinate systems which will need to be handled are given below. The theta angle for polar coordinates is measured from the positive x-axis in the counter-clockwise direction. You may add any other classes or methods you think will make it easier for other people to use or extend your inheritance hierarchy. PointName CoordinateSystem Coordinates A Polar r = 8, theta = pi/6 radians B Polar r = 10, theta = pi/3 radians C Cartesian x = 2, y = 8 D Cartesian x = 4, y = 10 2) Now, make a new class called PointDistances that holds a collection of pointers to objects from the CoordinatePoint classes you wrote for problem 1). The pointers stored in the PointDistances class will include both pointers to your classes created in problem 1), and pointers to new derived classes added to your hierarchy by other programmers. Give it the following methods: 2a) a method that adds a copy of a CoordinatePoint object to the collection. 2b) a method (or methods) which will return copies of the two points which are closest together and the distance between these 2 points. 3) Write a main() function using the classes you wrote for 1) and 2) which will print out the PointName and the Coordinates of the 2 closest points given in 1) along with the distance between these 2 points. |
|
|
cs.cpp:76: error: ISO C++ forbids declaration of âvectorâ with no type cs.cpp:76: error: expected â;â before â<â token cs.cpp: In constructor âPointDistances::PointDistances()â: cs.cpp:80: error: no matching function for call to âpoint::point()â cs.cpp:19: note: candidates are: point::point(const point&) cs.cpp:18: note: point::point(char, int) cs.cpp: In member function âdouble PointDistances::dist(point*, point*)â: cs.cpp:89: error: âclass pointâ has no member named ârâ cs.cpp:89: error: âclass pointâ has no member named âthetaâ cs.cpp:90: error: âclass pointâ has no member named ârâ cs.cpp:90: error: âclass pointâ has no member named âthetaâ cs.cpp:94: error: âclass pointâ has no member named âxâ cs.cpp:95: error: âclass pointâ has no member named âyâ cs.cpp:99: error: âclass pointâ has no member named ârâ cs.cpp:99: error: âclass pointâ has no member named âthetaâ cs.cpp:100: error: âclass pointâ has no member named ârâ cs.cpp:100: error: âclass pointâ has no member named âthetaâ cs.cpp:104: error: âclass pointâ has no member named âxâ cs.cpp:105: error: âclass pointâ has no member named âyâ cs.cpp: In member function âvoid PointDistances::add(point*)â: cs.cpp:112: error: âptvecâ was not declared in this scope cs.cpp: In member function âdouble PointDistances::closest()â: cs.cpp:116: error: âptvecâ was not declared in this scope cs.cpp:119: error: no match for âoperator==â in â((PointDistances*)this)->PointDistances::close2 == 0lâ cs.cpp:127: error: base operand of â->â has non-pointer type âpointâ cs.cpp:128: error: expected `;' before â}â token cs.cpp: In function âint main()â: cs.cpp:145: error: no matching function for call to âPointDistances::add(Ppoint&)â cs.cpp:112: note: candidates are: void PointDistances::add(point*) cs.cpp:146: error: no matching function for call to âPointDistances::add(Ppoint&)â cs.cpp:112: note: candidates are: void PointDistances::add(point*) cs.cpp:147: error: no matching function for call to âPointDistances::add(Cpoint&)â cs.cpp:112: note: candidates are: void PointDistances::add(point*) cs.cpp:148: error: no matching function for call to âPointDistances::add(Cpoint&)â cs.cpp:112: note: candidates are: void PointDistances::add(point*) |
vector<point*> ptvec; |
dist |
Ppoint |
Cpoint |
PointDistances |