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

Write a C++ program which has a main-driver and an Ellipse class that has the fo

ID: 3909172 • Letter: W

Question

Write a C++ program which has a main-driver and an Ellipse class that has the following member variables:
• semi-major-axis  A : a double
• semi-minor axis  B : a double
• const pi initialized with the value 3.141592
The class should have the following member functions:
Default Constructor. A default constructor that sets A and B to 0.0.
Constructor. Accepts the semi-major-axis  A and semi-minor axis  B of the ellipse as arguments.
setMajor. A mutator function for the semi-major-axis  A variable.
getMajor. An accessor function for the semi-major-axis  A variable.
setMinor. A mutator function for the semi-minor axis  B variable.
getMinor. An accessor function for the semi-minor axis  B variable.
getArea. Returns the area of the ellipse, which is calculated as area = pi * A * B
getCircumference. Returns the circumference of the ellipse, which is calculated
approximately in 2 steps:
  h = ((A - B)(A - B)) / ((A + B)(A + B))
circumference = pi * (A + B) * ( 1 + 3*h / ( 10 + sqrt( 4 - 3*h )  )      )
Sorry, but there is no easier way to compute this more exactly.  
Write a program that demonstrates the Circle class by asking the user for the ellipse’s
A and B (using member functions), creating a Ellipse object, and then reporting the ellipse’s area and circumference. Now you can study the orbits of the planets!

Explanation / Answer

#include <iostream>
#include <math.h>
using namespace std;

class Ellipse{
public:
double A;
double B;
const double pi = 3.141592;
Ellipse(){
A = 0.0;
B = 0.0;
}
Ellipse(double a, double b){
A = a;
B = b;
}
void setMajor(double a){
A = a;
}
double getMajor(){
return A;
}
void setMinor(double b){
B = b;
}
double getMinor(){
return B;
}
double getArea(){
double area = pi * A * B;
return area;
}
double getCircumference(){
double h = ((A - B)*(A - B)) / ((A + B)*(A + B));
double circumference = pi * (A + B) * ( 1 + 3*h / ( 10 + sqrt( 4 - 3*h ) ) );
return circumference;
}
};

int main(){
Ellipse obj1(5, 6);
cout << obj1.getArea() << endl;
cout << obj1.getCircumference() << endl;
}

**Comment for any further queries.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote