Category : C++ Source Code
Archive   : CPPTUT.ZIP
Filename : OVERLOAD.CPP

 
Output of file : OVERLOAD.CPP contained in archive : CPPTUT.ZIP
// Chapter 4 - Program 6
#include

overload do_stuff; // This is optional

int do_stuff(const int); // This squares an integer
int do_stuff(float); // This triples a float & returns int
float do_stuff(const float, float); // This averages two floats

main()
{
int index = 12;
float length = 14.33;
float height = 34.33;

cout << "12 squared is " << do_stuff(index) << "\n";
cout << "24 squared is " << do_stuff(2 * index) << "\n";
cout << "Three lengths is " << do_stuff(length) << "\n";
cout << "Three heights is " << do_stuff(height) << "\n";
cout << "The average is " << do_stuff(length,height) << "\n";
}

int do_stuff(const int in_value) // This squares an integer
{
return in_value * in_value;
}

int do_stuff(float in_value) // Triples a float & return int
{
return (int)(3.0 * in_value);
}

// This averages two floats
float do_stuff(const float in1, float in2)
{
return (in1 + in2)/2.0;
}




// Result of execution
//
// 12 squared is 144
// 24 squared is 576
// Three lengths is 42
// Three heights is 102
// The average is 24.330002


  3 Responses to “Category : C++ Source Code
Archive   : CPPTUT.ZIP
Filename : OVERLOAD.CPP

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/