function overloading??

I am new to programming and am wondering if someone can help me with this code...

Please implement concisely and efficiently the following function overloading (in red) which calculates the minimum of different numbers of inputs. OUTPUT all the results into an output file, out.txt.

Here is my source code to change... can anyone help me with this??


//overmin.cpp

#include <iostream>
using namespace std;

// Function Prototypes
//The following are all considered by the compiler
//to be different functions.

int min(int, int, int);
int min(int, int);
int min(int, int, int, int);
int min(int, int, int, int, int);
// declare the outfile out.txt here


int min (int x, int y){
if (x>y)
return y;
return x;
}


int min(int, int, int) {…} // Hint: set min to be the first parameter, etc. for concise logic
int min(int, int, int, int){..}
int min(int, int, int, int, int){…}
Here is what I have so far... I need the code to figure the min of 5 integers...I am stuck!

//overmin.cpp

#include <iostream>
using namespace std;

// Function Prototypes
//The following are all considered by the compiler
//to be different functions.

int min(int, int, int);
int min(int, int);
int min(int, int, int, int);
int min(int, int, int, int, int);
// declare the outfile out.txt here


int main(){
cout << "min= " << min(55, 66) << endl;
cout << "min= " << min(99, 77, 33) << endl;
cout << "min= " << min(34, 6, 72,9) << endl;
cout << "min= " << min(34, 6, 72, 9, 2) << endl;
char c; cin>>c;
return 0;
}


int min (int x, int y){
if (x>y)
return y;
return x;
}

int min (int x, int y, int z){
if (x<y){
if (x<z)
return x;
else
return z;
}
else{
if (y<z)
return y;
else
return z;
}
}

int min (int x, int y, int z, int r){
if (x<y){
if (x<z)
return x;
else
return z;
}
else{
if (y<z){
if (y<r)
return y;
else
return r;
}
else{
if (r<x){
if (r<z)
return r;
else
return z;
}
}}}

Avoid complicated else/if chains. it's hard to make sense of your min functions because they're such a large tangled mess. That's also why you're having difficulty with the last function.


Instead.... don't be afraid to make new variables. For example, in each function you could have a "lowest" variable. If a number is lower than the lowest, then it becomes the new lowest.
closed account (EzwRko23)
The only place you need to use "if" or ternary operator, is in the definition of min(x, y).

min(x, y) = if (x < y) x else y
min(x, y, z) = min(min(x, y), z)
min(x, y, z, r, u) = min(min(x, y), min(z, r, u))
don't post full solutions plzkthx
Topic archived. No new replies allowed.