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

Sample format is attached below. SAMPLE! CSE 112-Lab #6 Circle Class-Classes and

ID: 3757174 • Letter: S

Question

Sample format is attached below.

SAMPLE!

CSE 112-Lab #6 Circle Class-Classes and Objects (page 811-#8) and UML Diagram Create a circle class that has the following private member variables 1. Radius: a double 2. Pi: a double initialized to 3.14159 The class will have the following member functions 1. Default Constructor that sets the radius to 0.0 2. A Constructor that accepts the radius of the circle as an argument 3. setRadius- a mutator function for the radius variable 4. getRadius- an accessor function for the radius variable 5. getArea - returns that area of the circle (area pi radius * radius) 6. getDiameter-returns the diameter of the circle (diameter radius* 2) 7. getCircumference returns the circumference of the circle (circ 2*pi * radius) Requirements: Write a program that demonstrates the circle class by prompting the user for the circle's radius (with input validation), create a circle object, and then report the area, diameter, and circumference with the output precision set to (2) two decimal places. Use a separate header file for the class. Add a UML Diagram for the class as a comment below main The program will . Use a separate *.h file for the class and a .cpp file for main. Use 3.14159 as the value for pi Include #ifnder, and #endif directives as required Have a commented UML diagram with Access Specifiers in the program below main (ref pg 793) . . II CLASS NAME II MEMBER VARIABLES II MEMBER FUNCTIONS

Explanation / Answer

#include <iostream>

#include "circleClass.h"

using namespace std;

cont double PI = 3.14159;

//default constructor

//precondition: none

//postcondition: an object has been instantiated with a default radius of 1.

circleClass::circleClass()

{

radius = 1.0;

}

//constructor

//precondition: none

//postcondition: an object has been instantiated with a default radius of r.

circleClass::circleClass(double r)

{

if (r<=0)

{

cout << "An invalid radius has been detected. " <<endl;

cout << "The radius has been set to 1.0"<<endl;

radius = 1.0;

}

else

radius =r;

}

//Destructor

//precondition: an object exists with a valid radius.

//postcondition: the object is destroyed

circleClass::~circleClass()

{

cout << "A circle died"<<endl;

}

//Sets Radius

//precondition: an object exists with a valid radius.

//postcondition: the radius is changed to r.

void circleClass::setradius(double r)

{

//invalid input (r <= 0) is checked for in the calling function.

radius =r;

}

//Gets Radius

//precondition: an object exists with a valid radius.

//postcondition: the radius is changed to r.

double circleClass::getradius()

{

return radius;

}

  

//Calculate the area

//precondition: an object exists with a valid radius.

//postcondition: calculates and returns the area of the circle

double circleClass::area()

{

return (PI * (radius*radius));

}

//Calculate the circumference

//precondition: an object exists with a valid radius.

//postcondition: calculates and returns the circumference of the circle

double circleClass::circum()

{

return (2 * PI * radius);

}

//returns the diameter

//precondition: an object exists with a valid radius.

//postcondition: returns the diameter of the circle

double circleClass::diameter()

{

return (2 * radius);

}

//prints info for a circle

//precondition: an object exists with a valid radius.

//postcondition: prints all information about a circle

void circleClass::print()   

{

cout <<"The info for the circle is as follows"<<endl;

cout <<"Radius = "<<radius<<endl;

cout <<"Diameter = "<<diameter()<<endl;

cout <<"Area = " <<area()<<endl;

cout <<"Circumference = "<<circum()<<endl;

  

  

}

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