Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.
- #include <iostream>
- using namespace std;
- class liczby_zespolone{
- private:
- int re, im;
- public:
- liczby_zespolone(int a=0,int b=0){
- re=a;
- im=b;
- }
- void operator +(liczby_zespolone &B){
- re=re+B.re;
- im = im+B.im;
- }
- liczby_zespolone operator -(liczby_zespolone &B){
- liczby_zespolone wynik;
- wynik.re=re-B.re;
- wynik.im=im-B.im;
- return wynik;
- }
- liczby_zespolone operator *(liczby_zespolone &B){
- liczby_zespolone m;
- m.re=(re*B.re) - (im*B.im);
- m.im=(re*B.im) + (im*B.re);
- return m;
- }
- liczby_zespolone operator /(liczby_zespolone &B){
- liczby_zespolone n;
- n.re=((re*B.re) - (im*B.im))/((B.re*B.re)+(B.im*B.im));
- n.im=((re*B.im) + (im*B.re))/((B.re*B.re)+(B.im*B.im));
- return n;
- }
- void druk(){
- cout << "Liczba zespolona wynosi:" << "z=" << re << "+i(" << im << ")" << endl;
- }
- };
- int main()
- {
- liczby_zespolone L1(2,6);
- liczby_zespolone L2(7,-3);
- liczby_zespolone L3;
- liczby_zespolone L4;
- liczby_zespolone L5;
- L1.druk();
- L2.druk();
- L3.druk();
- cout << "Opcja 1: wynik dodawania L1 i L2" << endl;
- L1+L2;
- L1.druk();
- cout << "Opcja 2: wynik odejmowania L1 i L2" << endl;
- L3 = L1 - L2;
- L3.druk();
- cout << "Opcja 2: mnozenia L1 i L3" << endl;
- L4 = L1*L3;
- L4.druk();
- cout << "Opcja 2: dzielenie L4 i L3" << endl;
- L5 = L4/L3;
- L5.druk();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement