C and C++

Program to converting degree to radian using type conversion

In C++ programming, understanding type conversion is essential for precise mathematical computations. One common real-world application is converting angles from degrees to radians. This is especially useful in trigonometry, graphics, physics simulations, and embedded systems. In this tutorial, we’ll write a C++ program to convert degrees to radians using type conversion to ensure accuracy in calculations.

#include<iostream.h>
class degree
{
private:
float angle, f, t, d, r;
public:
degree();
float radian();
void disp();
};
degree::degree()
{
cout<<"Enter the angle in degree: "; cin>>angle;
}
float degree::radian()
{
const float PIE=3.142857;
r = angle*PIE/180;
return r;
}
void main()
{
float p,x,z;
degree a;
p = a.radian();
cout<<"Angle in radian is: "<<p<<endl;
}
OUTPUT
Enter the angle in degree: 90
Angle in radian is: 1.571429

Why Type Conversion Matters in C++:
Using type conversion ensures that integer division doesn’t lead to loss of data. Without converting degree to double, the result may be incorrect due to truncation.

Leave a comment

Your email address will not be published. Required fields are marked *