예제 #1
0
ComplexCalculator ComplexCalculator::Add(ComplexCalculator first,
                                         ComplexCalculator second) {
    ComplexCalculator temp(0, 0);
    temp.real = first.GetReal()+second.GetReal();
    temp.imaginary = first.GetImaginary()+second.GetImaginary();
    return temp;
}
예제 #2
0
int main(int argc, char** argv) {
    Expression expr = parseArguments(argc, argv);
    ComplexCalculator a;
    ComplexCalculator b;
    a = expr.arg1;
    b = expr.arg2;
    ComplexCalculator c;
    char str[35]="";

    switch (expr.operation) {
     case '+' :
        c = ComplexCalculator::Add(a, b);
        c.Output(str);
        printf("A+B = %s\n", str);
        break;
     case '-' :
        c = ComplexCalculator::Sub(a, b);
        c.Output(str);
        printf("A-B = %s\n", str);
        break;
     case '*' :
        c = ComplexCalculator::Multi(a, b);
        c.Output(str);
        printf("A*B = %s\n", str);
        break;
     case '/' :
        c = ComplexCalculator::Div(a, b);
        c.Output(str);
        printf("A/B = %s\n", str);
        break;
    }
    return 0;
}
ComplexCalculator ComplexCalculator::Div(ComplexCalculator first, ComplexCalculator second)
{
	ComplexCalculator temp(0,0);
	temp.real=(first.GetReal()*second.GetReal()+first.GetImaginary()*second.GetImaginary())/(second.GetReal()*second.GetReal()+second.GetImaginary()*second.GetImaginary());
	temp.imaginary=(first.GetImaginary()*second.GetReal()-first.GetReal()*second.GetImaginary())/(second.GetReal()*second.GetReal()+second.GetImaginary()*second.GetImaginary());
	return temp;
}