I need a code that demonstrates the use of the below items (Templates, overloading, and vectors). It doesn't need to be special and you can choose the example for the code. Maybe 30 - 50 lines of code that I can run in Visual Basic 2019. I just want to be able to compile it so that I understand what I am reading next week. Working examples are better than what I can pull from the single code examples in the book. Please label to help me identify. Thanks 1. Write C++ code (perhaps around 30-50 lines of code) and make it compile and run showing how to use: a. Templates b. Overloading c. Vectors
I need a code that demonstrates the use of the below items (Templates, overloading, and
1. Write C++ code (perhaps around 30-50 lines of code) and make it compile and run showing how to use:
a. Templates
b. Overloading
c. Vectors
Part (1)
Template:
PROGRAM CODE:
#include <iostream> // include the required header files
using namespace std;
template <typename T> // template function that works for all kinds of datatypes
T sum(T a, T b) // Parameter for the function are of the template type
{
return a+b; // return the result
}
int main() // main function
{
cout << sum<int>(9, 5) << endl; // Calls sum for integer data type
cout << sum<double>(5.7, 4.5) << endl; // calls sum for double data type
return 0;
}
OUTPUT:
Step by step
Solved in 3 steps with 3 images