Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- class complex {
- private:
- double r,i;
- public:
- complex(void);
- complex(double,double);
- double abs(void);
- void show(void);
- complex co(void);
- //friend complex operator+(complex,complex);
- complex operator+(complex); //c=a+b
- complex operator++(void); //prefix ++a
- complex operator++(int); //postfix a++
- };
- complex complex::operator +(complex b) {
- return complex(r+b.r,i+b.i);
- }
- /*complex operator+(complex a,complex b) {
- return complex(a.r+b.r,a.i+b.i);
- }*/
- complex complex::co(void) {
- return complex(r,-i);
- }
- complex::complex(void) {
- r=0;
- i=0;
- }
- complex::complex(double a,double b) {
- r=a;
- i=b;
- }
- double complex::abs(void) {
- return sqrt(r*r+i*i);
- }
- void complex::show(void) {
- printf("Re=%lf\nIm=%lf\n\n",r,i);
- }
- int main() {
- complex a(7,11),b(3,4);
- a=a+b;
- a.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment