Question

In: Computer Science

Please separate this code with different header files thank you. #include<iostream> //bismark using namespace std; public:...

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;
   }


}

Solutions

Expert Solution

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:


Related Solutions

What is the flowchart for this code. Thank You! #include<iostream> #include<iomanip> #include<string> #include<cmath> using namespace std;...
What is the flowchart for this code. Thank You! #include<iostream> #include<iomanip> #include<string> #include<cmath> using namespace std; float series(float r[], int n) {    float sum = 0;    int i;    for (i = 0; i < n; i++)        sum += r[i];    return sum; } float parallel(float r[], int n) {    float sum = 0;    int i;    for (i = 0; i < n; i++)        sum = sum + (1 / r[i]);...
--- TURN this Code into Java Language --- #include <iostream> #include <string> using namespace std; //...
--- TURN this Code into Java Language --- #include <iostream> #include <string> using namespace std; // constants const int FINAL_POSITION = 43; const int INITIAL_POSITION = -1; const int NUM_PLAYERS = 2; const string BLUE = "BLUE"; const string GREEN = "GREEN"; const string ORANGE = "ORANGE"; const string PURPLE = "PURPLE"; const string RED = "RED"; const string YELLOW = "YELLOW"; const string COLORS [] = {BLUE, GREEN, ORANGE, PURPLE, RED, YELLOW}; const int NUM_COLORS = 6; // names...
In C++, assuming you have the following incomplete code: #include<iostream> #include <unistd.h> using namespace std; //...
In C++, assuming you have the following incomplete code: #include<iostream> #include <unistd.h> using namespace std; // Structure for storing the process data struct procData { char pname[5]; // Name of a process int arrivt; //Arrival time of a process int pburst; // Burst time of a process int endtime; // Exit time/ Leaving time of a process int remburst; // Remaining burst time of a process int readyFlag; // boolean, Flag for maintaining the process status }; // Global variable...
Trace this code: 1) #include<iostream> using namespace std;    class Test {     int value; public:     Test(int...
Trace this code: 1) #include<iostream> using namespace std;    class Test {     int value; public:     Test(int v); };    Test::Test(int v) {     value = v; }    int main() {     Test t[100];     return 0; } =================================================================== 2) #include <iostream> using namespace std; int main() {                 int i, j;                 for (i = 1; i <= 3; i++)                 {                                 //print * equal to row number                                 for (j = 1; j <= i; j++)                                 {                                                 cout...
Please write variables and program plan(pseudocode) of this C++ programming code: #include <iostream> using namespace std;...
Please write variables and program plan(pseudocode) of this C++ programming code: #include <iostream> using namespace std; void leapYear(int x); int main() { int x; cout << "Enter a year: "; cin >> x; leapYear (x);   return 0; } void leapYear(int x ) {    if (x % 400 == 0)    {    cout << "This is a leap Year";}    else if    ((x % 4 == 0) && (x % 100 != 0))    {    cout <<...
write the algorithm for this the code?!. #include<iostream> using namespace std; #include<string.h> int main() { char...
write the algorithm for this the code?!. #include<iostream> using namespace std; #include<string.h> int main() { char plain[50], cipher[50]="", decrypt[50]=""; int subkeys[50], len;       cout<<"Enter the plain text:"<<endl; cin>>plain;    cout<<"Enter the first subkey:"<<endl; cin>>subkeys[0];    _strupr(plain);    len = strlen(plain);    /**********Find the subkeys**************/    for(int i=1; i<len; i++) { if ((plain[i-1]>='A') && (plain[i-1]<='Z')) { subkeys[i] = plain[i-1]-65; } }    /****************ENCRYPTION***************/       for(int i=0; i<len; i++) { if ((plain[i]>='A') && (plain[i]<='Z')) {    cipher[i] = (((plain[i]-65)+subkeys[i])%26)+65; }...
Complete the C++ code #include <iostream> #include <stdlib.h> #include <time.h> using namespace std; struct Cell {...
Complete the C++ code #include <iostream> #include <stdlib.h> #include <time.h> using namespace std; struct Cell { int val; Cell *next; }; int main() { int MAX = 10; Cell *c = NULL; Cell *HEAD = NULL; srand (time(NULL)); for (int i=0; i<MAX; i++) { // Use dynamic memory allocation to create a new Cell then initialize the // cell value (val) to rand(). Set the next pointer to the HEAD and // then update HEAD. } print_cells(HEAD); }
I need the following code completed: #include <iostream> #include <time.h> #include "CSVparser.hpp" using namespace std; //============================================================================...
I need the following code completed: #include <iostream> #include <time.h> #include "CSVparser.hpp" using namespace std; //============================================================================ // Global definitions visible to all methods and classes //============================================================================ // forward declarations double strToDouble(string str, char ch); // define a structure to hold bid information struct Bid { string bidId; // unique identifier string title; string fund; double amount; Bid() { amount = 0.0; } }; // FIXME (1): Internal structure for tree node struct Node {    Bid data; Node *left; Node...
what am I doing wrong here? thank you! #include <iostream> #include <string> using namespace std; class...
what am I doing wrong here? thank you! #include <iostream> #include <string> using namespace std; class DivSales { private:    int quarterSales[4];    static double totalSales; public:    void add(int, int, int, int);    int sales(int);    static double getValue()    {        return totalSales;    };    void DivSales::add(int s1, int s2, int s3, int s4)    {        quarterSales[0] = s1;        quarterSales[1] = s2;        quarterSales[2] = s3;        quarterSales[3] = s4;...
Complete the code provided to add the appropriate amount to totalDeposit. #include <iostream> using namespace std;...
Complete the code provided to add the appropriate amount to totalDeposit. #include <iostream> using namespace std; int main() { enum AcceptedCoins {ADD_QUARTER, ADD_DIME, ADD_NICKEL, ADD_UNKNOWN}; AcceptedCoins amountDeposited = ADD_UNKNOWN; int totalDeposit = 0; int usrInput = 0; cout << "Add coin: 0 (add 25), 1 (add 10), 2 (add 5). "; cin >> usrInput; if (usrInput == ADD_QUARTER) { totalDeposit = totalDeposit + 25; } /* Your solution goes here */ else { cout << "Invalid coin selection." << endl;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT