1
0
Fork 0

Ex2.2 feedback: explicit definition for int,double and double,int signatures for min function

This commit is contained in:
Eric Teunis de Boone 2020-07-01 14:11:04 +02:00
parent 52d1f4e4e9
commit bf04d5a4b2

View file

@ -3,12 +3,14 @@
* *
* generalisation of type is possible * generalisation of type is possible
* => not writing an int implementation means always use the double * => not writing an int implementation means always use the double
* => => even when to ints are supplied, they are generalised to doubles * => => even when two ints are supplied, they are generalised to doubles
*/ */
#include <iostream> #include <iostream>
//int min( int a, int b ); int min( int a, int b );
double min( double a, int b );
double min( int a, double b );
double min( double a, double b ); double min( double a, double b );
int min( int a[], int size); int min( int a[], int size);
@ -27,15 +29,30 @@ int main() {
std::cout << "min( 3.12345, 4 ) = " << min(3.12345, 4) << std::endl; std::cout << "min( 3.12345, 4 ) = " << min(3.12345, 4) << std::endl;
std::cout << "min( 4, 3.12345 ) = " << min(4, 3.12345) << std::endl;
return 0; return 0;
} }
//int min( int a, int b ) { int min( int a, int b ) {
// if ( a < b ) { if ( a < b ) {
// return a; return a;
// } }
// return b; return b;
//} }
double min( double a, int b ) {
if ( a < b ) {
return a;
}
return b;
}
double min( int a, double b ) {
if ( a < b ) {
return a;
}
return b;
}
double min( double a, double b ) { double min( double a, double b ) {
if ( a < b ) { if ( a < b ) {
@ -53,3 +70,5 @@ int min( int a[], int size ) {
return m; return m;
} }
// Fix interchangeabiliy of doubles and ints