-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from studas/lista06/ex03
Lista06/ex03
- Loading branch information
Showing
7 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + a; | ||
std::cout << "(" << a << ") + (" << b << ") = " << result << std::endl; | ||
|
||
result = a + c; | ||
std::cout << "(" << a.para_texto() << ") + (" << c.para_texto() << ") = " << result.para_texto() << std::endl; | ||
|
||
result = a - b; | ||
std::cout << "(" << a.para_texto() << ") - (" << b.para_texto() << ") = " << result.para_texto() << std::endl; | ||
|
||
result = a - c; | ||
std::cout << "(" << a.para_texto() << ") - (" << c.para_texto() << ") = " << result.para_texto() << std::endl; | ||
|
||
result = a * b; | ||
std::cout << "(" << a.para_texto() << ") * (" << b.para_texto() << ") = " << result.para_texto() << std::endl; | ||
|
||
result = b * c; | ||
std::cout << "(" << b.para_texto() << ") * (" << c.para_texto() << ") = " << result.para_texto() << std::endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "numeros_complexos.hpp" | ||
|
||
auto NumComplexo::soma(NumComplexo const num) const -> NumComplexo { | ||
return NumComplexo( _sigma + num._sigma, _omega + num._omega ); | ||
} | ||
|
||
auto NumComplexo::operator+(NumComplexo const other) const -> NumComplexo { | ||
return this->soma(other); | ||
} | ||
|
||
auto NumComplexo::subtracao(NumComplexo const num) const -> NumComplexo { | ||
return NumComplexo( _sigma - num._sigma, _omega - num._omega ); | ||
} | ||
|
||
auto NumComplexo::operator-(NumComplexo const other) const -> NumComplexo { | ||
return this->subtracao(other); | ||
} | ||
|
||
auto NumComplexo::multiplicacao(NumComplexo const num) const -> NumComplexo { | ||
return NumComplexo( _sigma * num._sigma - _omega * num._omega, _omega * num._sigma + _sigma * num._omega ); | ||
} | ||
|
||
auto NumComplexo::operator*(NumComplexo const other) const -> NumComplexo { | ||
return this->multiplicacao(other); | ||
} | ||
|
||
auto NumComplexo::modulo() const -> double { | ||
double expression = _sigma * _sigma + _omega * _omega; | ||
return sqrt(expression); | ||
} | ||
|
||
auto NumComplexo::operator~() const -> double { | ||
return this->modulo(); | ||
} | ||
|
||
auto NumComplexo::para_texto() const -> 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 ); | ||
} | ||
|
||
std::ostream &operator<<(std::ostream& os, const NumComplexo& num) { | ||
return os << num.para_texto(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#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 const num) const -> NumComplexo; | ||
auto operator+(NumComplexo const other) const -> NumComplexo; | ||
auto subtracao(NumComplexo const num) const -> NumComplexo; | ||
auto operator-(NumComplexo const other) const -> NumComplexo; | ||
auto multiplicacao(NumComplexo const num) const -> NumComplexo; | ||
auto operator*(NumComplexo const other) const -> NumComplexo; | ||
|
||
auto modulo() const -> double; | ||
auto operator~() const -> double; | ||
auto para_texto() const -> std::string; | ||
|
||
NumComplexo(int sigma, int omega) : _sigma { sigma }, _omega { omega } {}; | ||
NumComplexo(int module, double theta_deg); | ||
}; | ||
|
||
std::ostream &operator<<(std::ostream& os, const NumComplexo& num); | ||
#endif // NUMEROS_COMPLEXOS_H_ |