Question

In: Computer Science

Take the following program and include overload functions into it. Display result of function. C++ Program:...

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;

}

Solutions

Expert Solution

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...


Related Solutions

Your Task: Write a calculator Program with following functions (lack of function will result in a...
Your Task: Write a calculator Program with following functions (lack of function will result in a grade of zero). Your program must have the following menu and depending on the users choice, your program should be calling the pertaining function to display the result for the user. 1 - Add 2 - Subtract 3 - Multiply 4 - Divide 5 - Raise X to the power Y 6 - Finds if a number is even or odd 0 - Quit...
Your Task: Write a calculator Program with following functions (lack of function will result in a...
Your Task: Write a calculator Program with following functions (lack of function will result in a grade of zero). Your program must have the following menu and depending on the users choice, your program should be calling the pertaining function to display the result for the user. 1 - Add 2 - Subtract 3 - Multiply 4 - Divide 5 - Raise X to the power Y 6 - Finds if a number is even or odd 0 - Quit...
Using c++, write a program that will display your name as a void function then will...
Using c++, write a program that will display your name as a void function then will perform the following by user-defined functions: a. to compute for the sum of two numbers (n1, n2) using function.
Take the following C++ program and translate it into assembly language( pep9 ) #include using namespace...
Take the following C++ program and translate it into assembly language( pep9 ) #include using namespace std; char ch; int main() {    cin >> ch;    cout << "You inputted " << ch << endl;    ch++;    cout << "Next character is " << ch << endl; if (ch <= ‘Z’)         cout << “Could be luppercase\n”;    return 0; }
C++ Download the attached program and complete the functions. (Refer to comments) main.cpp ~ #include #include...
C++ Download the attached program and complete the functions. (Refer to comments) main.cpp ~ #include #include #define END_OF_LIST -999 using namespace std; /* * */ int exercise_1() { int x = 100; int *ptr; // Assign the pointer variable, ptr, to the address of x. Then print out // the 'value' of x and the 'address' of x. (See Program 10-2) return 0; } int exercise_2() { int x = 100; int *ptr; // Assign ptr to the address of...
C++ program to perform each of the area calculations in separate functions. Your program will take...
C++ program to perform each of the area calculations in separate functions. Your program will take in the relevant information in the main (), call the correct function that makes the calculation, return the answer to the main () and then print the answer to the screen. The program will declare a variable called “choice” of type int that is initialized to 0. The program will loop while choice is not equal to 4. In the body of the loop...
C++ Write a program that has two functions. The 1st function is the main function. The...
C++ Write a program that has two functions. The 1st function is the main function. The main function should prompt the user for three inputs: number 1, number 2, and an operator. The main function should call a 2nd function called calculate. The 2nd function should offer the choices of calculating addition, subtraction, multiplication, and division. Use a switch statement to evaluate the operator, then choose the appropriate calculation and return the result to the main function.
in C++ You will overload a function named printArray. The function will assign values to each...
in C++ You will overload a function named printArray. The function will assign values to each element and print out a single dimension array of integers and an array of characters. The main body of the program will call each function. (6 points) Using the player switch portion of the tic tac toe game, create a function that does the switch. This is a practice in applying local variables, parameters, and global variables. (4 points)
C++ program assignment asks to implement the following functions. Each function deals with null terminated C-strings....
C++ program assignment asks to implement the following functions. Each function deals with null terminated C-strings. Assume that any char array passed into the functions will contain valid, null-terminated data. The functions must have the signatures listed below. 1. This function returns the last index where the target char can be found in the string. it returns -1 if the target char does not appear in the string. For example, if s is “Giants” and target is ‘a’ the function...
C++ Program Overload the following operators to work with the Rational class and add test cases...
C++ Program Overload the following operators to work with the Rational class and add test cases in the driver program. Make sure your driver program now tests each of these symbols for your Rational Class. + – * / == != < <= > >= << (stream insertion operator, use the toString function) >> (stream extraction operator) Make sure you test all 12 operators Example Run (Bold is input), everything else is a print statement using the overloaded operators Enter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT