Advertisement
YouBlackHole

SelectorProcedureV4

Feb 19th, 2020
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.08 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.     private:
  10.  
  11.     // Coordenadas cartesianas
  12.     float x = 0, y = 0;
  13.     bool polar = false;
  14.    
  15.     // Access specifier
  16.     public:
  17.    
  18.     // --- Procedimentos seletores ---
  19.    
  20.     float& getEntryA (){
  21.         return x;
  22.     }
  23.  
  24.     float& getEntryB (){
  25.         return y;
  26.     }
  27.    
  28.     bool& getCoordinate (){
  29.         return polar;
  30.     }
  31.    
  32.     // --------------------------------
  33.    
  34.     // entrada a e b em graus.
  35.     Ponto (float a, float b, bool polarValue){
  36.         x = a;
  37.         y = b;
  38.         polar = polarValue;
  39.     }
  40.    
  41.     // Conversão para coordenadas polares:
  42.    
  43.     // arctan de (y/x)
  44.     float getTeta (){
  45.         if (polar == false){
  46.             // IV quadrante:
  47.             if (getEntryA() > 0 && getEntryB() < 0){
  48.                 return (atan2 (getEntryB(), getEntryA()) + (2*M_PI)) * 180/M_PI;
  49.             }
  50.             // II e III quadrante:
  51.             else if ((getEntryA() < 0 && getEntryB() > 0) ||
  52.                     (getEntryA() < 0 && getEntryB() < 0) ){
  53.                 return (atan2 (getEntryB(), getEntryA()) + (M_PI)) * 180/M_PI;
  54.             }
  55.             else{
  56.                 return atan2 (getEntryB(), getEntryA()) * 180/M_PI;  
  57.             }
  58.         }
  59.         else{
  60.             return getEntryB();  
  61.         }
  62.     }
  63.    
  64.     // raiz de (x² + y²)
  65.     float getR (){
  66.         if (polar == false){
  67.             return (sqrt(pow (getEntryA(), 2) + pow (getEntryB(), 2)));
  68.         }
  69.         else {
  70.             return getEntryA();
  71.         }
  72.     }
  73.    
  74.     // Conversão para coordenadas cartesianas:
  75.    
  76.     // x = r cosθ
  77.     float getX (){
  78.         if (polar == false){
  79.             return getEntryA();
  80.         }
  81.         else{
  82.             return (getEntryA()*cos((getEntryB()*(M_PI))/180));
  83.         }
  84.     }
  85.    
  86.     // y = r sinθ
  87.     float getY (){
  88.         if (polar == false){
  89.             return getEntryB();
  90.         }
  91.         else{
  92.             return (getEntryA()*sin((getEntryB()*(M_PI))/180));  
  93.         }
  94.     }
  95.    
  96.     void showCoordinate(){
  97.         cout << "X: " << getX()<< "\n";
  98.         cout << "Y: " << getY()<< "\n";
  99.         cout << "R: " << getR()<< "\n";
  100.         cout << "Teta: " << getTeta()<< "\n\n";  
  101.     }
  102. };
  103.  
  104. int main() {
  105.  
  106.     cout<<"Abstrações procedimentais: procedimento seletor\n";
  107.    
  108.     // Declare an object of class pointer
  109.     Ponto ponto(7, 7, false);
  110.     ponto.showCoordinate();
  111.    
  112.     // Can be: X, Y or R, Teta, respectively.
  113.     ponto.getEntryA() = 9.89949;
  114.     ponto.getEntryB() = 45;
  115.     ponto.getCoordinate() = true;
  116.    
  117.     ponto.showCoordinate();
  118.    
  119.        
  120.     // Can be: X, Y or R, Teta, respectively.
  121.     ponto.getEntryA() = 19;
  122.     ponto.getEntryB() = -25;
  123.     ponto.getCoordinate() = false;
  124.    
  125.     ponto.showCoordinate();
  126.    
  127.     // Can be: X, Y or R, Teta, respectively.
  128.     ponto.getEntryA() = 7;
  129.     ponto.getEntryB() = 270;
  130.     ponto.getCoordinate() = true;
  131.    
  132.     ponto.showCoordinate();
  133.    
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement