In: Computer Science
Please separate this code with different header files thank you.
#include<iostream>
//bismark
using namespace std;
public:
class Circle {
private double radius;
private char color;
private boolean filled;
public Circle(double radius, char color, boolean
filled) {
super();
this.radius = radius;
this.color = color;
this.filled = filled;
}
public Circle() {
super();
this.radius = 0;
this.color = 'W';
this.filled = false;
}
public Circle(double radius) {
super();
this.radius = radius;
this.color = 'W';
this.filled = false;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public char getColor() {
return color;
}
public void setColor(char color) {
this.color = color;
}
public boolean isFilled() {
return filled;
}
public void setFilled(boolean filled) {
this.filled = filled;
}
public double getCircumference(double r)
{
return 2 * 3.14*r;
}
public double getArea(double r)
{
return 3.14*r*r;
}
}
circle.h
class Circle
{
private:
double radius;
char color;
bool filled;
public:
//constructors
Circle(double radius, char color, bool filled);
Circle();
Circle(double radius);
//getter and setter methods
double getRadius();
void setRadius(double radius);
char getColor();
void setColor(char color);
bool isFilled();
void setFilled(bool filled);
//helper methods
double getCircumference(double r);
double getArea(double r);
};
Circle.cpp
#include "circle.h"
Circle::Circle(double radius, char color, bool filled)
//parametrized constructor
{
this->radius = radius;
this->color = color;
this->filled = filled;
}
Circle::Circle() //default constructor
{
this->radius = 0;
this->color = 'W';
this->filled = false;
}
Circle::Circle(double radius) //parametrized constructor
{
this->radius = radius;
this->color = 'W';
this->filled = false;
}
//getter and setter methods
double Circle::getRadius()
{
return radius;
}
void Circle::setRadius(double radius)
{
this->radius = radius;
}
char Circle::getColor()
{
return color;
}
void Circle::setColor(char color)
{
this->color = color;
}
bool Circle::isFilled()
{
return filled;
}
void Circle::setFilled(bool filled)
{
this->filled = filled;
}
//helper methods
double Circle::getCircumference(double r)
{
return 2 * 3.14*r;
}
double Circle::getArea(double r)
{
return 3.14*r*r;
}
mainTest.cpp
#include <iostream>
#include "circle.cpp"
using namespace std;
int main()
{
//testing the class Circle
Circle c(10);
cout << "Circumference: " <<
c.getCircumference(c.getRadius()) << endl;
cout << "Area: " << c.getArea(c.getRadius()) <<
endl;
return 0;
}
Output:
