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

c++ * Be sure to add your name as a cout in the first lines of each program - el

ID: 3884574 • Letter: C

Question

c++

* Be sure to add your name as a cout in the first lines of each program - else 0 credit.

       * Add constructors - a default and parameterized constructor to each.

       * Write an .h interface and a .cpp implementation for each class

       * Write an Drive/Test file that tests the constructors and functions

       * Write a UML class diagram for each class

cout << "Name: YOURNAME - Program Name: PROGRAM NAME - Date: MMDDYY" << endl;

Example:  cout << "Name: Jon Smith - Program Name: Prog9Box - Date: 6/28/17" << end;

Program 7 - Circle

You write ALL the code,

then run it - Produce the correct output. Turn in code and screen print of successful run, for credit

* Write a class for a Circle

* Input only the radius.

* Write functions that Calculate the circles Circumference, Area and Diameter, and print out the value of the radius

* Include error checking for radius, must be greater than zero

Explanation / Answer

/* The Circle class Header (Circle.h) */
#include <iostream>   
using namespace std;

// Circle class declaration
class Circle {
private: // Accessible by members of this class only
// private data members (variables)
double radius;

public:   
// Declare prototype of member functions
// Constructor with default values
Circle(double radius);

// Public getters & setters for private data members
double getRadius() ;
void setRadius(double radius);
// Public member Function
double getDiameter();
double getArea();
double getCircumference();
};

/* The Circle class Implementation (Circle.cpp) */

#include "Circle.h"

// Constructor

Circle::Circle(double r)

{

if(r < 0)

{

cout << "Radius cannot be negative ";

radius = 0;

}

else

{

radius = r;

}

}

// Public getter for private data member radius

double Circle::getRadius()

{

return radius;

}

// Public setter for private data member radius

void Circle::setRadius(double r)

{

if(r < 0)

{

cout << "Radius cannot be negative ";

radius = 0;

}

else

{

radius = r;

}

}

// A public member function

double Circle::getDiameter()

{

return 2*radius;

}

// A public member function

double Circle::getArea()

{

return radius*radius*3.14159265;

}

// A public member function

double Circle::getCircumference()

{

return 2*radius*3.14159265;

}


/* A test driver for the Circle class (TestCircle.cpp) */
#include <iostream>
#include "Circle.h" // using Circle class
using namespace std;

int main()
{
// Construct an instance of Circle c1
Circle c1(4.2);
cout << " Radius =" << c1.getRadius() << " Diameter =" << c1.getDiameter() << " Area =" << c1.getArea() << " Circumference = " << c1.getCircumference() << endl;

double r;
cout << " Enter Radius: ";
cin >> r;

Circle c2(r);
cout << "Radius =" << c2.getRadius() << " Diameter =" << c2.getDiameter() << " Area =" << c2.getArea() << " Circumference = " << c2.getCircumference() << endl;

return 0;
}

/*
output:


Radius =4.2
Diameter =8.4
Area =55.4177
Circumference = 26.3894


Enter Radius: -2
Radius cannot be negative
Radius =0
Diameter =0
Area =0
Circumference = 0

*/

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