#include
using namespace std;
int addiren( int augend, int addend )
{
return augend + addend;
}
int subtrahieren( int minuend, int subtrahend )
{
return minuend - subtrahend;
}
int multiplizieren( int multiplikand, int multiplikator )
{
return multiplikand * multiplikator;
}
int dividieren(int dividend, int divisor)
{
if(divisor == 0)
{
return 0;
}
return dividend / divisor;
}
/* Überladene Funktionen */
double addiren( double augend, double addend )
{
return augend + addend;
}
double subtrahieren( double minuend, double subtrahend )
{
return minuend - subtrahend;
}
double multiplizieren( double multiplikand, double multiplikator )
{
return multiplikand * multiplikator;
}
double dividieren(double dividend, double divisor)
{
if(divisor == 0)
{
return 0;
}
return dividend / divisor;
}
int main (void)
{
char id, jn='j', ra;
double erg=0, z1, z2;
do
{
cout << "Minirechner: (i)nteger oder (d)ouble ? ";
cin >> id;
if(id != 'i' && id != 'd')
continue;
cout << "Zahl 1 = ? ";
cin >> z1;
cout << "Rechenart (+ - * /) ? ";
cin >> ra;
cout << "Zahl 2 = ? ";
cin >> z2;
if(id == 'i')
{
z1 = (int)z1;
z2 = (int)z2;
switch(ra)
{
case '+':
erg = addiren( (int)z1, (int)z2 );
break;
case '-':
erg = subtrahieren( (int)z1, (int)z2 );
break;
case '*':
erg = multiplizieren( (int)z1, (int)z2 );
break;
case '/':
erg = dividieren( (int)z1, (int)z2 );
break;
default:
break;
}
}
else
/* if(id == 'd') */
{
switch(ra)
{
case '+':
erg = addiren( z1, z2 );
break;
case '-':
erg = subtrahieren( z1, z2 );
break;
case '*':
erg = multiplizieren( z1, z2 );
break;
case '/':
erg = dividieren( z1, z2 );
break;
default:
break;
}
}
cout << z1 << ra << z2 << "=" << erg << endl;
cout << "Noch einmal (j/n)? ";
cin >> jn;
}
while (jn == 'j');
return 0;
}