Programmieren leicht erlernt |
#include <iostream.h> #include <stdlib.h> #include <limits.h> #include <float.h> #include "main.h" // Die Funktionsdeklarationen wurden entfernt void ScppkMinus( int nZahl1, int nZahl2 ) { double dErgebnis; double d1 = 0; dErgebnis = (double) nZahl1 - (double) nZahl2; if ( nScppkIntegertest( dErgebnis ) ) { cout << nZahl1 - nZahl2; } } . . . |
void ScppkMinus( int nZahl1, int nZahl2 ); int nScppkIntegertest( double dZahl ); void ScppkPlus( int nZahl1, int nZahl2 ); int main( int argc, char * argv[], char * envp[] ); |
#ifndef __main_h__ #define __main_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[] ); #endif |
#include <iostream.h>
#include <stdlib.h>
#include <limits.h>
#include <float.h>
#include "main.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 )
{
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;
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 )
{
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__ void ScppkMinus( int nZahl1, int nZahl2 ); int nScppkIntegertest( double dZahl ); void ScppkPlus( int nZahl1, int nZahl2 ); int main( int argc, char * argv[], char * envp[] ); #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 |