Writea program that defines a template function named add(). This function takes
ID: 3608430 • Letter: W
Question
Writea program that defines a template function named add(). This function takestwo arguments, add two variables and then return the sum.
In main function, define two variables of type int, twovariables of type float and two objects of type‘String’. Now call the add() function three times forthese different data types.
Note: String isa user-defined data type and for this you have to define a classnamed ‘String’. When template function will be calledto add two objects of type String then it must concatenate twostrings.
Youroutput should look like this:
SampleOutput:
Enter two integer values to be added
EnterFirst value: 12
EnterSecond value: 25
Enter two float values to be added
EnterFirst value: 13.5
EnterSecond value: 14.2
Enter two Strings to be added
EnterFirst value: Virtual
EnterSecond value: University
Addition of two variables of different data types
Sumof values of type int = 37
Sumof values of type float = 27.7
Explanation / Answer
please rate - thanks you can find your answer at this post /computer-science-topic-5-455607-cpi0.aspx
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.