Advertisement
YouBlackHole

SelectorProcedure

Feb 15th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. class Ponto {
  7.    
  8.     // Access specifier
  9.     public:
  10.  
  11.     // Coordenadas cartesianas
  12.     float x = 0, y = 0;
  13.    
  14.     // Procedimentos seletores
  15.    
  16.     float& getX (){
  17.         return x;
  18.     }
  19.  
  20.     float& getY (){
  21.         return y;
  22.     }
  23.        
  24.     // Coordenadas polares:
  25.    
  26.     // arctan de (y/x)
  27.     float getTeta (){
  28.         return atan ((y/x));
  29.     }
  30.        
  31.     // raiz de (x² + y²)
  32.     float getR (){
  33.         return sqrt(pow (x, 2) + pow (y, 2));
  34.     }    
  35. };
  36.  
  37. int main() {
  38.  
  39.     cout<<"Abstrações procedimentais: procedimento seletor\n";
  40.    
  41.     // Declare an object of class pointer
  42.     Ponto ponto;
  43.  
  44.     ponto.getX() = 1;
  45.     ponto.getY() = 2;
  46.    
  47.    
  48.     cout <<"X: " << ponto.getX() << "\n" <<
  49.         "Y: " << ponto.getY() << "\n" <<
  50.         "R: " << ponto.getR() << "\n" <<
  51.         "Teta: " << ponto.getTeta();
  52.    
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement