Given the Point class defined in the attached \"point.h\" and the Sphere class d
ID: 3570983 • Letter: G
Question
Given the Point class defined in the attached "point.h" and the Sphere class described in the following declaration (and in the attached "student.h")
Add the following functionality:
Constructors
Implement the second Sphere constructor. The constructor must throw a double exception when given an invalid radius.
Getters
Implement functions to return the values of the private attributes of a Sphere object. For example, given:
S.getCenter() should return a point equal to P
S.getRadius() should return 10
Methods: Area and Volume
Implement functions to compute the surface area and volume of a sphere, given the following information:
PI = 3.14159265358979323846
So, given the following code:
Method: Logic
Implement a function that checks whether a Point is inside the calling sphere. For example, given:
S.in(P) returns true
S.in(P2) returns false
Note: You do not have to account for the Point P possibly being on the boundary of the Sphere.
Method: operator <
Overload the < operator so that it can be used to evaluate whether one sphere is bigger than another. For example, given:
S1<S2 returns true
S3<S2 returns false
friend: largest
Implement a function that returns the largest sphere in a list of spheres. The function should throw an integer exception on empty input. Given:
largest(spheres) should return a sphere equal to S3
If the vector contains identical elements, such as in the following example:
largest(spheres) should return a sphere equal to any element in the vector (S1, S2, or S3 for example)
Given the Point class defined in the attached ''point.h'' and the Sphere class described in the following declaration (and in the attached ''student.h'') class Sphere{ private: Point center; double radius; public: Sphere(); Sphere(Point c, double r); Point getCenter(); double getRadius(); double surfaceArea(); double volume(); bool in(Point P); bool operatorExplanation / Answer
import java.util.Random; class Shape { void drawShape() { } void eraseShape() { } } class Circle extends Shape { @Override void drawShape() { System.out.println("Circle.draw()"); } @Override void eraseShape() { System.out.println("Circle.erase()"); } } class Square extends Shape { @Override void drawShape() { System.out.println("Square.draw()"); } @Override void eraseShape() { System.out.println("Square.erase()"); } } class Triangle extends Shape { @Override void drawShape() { System.out.println("Triangle.draw()"); } @Override void eraseShape() { System.out.println("Triangle.erase()"); } } // A "factory" that randomly creates shapes: class RandomShapeGenerator { private Random rand = new Random(); //Choose randomly a circle, a squere or a triangle public Shape next() { switch (rand.nextInt(3)) { default: case 0: return new Circle(); case 1: return new Square(); case 2: return new Triangle(); } } } public class Polymorphism { private static RandomShapeGenerator gen = new RandomShapeGenerator(); public static void main(String[] args) { //This is an array of references of the superclass Shape Shape[] s = new Shape[9]; // Fill up the array with random shapes shapes: for (int i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.