Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <iostream>
- using namespace std;
- class Complex {
- private:
- float re;
- float im;
- public:
- Complex(float re = 0, float im = 0);
- void afisare();
- Complex& operator ++();
- Complex operator +(Complex z);
- Complex& operator ++(int);
- Complex operator ~();
- Complex operator +=(Complex z);
- Complex operator /(Complex z);
- friend Complex operator -(Complex z1,
- Complex z2);
- friend Complex operator -(Complex z);
- };
- Complex& Complex::operator ++() {
- //re += 1;
- ++re;
- printf("preincrementare\n");
- return *this;
- }
- Complex& Complex::operator ++(int n) {
- re++;
- printf("postincrementare\n");
- return *this;
- }
- Complex::Complex(float re, float im) {
- this->re = re;
- this->im = im;
- }
- void Complex::afisare() {
- printf("%-g%+g*i\n", re, im);
- }
- Complex Complex::operator +(Complex z) {
- Complex rez;
- rez.re = this->re + z.re;
- rez.im = this->im + z.im;
- return rez;
- }
- Complex Complex::operator /(Complex z) {
- Complex rez;
- rez.re = this->re + z.re;
- rez.im = this->im + z.im;
- return rez;
- }
- Complex Complex::operator +=(Complex z) {
- // Complex rez;
- re += z.re;
- this->im += z.im;
- return *this;
- }
- Complex Complex::operator ~() {
- return Complex(re, -im);
- }
- Complex operator -(Complex z1, Complex z2) {
- cout <<"hihi";
- return Complex(z1.re - z2.re, z1.im - z2.im);
- }
- Complex operator -(Complex z) {
- cout << "haha";
- return Complex(-z.re, -z.im);
- }
- void main() {
- Complex z1(4, 5), z2(3, 1), z;
- z = z1 + z2; z.afisare();
- z = z1 - z2; z.afisare();
- z = ~z1; z.afisare();
- z = -z1; z.afisare();
- z = z1;
- cout << endl << endl;
- z.afisare();
- z1 += z1;
- z1.afisare();
- z2.afisare();
- z = z1 / z2;
- z.afisare();
- ++z;
- z++;
- z.afisare();
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement