Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //h
- #ifndef LAB5P1_H
- #define LAB5P1_H
- #include <iostream>
- #include <math.h>
- using namespace std;
- class Complex
- {
- int re,im;
- public:
- Complex () {};
- Complex (int,int);
- Complex operator + (Complex);
- void afisare();
- float operator~();
- int operator==(Complex c2);
- Complex operator-(Complex c2);
- Complex operator*(Complex c2);
- void Complex::citire()
- {
- cout<<"Re=";
- cin>>this->re;
- cout<<"\nIm=";
- cin>>this->im;
- }
- };
- #endif
- //c
- #include "lab5p1.h"
- Complex::Complex (int re, int im)
- {
- this->re = re;
- this->im = im;
- }
- Complex Complex::operator+(Complex c2)
- {
- Complex temp;
- temp.re = this->re + c2.re;
- temp.im = this->im + c2.im;
- return temp;
- }
- void Complex::afisare()
- {
- cout << "(" << re << "+i" << im << ")" << endl;
- }
- int Complex::operator ==(Complex c2)
- {
- return ((this->re ==c2.re ) && (this->im ==c2.im ));
- }
- float Complex::operator ~()
- { float rim,inm,x;
- rim=this->re*this->re;
- inm=this->im*this->im;
- x=sqrt(rim+inm);
- return x;
- //return ( sqrt((this->re*this->re)+(this->im*this->im)));
- }
- Complex Complex::operator-(Complex c2)
- {
- Complex temp;
- temp.re = this->re - c2.re;
- temp.im = this->im - c2.im;
- return temp;
- }
- Complex Complex::operator *(Complex c2)
- {
- int x,y;
- x=this->re*c2.re-this->im*c2.im;
- y=this->re*c2.im+this->im*c2.re;
- Complex b(x,y);
- return b;
- }
- //main
- #include "lab5p1.h"
- int main()
- {
- int test;
- float v;
- Complex c1,c2,imp;
- cout<<"Introduceti primul numar complex:"<<endl;
- c1.citire();
- cout<<"\nIntroduceti al doilea numar complex:"<<endl;
- c2.citire();
- cout<<"\nModulul numarului complex c1 este:"<<endl;
- v=~c1;
- cout<<v;
- cout<<"\nModulul numarului complex c2 este:"<<endl;
- v=~c2;
- cout<<v;
- if(c1==c2)
- cout<<"\nNumerele complexe c1 si c2 sunt egale!"<<endl;
- else
- cout<<"\nNumerele complexe c1 si c2 nu sunt egale!"<<endl;
- imp=c1*c2;
- cout<<"Rezultatul inmultirii c1*c2 este: "<<endl;
- imp.afisare();
- cout<<"\nPress RETURN to exit!";
- cin>>test;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement