Programmieren leicht erlernt |
#include <iostream.h> #include <limits.h> #include <float.h> #include "main.h" #include "scppkMath.h" 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 ) { cout << SCPPK_STR_ERROR_ZUGROSS; } else if ( dZahl < INT_MIN ) { cout << SCPPK_STR_ERROR_ZUKLEIN; } else { nReturn = 1; } } else { cout << SCPPK_STR_ERROR_UNDEFINIERT; } 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__ void ScppkMinus( int nZahl1, int nZahl2 ); int nScppkIntegertest( double dZahl ); void ScppkPlus( int nZahl1, int nZahl2 ); #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 ) { SCPPK_OUT_HILFE } 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; } |
#ifndef __main_h__ #define __main_h__ #define SCPPK_STR_ERROR_ZUGROSS "Error (Das Ergebnis ist zu gross)\n" #define SCPPK_STR_ERROR_ZUKLEIN "Error (Das Ergebnis ist zu klein)\n" #define SCPPK_STR_ERROR_UNDEFINIERT "Error (Das Ergebnis ist \ nicht definiert)\n" #define SCPPK_OUT_HILFE \ cout << "Bitte geben sie 2 Zahlen als Parameter an.\n";\ cout << "z.B. Rechne 12 8\n"; #endif |
#include <iostream.h> #include <limits.h> #include <float.h> #include "scppkMath.h" void ScppkMinus( int nZahl1, int nZahl2 ) . . . |
#ifndef __scppkMath_h__ #define __scppkMath_h__ /// /// Texte /// #define SCPPK_STR_ERROR_ZUGROSS \ "Error (Das Ergebnis ist zu gross)\n" #define SCPPK_STR_ERROR_ZUKLEIN \ "Error (Das Ergebnis ist zu klein)\n" #define SCPPK_STR_ERROR_UNDEFINIERT \ "Error (Das Ergebnis ist \ nicht definiert)\n" /// /// Funktionen /// void ScppkMinus( int nZahl1, int nZahl2 ); void ScppkPlus( int nZahl1, int nZahl2 ); /// /// Intern genutzte Funktionen /// int nScppkIntegertest( double dZahl ); #endif |
#ifndef __main_h__ #define __main_h__ #define SCPPK_STR_HILFE \ "Bitte geben sie 2 Zahlen als Parameter an.\n\ z.B. Rechne 12 8\n" #endif |
.
.
.
int main( int argc, char * argv[], char * envp[] )
{
int nZahl1;
int nZahl2;
if ( argc != 3 )
{
cout << SCPPK_STR_HILFE;
}
else
{
.
.
.
|