Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. struct vec2{
  5.     double x,y;
  6.     vec2(){
  7.         x=0;
  8.         y=0;
  9.     }
  10.     vec2(double x_, double y_){
  11.     x = x_;
  12.     y = y_;
  13. }
  14.     double lengh(){
  15.         return sqrt(x*x+y*y);
  16.     }
  17.     void print(){
  18.         cout<<x<<' '<<y<<endl;
  19. }
  20.     void set_polar(double ph, double r){
  21.         y = r*sin(ph);
  22.         x = r*cos(ph);
  23.     }
  24. };
  25. int main()
  26. {
  27.     vec2 a(2,5),b(1,3);
  28.     /*cout<<a.lengh()<<endl;
  29.     cout<<b.lengh()<<endl;*/
  30.  
  31.     a.set_polar(0.785,3);
  32.     b.set_polar(0.785,1);
  33.     a.print();
  34.     b.print();
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement