-
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.
Implementa codigo fonte do exercicio 2
- Loading branch information
1 parent
3db9c75
commit f30984c
Showing
4 changed files
with
88 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_ |