Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class cplx{
- private:
- double liczbazes;
- double liczbauro;
- public:
- cplx(double re, double im)
- {
- liczbazes = re;
- liczbauro = im;
- }
- public:
- cplx add(cplx liczba)
- {
- cplx rez(0,0);
- rez.liczbazes = this->liczbazes + liczba.liczbazes;
- rez.liczbauro = this->liczbauro + liczba.liczbauro;
- return rez;
- }
- cplx sub(cplx *liczba)
- {
- cplx rez(0,0);
- rez.liczbazes = this->liczbazes - liczba->liczbazes;
- rez.liczbauro = this->liczbauro - liczba->liczbauro;
- return rez;
- }
- cplx mul(cplx &liczba)
- {
- cplx rez(0,0);
- rez.liczbazes = this->liczbazes*liczba.liczbazes + this->liczbauro*liczba.liczbauro;
- rez.liczbauro = this->liczbazes*liczba.liczbauro + this->liczbauro*liczba.liczbazes; //2*1+1*1= 3 , 2*1+1*1 = 3
- return rez;
- }
- cplx inc(cplx liczba)
- {
- this->liczbazes = this->liczbazes +1;
- return *this;
- }
- void show()
- {
- cout <<this->liczbazes <<"+"<<this->liczbauro<<"i"<<endl;
- }
- };
- int main()
- {
- cplx a = cplx(2,1);
- cplx b = cplx(1,1);
- cplx c = cplx(3,2);
- cout<<"Wynik dodawania 2 liczb zespolonych:"<<endl;
- cplx wynik = a.add(b);
- wynik.show();
- cout<<"Wynik odejmowania 2 liczb zespolonych:"<<endl;
- wynik = a.sub(&b);
- wynik.show();
- cout<<"Wynik mnozenia 2 liczb zespolonych:"<<endl;
- wynik = c.mul(b);
- wynik.show();
- cout<<"Wynik dodania o 1 do liczby rzeczywistej:"<<endl;
- wynik = a.inc(c);
- wynik.show();
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement