/*
* Andrzej Zieliński
* ne ind. 116366
* klasa liczby zespolone
*/
#include <iostream>
#include <memory>
#include <cmath>
using namespace std;
template<class type>
class complex_base
{
protected:
type a, b;
public:
complex_base(type a1 = 0, type b1 = 0) :
a(a1), b(b1)
{
}
type real()
{
return a;
}
void real(type a)
{
this->a = a;
}
type imag()
{
return b;
}
void imag(type b)
{
this->b = b;
}
void print() const
{
cout << a << ", j" << b;
}
friend ostream& operator<<(ostream& ostre, const complex_base<type>& z)
{
ostre << z.a << ", j" << z.b;
return ostre;
}
};
template<class type>
class extended_complex: public complex_base<type>
{
public:
extended_complex(type a1 = 0, type b1 = 0) :
complex_base<type>(a1, b1)
{
}
double mod()
{
type a2 = complex_base<type>::a * complex_base<type>::a;
type b2 = complex_base<type>::b * complex_base<type>::b;
return sqrt(a2 + b2);
}
double arg()
{
return atan2(complex_base<type>::b, complex_base<type>::a);
}
void print()
{
cout << mod() << ", " << arg();
}
};
int main()
{
complex_base<int> X(7, -10);
const complex_base<int>& Y = X;
cout << "Zawartosc Y: " << Y << endl;
Y.print();
shared_ptr<complex_base<int>> X1(new complex_base<int>(143, -24));
shared_ptr<complex_base<int>> Y1;
Y1 = X1;
Y1->print();
cout << "\nZawartosc Y1: " << *Y1 << endl;
extended_complex<int> Z(5, 3);
Z.print();
cout << "\nMod: " << Z.mod();
return 0;
}
Comments