// Calculation Program for the plane area of an egg shaped curve, 08 (Tues.) Dec., 2009

// egg equation: (x*x+y*y)**2=a*(x**3)+(a-b)*x*(y**2), The case that a=4 and b=3.2 (or, a=1 and b=0.8) may be the nearest shape to an actual egg.
// The general condition needs b<=a, and in the case of b=0, the curve is led to a circle.

// file name: area.c

#include< stdio.h>
#include< math.h>

void main(void)
{
	double a,b,x,y,dx,xmax,area,darea,pi;

	for(;;)
	{
		printf("Input of constant a; a= ? ");
		scanf("%lf",&a);
		if(a>0)
		{
			break;
		}
		else
		{
			printf("Please input the value of a after correcting a as a>0.\n");
		}
	}
	for(;;)
	{
		printf("Input of constant b; b= ? ");
		scanf("%lf",&b);
		if(b>=0&&b<=a)
		{
			break;
		}
		else
		{
			printf("Pleease input the value of b after correcting b as 0< b < a or b=0 or b=a.\n");
		}
	}

	printf("\n");

	pi=3.1415927;

	xmax=a;// the maximum value of x
	dx=xmax/100000;

// execution of calculation
	if(b==0)
	{
		area=pi*a*a/4;
	}
	else
	{
		for(x=0;x<=xmax;x=x+dx)
		{
			y=sqrt(((a-b-2*x)+sqrt(4*b*x+(a-b)*(a-b)))*x/2);
			darea=y*dx;
			area=area+darea;
		}
		area=2.0*area;
	}

	printf("The plane area of the egg shaped curve; A=%lf\n",area);
	printf("\n");

	printf("end\n");
}// the end of the program



RETURN