Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

. Solve problem using Array list . Preform file I/O . Apply Geometric concepts t

ID: 3908245 • Letter: #

Question

. Solve problem using Array list

. Preform file I/O

. Apply Geometric concepts that is translated to Java

The program will allow users to read a data from a file about Spheroids

You will read the data, store it appropriately in an object of type Spheroid, and produce the volume and whether the sphere is oblate or prolate. Obviously, you must create a custom class (that must be named Spheroid), and you must provide a means to store the required data.

The required data consist of the equatorial radius and the polar radius Some information related to spheroids:

• A spheroid is oblate if c < a

• A spheroid is prolate if c > a

• A spheroid is a sphere if c = a The volume of a spheroid, regardless of its classification is:

?? = 4 3 ???? 2c

Again, a is the equatorial radius, and c is the polar radius. For a sphere, since a = c, this would reduce to the familiar form ?? = 4 3 ???? 3 .

The input will be obtained from a file, named input.txt.

Equatorial_Radius Polar_Radius Specifically, a single line of example input might be: 5 2

OUTPUT As soon as the file is read into memory and the data is placed in the appropriate data structure(s), the following will be printed to standard output (the console), in general form: Volume Classification Where volume is the calculated volume from the formula, and the classification is oblate, prolate, or sphere.

EXAMPLE SAMPLE INPUT FILE

5 2

10 10

4 3

6 8

SAMPLE OUTPUT

209.44 Oblate

4188.79 Sphere

201.06 Oblate

1206.37 Prolate

HINTS AND NOTABLE REQUIREMENTS

You should consider creating two classes to help you solve the problem:

• Spheroid

o Represents a single spheroid

o Maintains the equatorial and polar radii as fields

o Has a constructor allowing the user to set the equatorial and polar radii (as doubles)

o Has accessors (getters) and mutators (setters) for both the equatorial radius and polar radius

o Can return the volume using a method getVolume ? Returns a double ? Takes no parameters

o Can return the classification of a spheroid, using a method getClassification ? Returns a string ? Takes no parameters ? Calculates the information based on the current equatorial and polar radius

o There should be NO print statements inside this class

•SpheroidDemo

o This class will contain the main method

o You must read the file

o You must create instances of Spheroid, and store them in an ArrayList ? You can use the constructor of the Spheroid immediately with the equatorial and polar radii that are read from file

o Once all information is read from the file and all the spheroid objects are created, loop through the ArrayList of Spheroids and print out their volumes and classifications to the console

Explanation / Answer

#include<iostream>
#include<math.h>
#include<fstream>

using namespace std;

class Spheroid {

   private:
       double a; // equatorial radius
       double c; // polar radius

   public:
       Spheroid(double a1, double c1){
          a = a1;
          c = c1;
       }
       double getVolume(){
          return (4.0/3.0) * M_PI * a * a *c;
       }
       string getShape(){
          if (a == c)
             return "Sphere";
          if (c < a)
             return "Oblate";
          if (c > a)
             return "Prolate";

       }

};

int main(){

   ifstream fin("input.txt");
   if (!fin){
      cout << "Error opening file ";
      return 0;
   }
   double c, a;
   while (fin >> a >> c){
       Spheroid d(a,c);
       cout << d.getVolume() << d.getShape() << endl;
   }
   fin.close();
   return 0;
}