Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Complex {
- public :
- double re, im;
- Complex(double r = 0, double i = 0) {
- re = r, im = i;
- }
- void citire() {
- cout << "Re = "; cin >> re;
- cout << "Im = "; cin >> im;
- }
- void afisare() {
- cout << "Partea reala : " << re << " Partea imaginara = " << im << "\n";
- }
- friend Complex operator+(Complex, Complex); // ????
- };
- Complex operator+(Complex a, Complex b) {
- Complex z;
- z.re = a.re + b.re;
- z.im = a.im + b.im;
- return z;
- }
- Complex operator-(Complex a, Complex b) {
- Complex z;
- z.re = a.re - b.re;
- z.im = a.im - b.im;
- return z;
- }
- Complex operator*(Complex a, Complex b) {
- Complex z;
- z.re = (a.re * b.re) - (a.im * b.im);
- z.im = (a.re * b.im + b.re * a.im);
- return z;
- }
- int main() {
- Complex z1, z2;
- z1.citire();
- z2.citire();
- cout << "z1 : ";
- z1.afisare();
- cout << "z2 : ";
- z2.afisare();
- cout << "z1 + z2 : ";
- Complex z3;
- z3 = z1 + z2;
- z3.afisare();
- Complex z4;
- z4 = z1 - z2;
- cout << "z1 - z2 : ";
- z4.afisare();
- Complex z5;
- z5 = z1 * z2;
- cout << "z1 * z2 : ";
- z5.afisare();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement