Programmieren leicht erlernt |
#include <iostream.h> #include <limits.h> #include <float.h> #include <string.h> #include "scppkMath.h" char szScppkMathError[128] = ""; int nScppkMathError = 0; void ScppkMinus( int nZahl1, int nZahl2 ) { double dErgebnis; dErgebnis = (double) nZahl1 - (double) nZahl2; if ( nScppkIntegertest( dErgebnis ) ) { cout << nZahl1 - nZahl2; } } int nScppkIntegertest( double dZahl ) { int nReturn = 0; if ( _finite( dZahl ) ) { if ( dZahl > INT_MAX ) { strcpy( szScppkMathError, SCPPK_STR_ERROR_ZUGROSS ); nScppkMathError = 1; } else if ( dZahl < INT_MIN ) { strcpy( szScppkMathError, SCPPK_STR_ERROR_ZUKLEIN ); nScppkMathError = 2; } else { nReturn = 1; nScppkMathError = 0; } } else { strcpy( szScppkMathError, SCPPK_STR_ERROR_UNDEFINIERT ); nScppkMathError = 3; } return nReturn; } void ScppkPlus( int nZahl1, int nZahl2 ) { double dErgebnis; dErgebnis = (double) nZahl1 + (double) nZahl2; if ( nScppkIntegertest( dErgebnis ) ) { cout << nZahl1 + nZahl2; } } |
#ifndef __scppkMath_h__ #define __scppkMath_h__ /// /// Texte /// #define SCPPK_STR_ERROR_ZUGROSS \ "Error 1 (Das Ergebnis ist zu gross)\n" #define SCPPK_STR_ERROR_ZUKLEIN \ "Error 2 (Das Ergebnis ist zu klein)\n" #define SCPPK_STR_ERROR_UNDEFINIERT \ "Error 3 (Das Ergebnis ist \ nicht definiert)\n" /// /// Variablen /// extern char szScppkMathError[128]; extern int nScppkMathError; /// /// Funktionen /// void ScppkMinus( int nZahl1, int nZahl2 ); void ScppkPlus( int nZahl1, int nZahl2 ); /// /// Intern genutzte Funktionen /// int nScppkIntegertest( double dZahl ); #endif |
#include <iostream.h>
#include <stdlib.h>
#include "main.h"
#include "scppkMath.h"
int main( int argc, char * argv[], char * envp[] )
{
int nZahl1;
int nZahl2;
if ( argc != 3 )
{
cout << SCPPK_STR_HILFE;
}
else
{
nZahl1 = atoi( argv[ 1 ] );
nZahl2 = atoi( argv[ 2 ] );
cout << "\n" << nZahl1 << " + " << nZahl2 << " = ";
ScppkPlus( nZahl1, nZahl2 );
if ( nScppkMathError )
{
cout << szScppkMathError;
}
cout << "\n" << nZahl1 << " - " << nZahl2 << " = ";
ScppkMinus( nZahl1, nZahl2 );
if ( nScppkMathError )
{
cout << szScppkMathError;
}
}
return 0;
}
|
#include <iostream.h>
#include <limits.h>
#include <float.h>
#include <string.h>
#include "scppkMath.h"
char szScppkMathError[128] = "";
int nScppkMathError = 0;
int nScppkMinus( int nZahl1, int nZahl2 )
{
double dErgebnis;
int nErgebnis;
dErgebnis = (double) nZahl1 - (double) nZahl2;
ScppkIntegertest( dErgebnis );
nErgebnis = nZahl1 - nZahl2;
return nErgebnis;
}
void ScppkIntegertest( double dZahl )
{
if ( _finite( dZahl ) )
{
if ( dZahl > INT_MAX )
{
strcpy( szScppkMathError, SCPPK_STR_ERROR_ZUGROSS );
nScppkMathError = 1;
}
else if ( dZahl < INT_MIN )
{
strcpy( szScppkMathError, SCPPK_STR_ERROR_ZUKLEIN );
nScppkMathError = 2;
}
else
{
// ... //
nScppkMathError = 0;
}
}
else
{
strcpy( szScppkMathError, SCPPK_STR_ERROR_UNDEFINIERT );
nScppkMathError = 3;
}
// ... //
}
int nScppkPlus( int nZahl1, int nZahl2 )
{
double dErgebnis;
int nErgebnis;
dErgebnis = (double) nZahl1 + (double) nZahl2;
ScppkIntegertest( dErgebnis );
nErgebnis = nZahl1 + nZahl2;
return nErgebnis;
}
|
. . . /// /// Funktionen /// int nScppkMinus( int nZahl1, int nZahl2 ); int nScppkPlus( int nZahl1, int nZahl2 ); /// /// Intern genutzte Funktionen /// void ScppkIntegertest( double dZahl ); #endif |
#include <iostream.h>
#include <stdlib.h>
#include "main.h"
#include "scppkMath.h"
int main( int argc, char * argv[], char * envp[] )
{
int nZahl1;
int nZahl2;
int nErgebnis;
if ( argc != 3 )
{
cout << SCPPK_STR_HILFE;
}
else
{
nZahl1 = atoi( argv[ 1 ] );
nZahl2 = atoi( argv[ 2 ] );
cout << "\n" << nZahl1 << " + " << nZahl2 << " = ";
nErgebnis = nScppkPlus( nZahl1, nZahl2 );
if ( nScppkMathError )
{
cout << szScppkMathError;
}
else
{
cout << nErgebnis;
}
cout << "\n" << nZahl1 << " - " << nZahl2 << " = ";
nErgebnis = nScppkMinus( nZahl1, nZahl2 );
if ( nScppkMathError )
{
cout << szScppkMathError;
}
else
{
cout << nErgebnis;
}
}
return 0;
}
|