Quick actions

cmd+k|ctrl+k

Navigation

Languages

Lab2_Q3

Snippet info

Language

Cpp

Visibility

public

Author

chriscui14

Created

2020-06-04T21:22:10Z

Updated

2020-06-05T01:35:30Z

#include <iostream>
using namespace std;

struct complex{
    double re;
    double im;
    complex(double a, double b){
        re = a;
        im = b;
    }
    void add(complex b);
    void multiply(complex b);
    void conjugate();
    void print();
};
void complex::print(){
    cout << "real is " << re << " and imaginary is " << im << endl;
}
void complex::multiply(complex b){
    int temp = re*b.re-im*b.im;
    im = im*b.re+re*b.im;
    re = temp;
}

void complex::add(complex b){
    re += b.re;
    im += b.im;
}
void complex::conjugate(){
    im = -im;
}



int main() {
    complex x={3,4}, y={1,-0.25};
    x.print();
    y.print();
    
    x.add(y);
    x.print();
    
    y.multiply(x);
    y.print();
    
    x.conjugate();
    x.print();
    
    y.conjugate();
    y.print();
    return 0;
}
INFO