Mathematical and Trigonometric Methods in Calculator Applicaiton

Implementing the Mathematical and Trigonometric Method



The Mathematical and trigonometric related methods are defined in the Math_class. The trigonometric related methods are sin and cos. The mathematical related methods that you can perform in the Calculator application are square, square root, factorial and pow.

The sin_func() method is defined to calculate the trigonometric sine value of an integer. The sin_func() accepts one argument of data type, double, and returns a value of data type, double.

Declaring sin_func() Method

public static double sin_func(double x)
{
if (x<=0.0005)
  x=x+((x*x*x)/6);
else
  x=2*sin_func(x/2)*cos_func(x/2);
return x;
}


The above listing shows the declaration of the sin_func() method that calculates the sine of a numeric value of double data type.


=============================================================

The cos_func() method id defined to calculate the cosine value of an integer. The cos_func() accepts one argument of double data type and returns a value of double data type.

Declaring cos_func()


public static double cos_func (double x)
{
if (x<=0.0005)
  x=1-((x*x*x)/2);
else
  x=(cos_func(x/2)*cos_func(x/2))-(sin_func(x/2)*sin_func(x/2));
return x;
}// End of cos_func() method.


The above listing shows the declaration of the cos_func() method that calculates the cosine of a numeric value of double data type.


=============================================================

The convert_rad_deg() is defined to convert the radian value into degree value. The convert_rad_deg() accepts one argument of double data type and returns a value of double data type.

Declaring convert_rad_deg() Method


public static double convert_rad_deg (double x)
{
//converting from radian to degree 
double y;
y=(180*x)/Math.PI;
return y;
}

The above listing shows the declaration of the convert_rad_deg() method that converts the radian value of to equivalent degree value of double data type.


=============================================================

The convert_deg_rad() is defined to convert the degree value into radian value. The convert_deg_rad() accepts one argument of double data type and returns a value of double data type.

Declaring the convert_deg_rad() Method

public static double convert_deg_rad (double x)
{
//Converting from degree to radian.
double y;
y=(Math.PI*x)/180;
return y;
}

The above listing shows the declaration of the convert_deg_rad() method that converts the degree value to equivalent radian value of double data type.


=============================================================

The pow_func() is defined to calculate the value of power method. The pow_func() accepts two arguments of double and int data types adn returns a value of double data type.

Declaring the pow_func() Method

public static double pow_func(double x,int y)
{
double s;
s=1;
for(int i=1;i<=y;i++)
  s=s*x;
return s;
}

The above listing shows the declaration of the pow_func() method.



=============================================================

The sqr_func() is defined to calculate the square of a number. The sqr_func() accepts one argument of double data type and value of daouble data type.

Declaring the sqr_func() Method


public static double sqr_func (double x)
{
            double s=x*x;
            return s;
}

The above listing shows the decarationf of the sqr_func() method. The sqr_func method calculates square of a variable of double data type.

The fact_func() method is defined to calculates the factorial of a number. The fact_func() method accepts one argument of int data types and returms a value of data type, long.


=============================================================

Declaring the fact_func() Method


public static long fact_func (int x)
//Factorial method.
{
long t=1;
for(int i=x;i>0;i--)
  t=i*t;
return t;
}

The above listing shows the declaration of the fact_func() method.

0 Comments:

Post a Comment