Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- struct ComplexPolar;
- struct Complex {
- double a, b;
- ComplexPolar GetComplexPolar();
- void Print() {
- std::cout << a << " + " << b << " * i" << std::endl;
- }
- };
- struct ComplexPolar {
- double r, phi;
- Complex GetComplex() {
- return Complex{r * std::cos(phi), r * std::sin(phi)};
- }
- void Print() {
- std::cout << r << "(cos(" << phi << ") + sin(" << phi << "))" << std::endl;
- }
- };
- ComplexPolar Complex::GetComplexPolar() {
- return ComplexPolar{std::sqrt(a * a + b * b), std::atan(b / a)};
- }
- int main() {
- ComplexPolar a{1, 2};
- a.Print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment