Esempio n. 1
1
int main() {
	
	
	// set the radius equal to -1 so we can ensure that
	// the user isgiving us valid input
	// what was the point of a constructor that has us
	// set radius=0? 
	double radius = -1;	

	// keeps asking for radius until positive radius is entered
	do {
		cout << "Please enter a radius: ";
		cin >> radius;
	} while (radius < 0);

	// create a pointer to an instance of a circle
	Circle * c = new Circle(radius);

	// output the area diameter, and circumference measurements
	cout << "The Area of your circle is: " << c->getArea() << endl;
	cout << "The Diameter of your circle is: " << c->getDiameter() << endl;
	cout << "The Circumference of your circle is: " << c->getCircumference() << endl;

	// free up the memory we used for c
	// How do we know if we should do this in the main or in the class?
	delete [] c;

	return 0;
}
Esempio n. 2
0
File: J.cpp Progetto: Voleking/ICPC
/* 三角形一顶点为圆心 */
double getPublicAreaToTriangle (Circle O, Point a, Point b) {
    if (sgn((a-O.o)^(b-O.o)) == 0) return 0;
    int sig = 1;
    double da = getPLength(O.o-a), db = getPLength(O.o-b);
    if (sgn(da-db) > 0) {
        swap(da, db); swap(a, b); sig = -1;
    }

    double t1, t2;
    vector<Point> sol;
    int n = getLineCircleIntersection(a, b, O, t1, t2, sol);

    if (sgn(da-O.r*O.r) <= 0) {
        if (sgn(db-O.r*O.r) <= 0) return getDirArea(O.o, a, b) * sig;

        int k = 0;
        if (n == 2 && getPLength(sol[0]-b) > getPLength(sol[1]-b)) k = 1;

        double ret = getArea(O.o, a, sol[k]) + O.getArea(getAngle(sol[k]-O.o, b-O.o));
        double tmp = (a-O.o)^(b-O.o);
        return ret * sig * sgn(tmp);
    }

    double d = getDistanceToSegment(O.o, a, b);
    if (sgn(d-O.r) >= 0) {
        double ret = O.getArea(getAngle(a-O.o, b-O.o));
        double tmp = (a-O.o)^(b-O.o);
        return ret * sig * sgn(tmp);
    }

    double ret1 = O.getArea(getAngle(a-O.o, b-O.o));
    double ret2 = O.getArea(getAngle(sol[0]-O.o, sol[1]-O.o)) - getArea(O.o, sol[0], sol[1]);
    double ret = (ret1 - ret2), tmp = (a-O.o)^(b-O.o);
    return ret * sig * sgn(tmp);
}
Esempio n. 3
0
void main()
{
	Circle c;
	c.setPoint(1, 1);
	c.getArea();

	c.setPoint(5, 5);
	c.setRadius(6);

	c.setRadius(3);
	cout << c.getArea() << endl;
}
Esempio n. 4
0
double getPublicAreaCircleToCircle(Circle a, Circle b) {
	double dis = getLength(a.o - b.o);

	if (dcmp(dis-a.r-b.r) >= 0) return 0;

	if (dis <= fabs(a.r - b.r)) { return min(a.getArea(2*pi), b.getArea(2*pi)); }

	double ang1 = getAngle(a.r, dis, b.r);
	double ang2 = getAngle(b.r, dis, a.r);
	double ret = ang1 * a.r * a.r + ang2 * b.r * b.r - dis * a.r * sin(ang1);
	return ret;
}
Esempio n. 5
0
void UseVector::printVector() {
	vector<Shape*>::iterator vectorIterator;
	Circle *circleElement;
	Rectangle *rectangleElement;
	Triangle *triangleElement;

	for (vectorIterator = shapeVector->begin(); vectorIterator < shapeVector->end(); vectorIterator++) {
		if ((*vectorIterator)->getShapeType() == "Circle") {
			circleElement = dynamic_cast<Circle*>((*vectorIterator));
			cout << "The circle has a area of " << (*vectorIterator)->getArea() << endl;;
			cout << "The circleElement has an area of " << circleElement->getArea() << endl;
			this->printElement(circleElement);
		} else if ((*vectorIterator)->getShapeType() == "Rectangle") {
			rectangleElement = dynamic_cast<Rectangle*>((*vectorIterator));
			cout << "The rectangle has a area of " << (*vectorIterator)->getArea() << endl;
			cout << "The rectangleElement has an area of " << rectangleElement->getArea() << endl;
			this->printElement(rectangleElement);
		} else if ((*vectorIterator)->getShapeType() == "Triangle") {
			triangleElement = dynamic_cast<Triangle*>((*vectorIterator));
			cout << "The triangle has a area of " << (*vectorIterator)->getArea() << endl;
			cout << "The triangleElement has an area of " << triangleElement->getArea() << endl;
			this->printElement(triangleElement);
		}
	}
}
Esempio n. 6
0
int main() {
    Circle circle;
    double radius;
    cout<<"enter the circle's radius: ";
    cin>>radius;

    circle.setRadius(radius);

    cout<<"the circle's area is "<<circle.getArea()<<endl;
    cout<<"the circle's diameter is "<<circle.getDiameter()<<endl;
    cout<<"the circle's circumference is "<<circle.getCircumference()<<endl;

   return 0;
}
int main(int argc, char** argv) {
    float rad;
    Circle info;
    //input 
    cout<<"Input the radius"<<endl;
    cin>>rad;
    info.setRadius(rad);
    cout<<"Circle Information\n";
    cout<<"Area: "<<info.getArea(rad,PI)<<endl;
    cout<<"Diameter: "<<info.getDiameter(rad)<<endl;
    cout<<"Circumference: "<<info.getCircum(rad,PI)<<endl;
   
    return 0;
}
Esempio n. 8
0
/*
 * The Circle main thread
 */
int main(int argc, char** argv) {

    double radius;
    
    cout << "Please enter the radius of a circle: ";
    cin >> radius;
    
    Circle* circle = new Circle(radius);
    
    cout << "The area of this circle is: " << circle->getArea() << endl;
    cout << "The diameter of this circle is: " << circle->getDiameter() << endl;
    cout << "The circumference of this circle is: " << circle->getCircumference() << endl;
    return 0;
}
int main()
{
    Circle dayra;
    string CircleColor = "blue" ;
    dayra.setColor(CircleColor);
    cout<< dayra.getColor()<<" "<< dayra.isfilled()<<" before set "<< "\n";
    dayra.setfilled() ;
    cout<< dayra.isfilled()<<"\n" ;
    dayra.setRadius(5);
    Rectangle mostatel;
    mostatel.setWidth(5);
    mostatel.setLength(5);
    mostatel.setColor(CircleColor);
    cout << dayra.getArea()<< " area "<<mostatel.getArea() << "\n" ;
    cout << dayra.getPerimeter() << " prmtr " << mostatel.getPerimeter() << "\n" ;
    dayra.toString();
     cout << "\n" ;
     mostatel.toString() ;

    return 0;
}
Esempio n. 10
0
//Copy Constructor
Circle :: Circle(const Circle &rhs){
radius = rhs.getRadius();
Area = rhs.getArea();
X = rhs.getX();
Y = rhs.getY();
}
void printCircle(Circle &c) {
  cout << "The area of the circle of " <<
          c.getRadius() << " is " << c.getArea() << endl;
}