Advertisement
Guest User

zespolone

a guest
May 29th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class cplx{
  6.   private:
  7.           double liczbazes;
  8.           double liczbauro;
  9.  
  10.   public:
  11.          cplx(double re, double im)
  12.          {
  13.          liczbazes = re;
  14.          liczbauro = im;                  
  15.          }
  16.          
  17.   public:
  18.          cplx add(cplx liczba)
  19.          {
  20.          cplx rez(0,0);
  21.          rez.liczbazes = this->liczbazes + liczba.liczbazes;
  22.          rez.liczbauro = this->liczbauro + liczba.liczbauro;
  23.          return rez;
  24.          }
  25.          
  26.          cplx sub(cplx *liczba)
  27.          {
  28.          cplx rez(0,0);
  29.          rez.liczbazes = this->liczbazes - liczba->liczbazes;
  30.          rez.liczbauro = this->liczbauro - liczba->liczbauro;
  31.          return rez;
  32.          }
  33.          
  34.          cplx mul(cplx &liczba)
  35.          {
  36.          cplx rez(0,0);
  37.          rez.liczbazes = this->liczbazes*liczba.liczbazes + this->liczbauro*liczba.liczbauro;
  38.          rez.liczbauro = this->liczbazes*liczba.liczbauro + this->liczbauro*liczba.liczbazes; //2*1+1*1= 3 , 2*1+1*1 = 3
  39.          return rez;
  40.          }
  41.          
  42.          cplx inc(cplx liczba)
  43.          {
  44.          this->liczbazes = this->liczbazes +1;
  45.          return *this;
  46.          }
  47.                  
  48.          void show()
  49.          {
  50.               cout <<this->liczbazes <<"+"<<this->liczbauro<<"i"<<endl;
  51.          }    
  52. };        
  53. int main()
  54. {
  55.  cplx a = cplx(2,1);
  56.  cplx b = cplx(1,1);
  57.  cplx c = cplx(3,2);
  58.  
  59.  cout<<"Wynik dodawania 2 liczb zespolonych:"<<endl;
  60.  cplx wynik = a.add(b);
  61.  wynik.show();
  62.  
  63.  cout<<"Wynik odejmowania 2 liczb zespolonych:"<<endl;
  64.  wynik = a.sub(&b);
  65.  wynik.show();
  66.  
  67.  cout<<"Wynik mnozenia 2 liczb zespolonych:"<<endl;
  68.  wynik = c.mul(b);
  69.  wynik.show();
  70.  
  71.  cout<<"Wynik dodania o 1 do liczby rzeczywistej:"<<endl;
  72.  wynik = a.inc(c);
  73.  wynik.show();
  74.  
  75.  
  76.  system("PAUSE");              
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement