Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MAIN.CPP
- //kompulowac z plikiem vect.cpp
- #include <iostream>
- #include "complex0.h"
- using namespace std;
- int main()
- {
- Complex0 a(3,4);
- Complex0 c(10,12);
- cin >> c;
- cout << "c to " << c << '\n';
- cout << "a to " << a << '\n';
- cout << "a + c wynosi " << a + c << endl;
- cout << "a - c wynosi " << a - c << endl;
- cout << "a * c wynosi " << a * c << endl;
- cout << "c * 2 wynosi " << c * 2 << endl;
- return 0;
- }
- //////////
- COMPLEX0.H
- /////////
- #ifndef COMPLEX0_H_
- #define COMPLEX0_H_
- #include <iostream>
- class Complex0
- {
- private:
- double real;
- double imag;
- public:
- Complex0();
- Complex0(double rl, double im);
- ~Complex0();
- void set_real() {std::cin >> real;}
- void set_imag() {std::cin >> imag;}
- friend std::ostream & operator<<(std::ostream & os, const Complex0 & c);
- friend std::iostream & operator>>(std::iostream & os, Complex0 & c);
- Complex0 operator+(Complex0 &b);
- Complex0 operator-(Complex0 &b);
- Complex0 operator*(Complex0 &b);
- Complex0 operator*(double b);
- };
- #endif
- ///////////
- COMPLEX0.CPP
- ///////////
- //#include <cmath>
- #include <iostream>
- #include "complex0.h"
- using namespace std;
- Complex0::Complex0()
- {
- cout << "Nie podano danych liczby. Zerowanie liczby";
- real = 0;
- imag = 0;
- }
- Complex0::Complex0(double rl, double im=0)
- {
- real = rl;
- imag = im;
- }
- Complex0::~Complex0() {}
- std::ostream & operator<<(std::ostream & os, const Complex0 & c)
- {
- os << "(" << c.real << ", " << c.imag << "i)";
- return os;
- }
- std::iostream & operator<<(std::iostream & os, Complex0 & c)
- {
- os << "Podaj czesc rzeczywista: ";
- c.set_real();
- os << endl << "Podaj czesc urojona: ";
- c.set_imag();
- os << endl;
- return os;
- }
- Complex0 Complex0::operator+(Complex0 &b)
- {
- return Complex0(real+b.real, imag + b.imag);
- }
- Complex0 Complex0::operator-(Complex0 &b)
- {
- return Complex0(real-b.real, imag-b.imag);
- }
- Complex0 Complex0::operator*(Complex0 &b)
- {
- return Complex0(real*b.real - imag*b.imag, real*b.imag+imag*b.real);
- }
- Complex0 Complex0::operator*(double b)
- {
- return Complex0(real*b, imag*b);
- }
Advertisement
Add Comment
Please, Sign In to add comment