Programmieren leicht erlernt |
#include <iostream.h> #include <stdlib.h> void ScppkPlus( int nZahl1, int nZahl2 ) { cout << nZahl1 + nZahl2; } int main( int argc, char * argv[], char * envp[] ) { int nZahl1; int nZahl2; if ( argc != 3 ) { cout << "Bitte geben sie 2 Zahlen als Parameter an.\n"; cout << "z.B. Rechne 12 8\n"; } else { nZahl1 = atoi( argv[ 1 ] ); nZahl2 = atoi( argv[ 2 ] ); cout << "\n" << nZahl1 << " + " << nZahl2 << " = "; ScppkPlus( nZahl1, nZahl2 ); } return 0; } |
#include <iostream.h> #include <stdlib.h> #include <limits.h> #include <float.h> int nScppkIntegertest( double dZahl ) { int nReturn = 0; if ( _finite( dZahl ) ) { if ( dZahl > INT_MAX ) { cout << "Error (Das Ergebnis ist zu gross)\n"; } else if ( dZahl < INT_MIN ) { cout << "Error (Das Ergebnis ist zu klein)\n"; } else { nReturn = 1; } } else { cout << "Error (Das Ergebnis ist nicht definiert)\n"; } return nReturn; } void ScppkPlus( int nZahl1, int nZahl2 ) { double dErgebnis; double d1 = 0; dErgebnis = (double) nZahl1 + (double) nZahl2; if ( nScppkIntegertest( dErgebnis ) ) { cout << nZahl1 + nZahl2; } } int main( int argc, char * argv[], char * envp[] ) { int nZahl1; int nZahl2; if ( argc != 3 ) { cout << "Bitte geben sie 2 Zahlen als Parameter an.\n"; cout << "z.B. Rechne 12 8\n"; } else { nZahl1 = atoi( argv[ 1 ] ); nZahl2 = atoi( argv[ 2 ] ); cout << "\n" << nZahl1 << " + " << nZahl2 << " = "; ScppkPlus( nZahl1, nZahl2 ); } return 0; } |
#include <iostream.h>
#include <stdlib.h>
#include <limits.h>
#include <float.h>
void ScppkMinus( int nZahl1, int nZahl2 )
{
double dErgebnis;
double d1 = 0;
dErgebnis = (double) nZahl1 - (double) nZahl2;
if ( nScppkIntegertest( dErgebnis ) )
{
cout << nZahl1 - nZahl2;
}
}
int nScppkIntegertest( double dZahl )
{
.
.
.
else
{
nZahl1 = atoi( argv[ 1 ] );
nZahl2 = atoi( argv[ 2 ] );
cout << "\n" << nZahl1 << " + " << nZahl2 << " = ";
ScppkPlus( nZahl1, nZahl2 );
cout << "\n" << nZahl1 << " - " << nZahl2 << " = ";
ScppkMinus( nZahl1, nZahl2 );
}
return 0;
}
|
#include <iostream.h> #include <stdlib.h> #include <limits.h> #include <float.h> void ScppkMinus( int nZahl1, int nZahl2 ); int nScppkIntegertest( double dZahl ); void ScppkPlus( int nZahl1, int nZahl2 ); int main( int argc, char * argv[], char * envp[] ); void ScppkMinus( int nZahl1, int nZahl2 ) { . . . |