answersLogoWhite

0


Best Answer

Write a program that defines a template function named add(). This function takes two arguments, add two variables and then return the sum. In main function, define two variables of type int, two variables of type float and two objects of type 'String'. Now call the add() function three times for these different data types. Note: String is a user-defined data type and for this you have to define a class named 'String'. When template function will be called to add two objects of type String then it must concatenate two strings. Your output should look like this: Sample Output: Enter two integer values to be added Enter First value: 12 Enter Second value: 25 Enter two float values to be added Enter First value: 13.5 Enter Second value: 14.2 Enter two Strings to be added Enter First value: Virtual Enter Second value: University Addition of two variables of different data types Sum of values of type int = 37 Sum of values of type float = 27.7 Sum of values of type String = VirtualUniversity

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program that defines a template function named add This function takes two arguments add two variables and then return the sum?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Object and classes Use a person as an example?

A class is like a template. You can define a class "Person", which defines what type of data you want to store for a person - for example, for a computer game, the person's name his accumulated score, and how many lives he has left. The class might better be called "Player" in this case - but you can just as well store other data for a Person.Then, you create objects for two different players. You declare variables player1 and player2, both of type "Person". It is in these variables - player1 and player2 - where you store specific information about individual persons.A class is like a template. You can define a class "Person", which defines what type of data you want to store for a person - for example, for a computer game, the person's name his accumulated score, and how many lives he has left. The class might better be called "Player" in this case - but you can just as well store other data for a Person.Then, you create objects for two different players. You declare variables player1 and player2, both of type "Person". It is in these variables - player1 and player2 - where you store specific information about individual persons.A class is like a template. You can define a class "Person", which defines what type of data you want to store for a person - for example, for a computer game, the person's name his accumulated score, and how many lives he has left. The class might better be called "Player" in this case - but you can just as well store other data for a Person.Then, you create objects for two different players. You declare variables player1 and player2, both of type "Person". It is in these variables - player1 and player2 - where you store specific information about individual persons.A class is like a template. You can define a class "Person", which defines what type of data you want to store for a person - for example, for a computer game, the person's name his accumulated score, and how many lives he has left. The class might better be called "Player" in this case - but you can just as well store other data for a Person.Then, you create objects for two different players. You declare variables player1 and player2, both of type "Person". It is in these variables - player1 and player2 - where you store specific information about individual persons.


What are the usages of keyword final in java?

It's a built-in keyword that defines an entity that cannot be later modified. It can be used in different aspects within your code (like setting a 'final' class, method (function), or variable).


What are local variables and global variables?

Local variables: These variables only exist inside the specific function that creates them. They are unknown to other functions and to the main program. As such, they are normally implemented using a stack. Local variables cease to exist once the function that created them is completed. They are recreated each time a function is executed or called. Global variables: These variables can be accessed (ie known) by any function comprising the program. They are implemented by associating memory locations with variable names. They do not get recreated if the function is recalled.


What is the difference between state table and truth table?

A state table defines the behaviour of the of the sequantial function


What is static extern variables in C?

Basically storage class defines the accessibity of a variable. If you specify a variable with auto storage class, then that variable can be accessed only in that function or block where it is declared. if you specify a variable with static storage class, it has the same visibily like an auto variable but it can retains it's value between function calls where as an auto variable cannot. look at this example: void main() { int i,j ; for(j = 0; j< =2; j++) { i = fun1(); printf("%d",i); } } int fun1() { static int k =0; k = k+1; return k; } it prints 1 2 3

Related questions

What is the name of a sentence that defines the value of the unknowns in a problem is called a?

A sentence which defines a value of variables in a mathematical problem is called a statement. The relationship between variables in a mathematical problem is called a function.


What arguments are optional and not required for the PMT function in MS Excel?

The FV and Type arguments are optional in the PMT function.


What is an algebraic expression that defines a function?

It is a function notation


What word defines irrelevant facts or arguments to distract?

I think the word you're looking for is erroneous


What is implicit differentiation?

implicit function/? an equation the function(x,y)=0 defines y implicitly as a function of x the domain of that implicitiy defines function consists of those x for which there is a unique y such that the function (x,y)=0


Is the regression equation a mathematical equation that defines the relationship between two variables?

No. It is an estimated equation that defines the best linear relationship between two variables (or their transforms). If the two variables, x and y were the coordinates of a circle, for example, any method for calculating the regression equation would fail hopelessly.


What defines the nature and function of the American government?

The people.


Main function in c?

The main function defines the entry point of an application in C.


What defines The function of a protein?

i dount know lol if you check, you got trolled :)


Object and classes Use a person as an example?

A class is like a template. You can define a class "Person", which defines what type of data you want to store for a person - for example, for a computer game, the person's name his accumulated score, and how many lives he has left. The class might better be called "Player" in this case - but you can just as well store other data for a Person.Then, you create objects for two different players. You declare variables player1 and player2, both of type "Person". It is in these variables - player1 and player2 - where you store specific information about individual persons.A class is like a template. You can define a class "Person", which defines what type of data you want to store for a person - for example, for a computer game, the person's name his accumulated score, and how many lives he has left. The class might better be called "Player" in this case - but you can just as well store other data for a Person.Then, you create objects for two different players. You declare variables player1 and player2, both of type "Person". It is in these variables - player1 and player2 - where you store specific information about individual persons.A class is like a template. You can define a class "Person", which defines what type of data you want to store for a person - for example, for a computer game, the person's name his accumulated score, and how many lives he has left. The class might better be called "Player" in this case - but you can just as well store other data for a Person.Then, you create objects for two different players. You declare variables player1 and player2, both of type "Person". It is in these variables - player1 and player2 - where you store specific information about individual persons.A class is like a template. You can define a class "Person", which defines what type of data you want to store for a person - for example, for a computer game, the person's name his accumulated score, and how many lives he has left. The class might better be called "Player" in this case - but you can just as well store other data for a Person.Then, you create objects for two different players. You declare variables player1 and player2, both of type "Person". It is in these variables - player1 and player2 - where you store specific information about individual persons.


What are the usages of keyword final in java?

It's a built-in keyword that defines an entity that cannot be later modified. It can be used in different aspects within your code (like setting a 'final' class, method (function), or variable).


What defines an organelle and what they do for a cell?

Organelles are the structures within the cell. They help the cell function.