Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // zespolone.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- class LiczbyZespolone
- {
- private:
- int _re, _im;
- public:
- LiczbyZespolone(int re, int im)
- {
- this->_re = re;
- this->_im = im;
- }
- LiczbyZespolone(const LiczbyZespolone& lzesp)
- {
- this->_re = lzesp._re;
- this->_im = lzesp._im;
- }
- int getRe()
- {
- return this->_re;
- }
- int getIm()
- {
- return this->_im;
- }
- void setRe(int re)
- {
- this->_re = re;
- }
- void setIm(int im)
- {
- this->_im = im;
- }
- LiczbyZespolone& operator=(const LiczbyZespolone& lzesp)
- {
- this->_re = lzesp._re;
- this->_im = lzesp._im;
- return *this;
- }
- LiczbyZespolone& operator+(const LiczbyZespolone& lzesp)
- {
- this->_re += lzesp._re;
- this->_im += lzesp._im;
- return *this;
- }
- LiczbyZespolone& operator-(const LiczbyZespolone& lzesp)
- {
- this->_re -= lzesp._re;
- this->_im -= lzesp._im;
- return *this;
- }
- /*
- ostream& operator<<(ostream& strm)
- {
- return strm << "(" << this->_re << " + " << this->_im << "i)";
- }
- */
- };
- ostream& operator<<(ostream& strm, LiczbyZespolone& lzesp)
- {
- return strm << "(" << lzesp.getRe() << " + " << lzesp.getIm() << "i)";
- }
- int main()
- {
- LiczbyZespolone lzesp1(3, 5);
- LiczbyZespolone lzesp2(2, 8);
- LiczbyZespolone lzesp3(21, 37);
- LiczbyZespolone lzesp4(9, 11);
- cout << endl << lzesp1 << endl << lzesp2 << endl << lzesp3 << endl << lzesp4 << endl << endl;
- cout << lzesp1 + lzesp2 << endl;
- cout << lzesp3 - lzesp4 << endl;
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement