Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementa codigo fonte do exercicio 2 #49

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added lista06/ex02/src/a.out
Binary file not shown.
31 changes: 31 additions & 0 deletions lista06/ex02/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <iostream>
#include "numeros_complexos.hpp"

int main(int argc, char *argv[]) {

// Cria numeros complexos
NumComplexo a = NumComplexo(1, 2);
NumComplexo b = NumComplexo(0, 8);
NumComplexo c = NumComplexo(42, 0);

// Exemplos da biblioteca funcionando
NumComplexo result = b.soma(a);
std::cout << "(" << a.para_texto() << ") + (" << b.para_texto() << ") = " << result.para_texto() << std::endl;

result = a.soma(c);
std::cout << "(" << a.para_texto() << ") + (" << c.para_texto() << ") = " << result.para_texto() << std::endl;

result = a.subtracao(b);
std::cout << "(" << a.para_texto() << ") - (" << b.para_texto() << ") = " << result.para_texto() << std::endl;

result = a.subtracao(c);
std::cout << "(" << a.para_texto() << ") - (" << c.para_texto() << ") = " << result.para_texto() << std::endl;

result = a.multiplicacao(b);
std::cout << "(" << a.para_texto() << ") * (" << b.para_texto() << ") = " << result.para_texto() << std::endl;

result = b.multiplicacao(c);
std::cout << "(" << b.para_texto() << ") * (" << c.para_texto() << ") = " << result.para_texto() << std::endl;

return 0;
}
31 changes: 31 additions & 0 deletions lista06/ex02/src/numeros_complexos.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "numeros_complexos.hpp"

auto NumComplexo::soma(NumComplexo num) -> NumComplexo {
return NumComplexo( _sigma + num._sigma, _omega + num._omega );
}

auto NumComplexo::subtracao(NumComplexo num) -> NumComplexo {
return NumComplexo( _sigma - num._sigma, _omega - num._omega );
}

auto NumComplexo::multiplicacao(NumComplexo num) -> NumComplexo {
return NumComplexo( _sigma * num._sigma - _omega * num._omega, _omega * num._sigma + _sigma * num._omega );
}

auto NumComplexo::modulo() -> double {
double expression = _sigma * _sigma + _omega * _omega;
return sqrt(expression);
}

auto NumComplexo::para_texto() -> std::string {
auto str_buffer = std::to_string(_sigma);
str_buffer += ((_omega >= 0)? " + " : " - ");
str_buffer += std::to_string(abs(_omega));
str_buffer += "j";
return str_buffer;
}

NumComplexo::NumComplexo(int module, double theta_deg) {
_sigma = module * cos ( theta_deg * PI / 180.0 );
_omega = module * sin ( theta_deg * PI / 180.0 );
}
26 changes: 26 additions & 0 deletions lista06/ex02/src/numeros_complexos.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef NUMEROS_COMPLEXOS_H_
#define NUMEROS_COMPLEXOS_H_

#define PI 3.14159265

#include <iostream>
#include <string>
#include <cmath>

class NumComplexo {
protected:
int _sigma;
int _omega;

public:
auto soma(NumComplexo num) -> NumComplexo;
auto subtracao(NumComplexo num) -> NumComplexo;
auto multiplicacao(NumComplexo num) -> NumComplexo;
auto modulo() -> double;
auto para_texto()-> std::string;

NumComplexo(int sigma, int omega) : _sigma { sigma }, _omega { omega } {};
NumComplexo(int module, double theta_deg);
};

#endif // NUMEROS_COMPLEXOS_H_