Please create a C++ code that is around 20-30 lines of code and make it compile and run showing how to use templates, overloading, and vectors (define these functions in the code)
#include <iostream>
using namespace std;
#include<vector>
template <class T, class U>
T smaller(T a, U b) {
return (a < b ? a : b);
}
void printNumber(int x) {
cout << "Prints an integer: " << x << endl;
}
void printNumber(float x) {
cout << "Prints a float: " << x << endl;
}
int main () {
int x=72;
double y=15.34;
cout << smaller(x, y) << endl;
vector<int> a;
a.push_back(5);
a.push_back(6);
a.push_back(8);
for(int i=0;i<a.size();i++){
cout<<a.at(i)<<" ";
}
cout<<endl;
int c = 16;
float b = 54.541;
printNumber(c);
printNumber(b);
}
Get Answers For Free
Most questions answered within 1 hours.