Sunday 15 June 2014

C++ program to convert degree to radian and vice versa

C++ program to convert degree to radian and vice versa. First program converts degree to radian and second program converts radian to degree and in third program to convert degree to radian and vice versa using class.


C++ program to convert degree to radian

#include<iostream>
using namespace std;
int main()
{
    float rad,degree;
    cout<<"Enter the value in degree ";
    cin>>degree;
    rad=degree*22/(180*7);
    cout<<degree<<" degree = "<<rad<<" radian";
    return 0;
}

OUTPUT




C++ program to convert radian to degree

#include<iostream>
using namespace std;
int main()
{
    float rad,degree;
    cout<<"Enter the value in radian ";
    cin>>rad;
    degree=rad*180*7/22;
    cout<<rad<<" rad = "<<degree<<" degree";
    return 0;
}

OUTPUT




C++ program to convert degree to radian and vice versa using class

#include<iostream>
using namespace std;
class convert
{
private:
    float degree,radian;
public:

    void getradian()
    {
        cout<<"Enter the value in radian : ";
        cin>>radian;
    }
    void getdegree()
    {
        cout<<"Enter the value in degree : ";
        cin>>degree;
    }
    void radtodeg()
    {
        degree=radian*180*7/22;
    }
    void degtorad()
    {
        radian=degree*22/(180*7);
    }
    void showrad()
    {
        cout<<"Radian = "<<radian;
    }
    void showdeg()
    {
        cout<<"Degree = "<<degree;
    }
};
int main()
{
    convert obj;
    int choice;
    float result;
    cout<<"*****Menu*****\n1.) Convert Radian to Degree\n2.) Convert Degree to Radian\nEnter your choice : ";
    cin>>choice;
    switch(choice)
    {
    case 1 :
        obj.getradian();
        obj.radtodeg();
        obj.showdeg();
        break;
    case 2:
        obj.getdegree();
        obj.degtorad();
        obj.showrad();
        break;
    default :
        cout<<"Sorry wrong choice ";
    }
    return 0;
}


OUTPUT


1 comment:

  1. This is not a very good way of doing this. Very inaccurate. You should use a better approximation of pi than 22/7.

    ReplyDelete