#include <math.h>
#include <stdio.h>

struct str_complex {
private:
    double re, im, mod, arg;
public:
    str_complex(double a_re, double a_im) {
        re = a_re; im = a_im;
        mod = sqrt(re*re + im*im);
        arg = atan2(im, re);
    }
    double get_re() { return re; }
    double get_im() { return im; }
    double magnitude() { return mod; }
    double argument() { return arg; }
};

/* same layout, but everything public */
struct open_complex {
    double re, im, mod, arg;
};

int main()
{
    str_complex a(3, 4);
    double *p;
    open_complex *q;

    p = (double *) &a;
    p[0] = 6;
    p[1] = 8;
    printf("%g %+gi = %g\n", a.get_re(), a.get_im(), a.magnitude());

    q = (open_complex *) &a;
    q->mod = 10;
    printf("%g %+gi = %g\n", a.get_re(), a.get_im(), a.magnitude());

    return 0;
}
