Write a function template named maximum. The function takes two values of the same type as its arguments and returns the larger of the two arguments (or either value if they are equal). Give both the function declaration and the function definition for the template. You will use the operator < in your definition. Therefore, this function template will apply only to types for which < is defined. Write a comment for the function declaration that explains this restriction.
Want to see the full answer?
Check out a sample textbook solutionChapter 17 Solutions
Problem Solving with C++ (9th Edition)
Additional Engineering Textbook Solutions
Modern Database Management (12th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Programming in C
Starting Out with C++ from Control Structures to Objects (9th Edition)
Computer Science: An Overview (12th Edition)
Database Concepts (7th Edition)
- Using C++ make a set of function templates that have these features: This function must return a value. A function template with 1 template parameter, T. And, any other parameters you want. A function template with 2 template parameters, T1 and T2. And, any other parameters you want. Using your own creativity, make a set of class templates that have these features: For this class template, put everything in one place--do not declare the member functions and have separate definition of the member functions elsewhere. Keep them in one place. Include a private variable. Include a constructor that loads the private variable when constructed. Include a destructor that clears the private variable to zero. Include set and get functions to set and get the private variable. For this class template, use declarations for variables and functions, like you do in header file (which you may use if you want). Then, separately put the full function definitions for each class member function…arrow_forwardWrite a simple function template for predicate function isEqualTo that compares its two arguments of the same type with the equality operator (==) and returns true if they are equal and false otherwise. Use this function template in a program that calls isEqualTo only with a variety of fundamental types. Now write a separate version of the program that calls isEqualTo with a user-defined class type, but does not overload the equality operator. What happens when you attempt to run this program? Now overload the equality operator (with the operator function) operator==. Now what happens when you attempt to run this program?arrow_forwardGiven the code segment below, what should be the data type of the formal parameter in the function prototype of func(), given the call from main()?Note that function prototypes need not include the identifier (name of the parameter), so do NOT put any variable name in your answer. Remove any space in your answer. If the accessing is wrong, answer INVALID (in all capital letters). void func( ______ );int main(){ double aData[6][4];func(&aData[4]);return 0;}arrow_forward
- Create the C++ Function Template named multiples so that it has three parameters sum, x, and n.The first two parameters will have the type represented by the function template type parameterWhatKind. n will always be int. The return type is void. All parameters are passed by valueexcept for sum which is passed by reference. A Template Function created from multiples willcompute...sum = 1 + x + 2x + 3x + ... + nxarrow_forwardGiven the Class Definition for ClockType discussed extensively in class, write what would have to be added to the IMPLEMENTATION FILE for the Class ClockType to overload the “= =”, i.e., the comparison “equal-equal sign,” here: That is, write the FULL FUNCTION DEFINITION for THE FUNCTION associated with Class ClockType to overload the “= =” remembering the private members are: b) int hr; // that contains the hours int min; // that contains the minutes int sec; // that contains the secondsarrow_forwardGiven the Class Definition for ClockType discussed extensively in class, write what would have to be added to the FUNCTION DEFINITION for the Class ClockType to overload the “= =”, i.e., the comparison “equal-equal sign,” here: NOTE: In other words, WHAT WOULD BE ADDED TO THE CLASS DEFINITION ONLY? Note: ThePrivate Members are: int hr; // contains the hours int min; // contains the minutes int sec; // contains the secondsarrow_forward
- Using C++ Using your own creativity, make a set of function templates that have these features: This function must return a value. A function template with 1 template parameter, T. And, any other parameters you want. A function template with 2 template parameters, T1 and T2. And, any other parameters you want. Using your own creativity, make a set of class templates that have these features: For this class template, put everything in one place--do not declare the member functions and have separate definition of the member functions elsewhere. Keep them in one place. Include a private variable. Include a constructor that loads the private variable when constructed. Include a destructor that clears the private variable to zero. Include set and get functions to set and get the private variable. For this class template, use declarations for variables and functions, like you do in header file (which you may use if you want). Then, separately put the full function definitions for…arrow_forwardConsider the following template function prototype: template <class Type> Type addem (Type x, Type y) Write the DEFINITION (code) of the template to implement the function that would ADD the two parameters x and y and return the result. NO include or using statements required in this code segment. Write a STATEMENT that would call (invoke) the function with two integer values/variables.arrow_forwardWrite a class basicMaths and use constructor to pass a number. Create a function FindNumber takes one number as a parameter and Ñnds if it is positive or negatieve number. Create another class intermediateMaths with same functions and redeÑne the FindNumber functionality by Ñnding the number as even or odd number. Create another class advanceMaths with same functions and redeÑne the FindNumber functionality by Ñnd the number as prime number or composite number. Consider the following example code for the logic of prime number:arrow_forward
- Use Clojure to complete these questions: Please note that this is the beginning of the course so please use simple methods possible, thanks a. The built-in function type is useful for checking what kind of object an expression evaluates to. Write a function both-same-type? that takes two arguments, and returns true when they both have the same type, and false otherwise. b. Write a function list-longer-than? which takes two arguments: an integer n, and a list lst and returns true if lst has more than n elements, and false otherwise. For example, (list-longer-than? 3 '(1 2 3)) should return false, and (list-longer-than? 2 '(1 2 3)) should return true. c. See attached picture.arrow_forwardA function template can be overloaded by another function template with the samefunction name. T/Farrow_forwardWrite a simple function template using C++ with a focus on functions, parameters, and class tenplates. Please explain the example thank you.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning