Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- class Ponto {
- // Access specifier
- private:
- // Coordenadas cartesianas
- float x = 0, y = 0;
- bool polar = false;
- // Access specifier
- public:
- // --- Procedimentos seletores ---
- float& getEntryA (){
- return x;
- }
- float& getEntryB (){
- return y;
- }
- bool& getCoordinate (){
- return polar;
- }
- // --------------------------------
- // entrada a e b em graus.
- Ponto (float a, float b, bool polarValue){
- x = a;
- y = b;
- polar = polarValue;
- }
- // Conversão para coordenadas polares:
- // arctan de (y/x)
- float getTeta (){
- if (polar == false){
- // IV quadrante:
- if (getEntryA() > 0 && getEntryB() < 0){
- return (atan2 (getEntryB(), getEntryA()) + (2*M_PI)) * 180/M_PI;
- }
- // II e III quadrante:
- else if ((getEntryA() < 0 && getEntryB() > 0) ||
- (getEntryA() < 0 && getEntryB() < 0) ){
- return (atan2 (getEntryB(), getEntryA()) + (M_PI)) * 180/M_PI;
- }
- else{
- return atan2 (getEntryB(), getEntryA()) * 180/M_PI;
- }
- }
- else{
- return getEntryB();
- }
- }
- // raiz de (x² + y²)
- float getR (){
- if (polar == false){
- return (sqrt(pow (getEntryA(), 2) + pow (getEntryB(), 2)));
- }
- else {
- return getEntryA();
- }
- }
- // Conversão para coordenadas cartesianas:
- // x = r cosθ
- float getX (){
- if (polar == false){
- return getEntryA();
- }
- else{
- return (getEntryA()*cos((getEntryB()*(M_PI))/180));
- }
- }
- // y = r sinθ
- float getY (){
- if (polar == false){
- return getEntryB();
- }
- else{
- return (getEntryA()*sin((getEntryB()*(M_PI))/180));
- }
- }
- void showCoordinate(){
- cout << "X: " << getX()<< "\n";
- cout << "Y: " << getY()<< "\n";
- cout << "R: " << getR()<< "\n";
- cout << "Teta: " << getTeta()<< "\n\n";
- }
- };
- int main() {
- cout<<"Abstrações procedimentais: procedimento seletor\n";
- // Declare an object of class pointer
- Ponto ponto(7, 7, false);
- ponto.showCoordinate();
- // Can be: X, Y or R, Teta, respectively.
- ponto.getEntryA() = 9.89949;
- ponto.getEntryB() = 45;
- ponto.getCoordinate() = true;
- ponto.showCoordinate();
- // Can be: X, Y or R, Teta, respectively.
- ponto.getEntryA() = 19;
- ponto.getEntryB() = -25;
- ponto.getCoordinate() = false;
- ponto.showCoordinate();
- // Can be: X, Y or R, Teta, respectively.
- ponto.getEntryA() = 7;
- ponto.getEntryB() = 270;
- ponto.getCoordinate() = true;
- ponto.showCoordinate();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement