Programming

C++ Program to Convert Degree to Radian & Vice-Versa

Write a program that convert degree to radian & vice-versa using the basic concept degree to radian & vice-versa using the concept of object & class. Make separate class for degree and radian which will have the private member to hold the value & make conversion function in each class for conversion from one to another.

Source Code

#include<iostream>

#include<conio.h>

#define PI 3.1415

using namespace std;

class degree

{

float d,r;

public:

void get_data()

{

    cout<<"Enter the value in degree:";

    cin>>d;

}

void show_data()

    {

        r=d*(PI/180);

        cout<<"the equivalent value in radian is: "<<r<<endl;;

    }

};

class radian

{

float r,d;

public:

void get_data()

    {

        cout<<"Enter the value in radian:";

        cin>>r;

    }

void show_data()

    {

        d=r*(180/PI);

        cout<<"the equivalent value in degree is:"<<d<<endl;

    }

} ;

int main()

{

    degree d;

    d.get_data();

    d.show_data();

    radian r;

    r.get_data();

    r.show_data();

}

Output

Convert Degree to Radian & Vice-Versa

Tuts

About Author

Tutsmaster.org provides tutorials related to tech and programmings. We are also setting up a community for the users and students.