In: Computer Science
Take the following program and include overload functions into it. Display result of function. C++
Program:
#include <iostream>
using namespace std;
// this is the additional function
string read()
{
string input;
cout << "Enter input: ";
cin >> input;
return input;
}
int main()
{
// call function here
string output = read();
cout << "You entered: " << output;
}
Function overloading is a C++ programming feature that allows us to have more than one function having same name but different parameter list, when I say parameter list, it means the data type and sequence of the parameters.
CODE:
#include <iostream>
using namespace std;
class overload {
public:
string read(string i) { //Overloaded fuction
return i;
}
double read(double d) { //Overloaded fuction
return d;
}
};
int main(void) {
overload obj;
cout<<obj.read(100)<<endl;
cout<<obj.read(5005.516);
return 0;
}
upvote pls...