void TestMathematicalOperationsOfTwoComplexNumbers()
{
	cnum1.real = 1;
	cnum1.imag = 2;
	cnum2.real = 3;
	cnum2.imag = 4;

	complexNumber result;

	result = complexAdd(cnum1, cnum2);
	assert(result.real == 4);
	assert(result.imag == 6);

	result = complexSub(cnum1, cnum2);
	assert(result.real = -2);
	assert(result.imag = -2);

	result = complexMul(cnum1, cnum2);
	assert(result.real = -5);
	assert(result.imag = 10);

	result = complexDiv(cnum1, cnum2);
	assert(result.real = .44);
	assert(result.imag = .08);
}
Пример #2
0
void fixIntoUnitCircle (__CLPK_doublecomplex ioroots[], int nroots) {
	for (int j = 0; j < nroots; j++)
		if (complexMod (ioroots[j]) > 1.0) {
            __CLPK_doublecomplex a = {1.0, 0.0}, b, c;
            b.r = ioroots[j].r;
            b.i = -ioroots[j].i;        // Conjugate of the root
			complexDiv (a, b, &c);      // c = a/b
            ioroots[j].r = c.r;         // Return c
            ioroots[j].i = c.i;
        }
}
/**
*					---showMenu---
*
* Gives the user the choice of the mathematical operation 
* to be executed
*
* 1: ADDITION | 2: SUBTRACTION | 3: MULTIPLICATION | 4: DIVISION
*
* recursive exception-handling for wrong user input
*/
void showMenu()
{
	system("CLS");
	printf_s("Welche Rechnenoperation m%cchten Sie durchf%chren?", oe, ue); 
	printf_s("\n1: Addition\n2: Subtraktion\n3: Multiplikation\n4: Division\n");

	int userInput;
	complexNumber divResult;

	fflush(stdin);
	scanf_s("%d", &userInput); fflush(stdin);

	switch (userInput)
	{
	case ADDITION:
		printf_s("\nDas Ergebnis der Operation Zahl1 + Zahl2 lautet: ");
		showResult(complexAdd(cnum1, cnum2));
		break;

	case SUBTRACTION:
		printf_s("\nDas Ergebnis der Operation Zahl1 - Zahl2 lautet: ");	
		showResult(complexSub(cnum1, cnum2));
		break;

	case MULTIPLICATION:
		printf_s("\nDas Ergebnis der Operation Zahl1 * Zahl2 lautet: ");
		showResult(complexMul(cnum1, cnum2));
		break;

	case DIVISION:
		divResult = complexDiv(cnum1, cnum2);
		if(divResult.real != -1 && divResult.imag != -1)
		{
			printf_s("\nDas Ergebnis der Operation Zahl1 / Zahl2 lautet: ");
			showResult(divResult);
			break;
		} else 
			break;

	default: 
		printf_s("\n%d, ist keine g%cltige Eingabe...\nBitte wiederholen:\n", userInput, ue);
		Sleep(2000);
		showMenu();
	}
}