Problem statement In this question first we will practice function overloading and then function templates. Please follow below instructions. 1. We can extend multiplication easily for string types if we interpret the operation as repetition. For example "code" * 3 may be interpreted as "codecodecode". In fact, languages like Python already support this operation. Write a C++ function named multiply that can multiply(repeat) an std::string by a given integer number and return the repeated string. 2. Write another C++ function named multiply that can multiply two given integer (int type) numbers and return the product as an integer. 3. Write another C++ function with the same name that can multiply a floating point number (double type) by a given integer number and return the product as a floating point number. 4. We defined three functions with the same name without a problem. It is either because they have a different number of parameters, or because any of their parameters are of a different type. This allows the compiler to recognize which one to consider, each function is unique though the names are same. 5. What if we can write a single function that can handle all three data types and give the results accordingly? We can do so using C++ function templates. Write a C++ function template named multiply_type that can take any floating point number(double type) or integer(int type) or an std::string as the first parameter and any integer number as the second and returns the respective product of the two. Do the following 1. Write your algorithm as code comments. I recommend to follow UMPIRE technique ( 2. Implement your functions (60) 3. In your driver program, test your function for the criteria given below. Note that this may be either fully or partially set up already in CodeCheck. points) 1 2 3 5 6 Test # 10 10 4 6 2.8 10 "C++" 10 "Rain" 2 input Criteria 100 24 28.0 Output "C++C++C++C++C++C++C++C++C++C++" "RainRain"
Problem statement In this question first we will practice function overloading and then function templates. Please follow below instructions. 1. We can extend multiplication easily for string types if we interpret the operation as repetition. For example "code" * 3 may be interpreted as "codecodecode". In fact, languages like Python already support this operation. Write a C++ function named multiply that can multiply(repeat) an std::string by a given integer number and return the repeated string. 2. Write another C++ function named multiply that can multiply two given integer (int type) numbers and return the product as an integer. 3. Write another C++ function with the same name that can multiply a floating point number (double type) by a given integer number and return the product as a floating point number. 4. We defined three functions with the same name without a problem. It is either because they have a different number of parameters, or because any of their parameters are of a different type. This allows the compiler to recognize which one to consider, each function is unique though the names are same. 5. What if we can write a single function that can handle all three data types and give the results accordingly? We can do so using C++ function templates. Write a C++ function template named multiply_type that can take any floating point number(double type) or integer(int type) or an std::string as the first parameter and any integer number as the second and returns the respective product of the two. Do the following 1. Write your algorithm as code comments. I recommend to follow UMPIRE technique ( 2. Implement your functions (60) 3. In your driver program, test your function for the criteria given below. Note that this may be either fully or partially set up already in CodeCheck. points) 1 2 3 5 6 Test # 10 10 4 6 2.8 10 "C++" 10 "Rain" 2 input Criteria 100 24 28.0 Output "C++C++C++C++C++C++C++C++C++C++" "RainRain"
Related questions
Question
C++ questions
why I'm getting these errors please help
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 4 images