Search
 
SCRIPT & CODE EXAMPLE
 

CPP

how to calculate polar coordinates in c++

#include <iostream>
#include <cmath>		// For 'atan()' which is the inverse fuction of 'tan' in C++,
						// and for 'M_PI' which is the real number 'pi'.
void radius();		// Calculate the radius.
void theeta();		// Calculate the angle associated to the couple (x,y) in degree.

void main() {

	int x, y;
	cout << "Enter the x coordinate: " << flush;
	cin >> x;
    
	cout << "enter the y coordinate: " << flush;
	cin >> y;
    
    radius();
    theeta();
}

void radius() {
	float r;
	r = sqrt(x*x + y*y);
	cout << "Radius = " << r << endl;
}

void theeta() {
	float theta, angle;
	theta = atan(y/x);		// 'theta' is the angle associated to the couple (x, y) in radian.
	angle = theta*(180/M_PI);		// The conversion of 'theta' from radian to degree.
	cout << "Theta = " << angle << endl;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to type hello world in c++ 
Cpp :: gmod hitman job code 
Cpp :: qt qchar to lower 
Cpp :: shuffle elements c++ 
Cpp :: std string to wstring 
Cpp :: C++ sqlite open file in other directory 
Cpp :: initialize a pair 
Cpp :: eosio get time 
Cpp :: c++ string to wstring 
Cpp :: factore of 20 in c+ 
Cpp :: set cmd size c++ 
Cpp :: calculate how many liters would be needed 
Cpp :: min heap in c++ 
Cpp :: c++ remove whitespace from string and keep the same size 
Cpp :: qt qstring to double 
Cpp :: oncomponentbeginoverlap ue4 c++ 
Cpp :: c++ print byte as bit 
Cpp :: using find in vector c++ 
Cpp :: how to make a hello world program in c++ 
Cpp :: how to change string to lowercase and uperCase in c++ 
Cpp :: heap buffer overflow c++ 
Cpp :: c++ mst kruskal 
Cpp :: how to iterater map of sets in c++ 
Cpp :: c++ print vector without loop 
Cpp :: random number in a range c++ 
Cpp :: how to make a random number in c++ 
Cpp :: how to make calculaor in c++ 
Cpp :: c++ vector loop delete 
Cpp :: c++ random number within range 
Cpp :: round up 2 digits float c++ 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =