コード例 #1
0
ファイル: Fig09_04.cpp プロジェクト: tjyang/abmon
int main()
{
   Point *pointPtr = 0, p( 30, 50 );
   Circle *circlePtr = 0, c( 2.7, 120, 89 );

   cout << "Point p: " << p << "\nCircle c: " << c << '\n';

   // Treat a Circle as a Point (see only the base class part)
   pointPtr = &c;   // assign address of Circle to pointPtr
   cout << "\nCircle c (via *pointPtr): " 
        << *pointPtr << '\n';

   // Treat a Circle as a Circle (with some casting)
   // cast base-class pointer to derived-class pointer
   circlePtr = static_cast< Circle * >( pointPtr );  
   cout << "\nCircle c (via *circlePtr):\n" << *circlePtr 
        << "\nArea of c (via circlePtr): "
        << circlePtr->area() << '\n';

   // DANGEROUS: Treat a Point as a Circle
   pointPtr = &p;   // assign address of Point to pointPtr
   
   // cast base-class pointer to derived-class pointer
   circlePtr = static_cast< Circle * >( pointPtr );
   cout << "\nPoint p (via *circlePtr):\n" << *circlePtr
        << "\nArea of object circlePtr points to: "
        << circlePtr->area() << endl;
   return 0;
}
コード例 #2
0
int main() {
	Circle luke (10.5);
	Circle wallace;
	Circle lindsay = 6.2;
	Circle owen(lindsay);
	Circle isaac = luke + lindsay;

	cout << "luke's area: " << luke.area() << "\n";
	cout << "luke's circum: " << luke.circum() << "\n\n";
	cout << "lindsay's area: " << lindsay.area() << "\n";
	cout << "lindsay's circum: " << lindsay.circum() << "\n\n";
	cout << "owen's area: " << owen.area() << "\n";
	cout << "owen's circum: " << owen.circum() << "\n\n";
	cout << "isaac's area: " << isaac.area() << "\n";
	cout << "isaac's circum: " << isaac.circum() << "\n\n";
	cout << "wallace's area: " << wallace.area() << "\n";
	cout << "wallace's circum: " << wallace.circum() << "\n\n\n";

	int a = 123;
	int b = 456;
	cout << "before swap: a = " << a << " and b = " << b << "\n";
	swapInts(a, b);
	cout << "after swap: a = " << a << " and b = " << b << "\n";
	return 0;
}
コード例 #3
0
ファイル: hello.cpp プロジェクト: william30101/MapSample
	JNIEXPORT jint JNICALL Native_StartCal(JNIEnv *env,jobject mc)
	{

		//int *str = (char*)env->GetStringUTFChars(data, NULL);

		Circle* cir = new Circle(5);
		cir->area();
		LOGI("radius = %lf area=%lf",cir->radius,cir->area());
		//cir.


		  return 0;
	}
コード例 #4
0
int main() {
	Circle circle = Circle(5.3, 3.4, 9.88);
	circle.showCircle();
	cout << "Area = " << circle.area() << endl;

	circle.move(12.09, 2);
	// move()继承自Point,在父类中是公有的
	// 公有继承下,move()在子类中是公有的
	// 私有继承下,move()在子类中是私有的,main()中无法访问,但子类可以进行同名覆盖
	circle.showCircle();
	cout << "Area = " << circle.area() << endl;

	return 0;
}
コード例 #5
0
ファイル: Source.cpp プロジェクト: gamefinity/CSDNQA
int main()
{
	Circle cir;
	cout << "圆的面积为:" << cir.area() << endl;
	Cylinder cy;
	cout << "圆柱体的表面积为:" << cy.area() << endl;
	cout << "圆柱体的体积为:" << cy.volume() << endl;
	return 0;
}
コード例 #6
0
double circleoverlap(Circle c1,Circle c2)
{
    double d = dis(c1.c,c2.c);
    if(dcmp(c1.r-c2.r)<0)
        swap(c1,c2);
    if(dcmp(c1.r+c2.r-d)<=0)
        return 0.0;
    else if(dcmp(d+c2.r-c1.r)<=0)
        return c2.area();
    double theta1 = acos((c1.r*c1.r+d*d-c2.r*c2.r)/(2*d*c1.r));
    double theta2 = acos((c2.r*c2.r+d*d-c1.r*c1.r)/(2*d*c2.r));
    return c1.r*c1.r*theta1 + c2.r*c2.r*theta2 - d * c1.r * sin(theta1);
}
コード例 #7
0
	double volume() {return base.area() * height;}