Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- class Complex {
- private:
- int Rl;
- int Im;
- public:
- Complex(int x, int y) {
- Rl = x;
- Im = y;
- }
- void wypisz() {
- cout << Rl << "+j*" << Im << endl;
- }
- int CzRzeczywista() {
- return Rl;
- }
- int CzImaginowana() {
- return Im;
- }
- friend Complex& operator +(Complex, Complex);
- friend ostream& operator <<(ostream&, Complex);
- };
- Complex& operator +(Complex x, Complex y) {
- int tmp1 = x.CzRzeczywista() + y.CzRzeczywista();
- int tmp2 = x.CzImaginowana() + y.CzImaginowana();
- Complex *obiekt = new Complex(tmp1, tmp2);
- return (*obiekt);
- }
- ostream& operator <<(ostream &str, Complex x) {
- str << x.CzRzeczywista() << "+j*" << x.CzImaginowana();
- return str;
- }
- int main() {
- Complex c1(20, 30), c2(40, 10);
- cout << "c1="; c1.wypisz();
- cout << "c2="; c2.wypisz();
- cout << "c1+c2=" << c1 + c2 << endl;
- Complex *c3 = new Complex(1, 7);
- cout << "c3 wskazuje na obiekt="; c3->wypisz();
- cout << "c3 wskazuje na obiekt=" << *c3 << endl;
- Complex c4 = c1 + c2;
- cout << "c4=" << c4;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement