Answer to Question #193031 in C++ for Ajith M

Question #193031

Design a template function for swapping the int, double and char type values between two variables. Note: Use function overloading.


1
Expert's answer
2021-05-20T00:27:47-0400
#include<iostream>
using namespace std;

void template(int a, int b){
  int temp=a;
  a=b;
  b=a;
}
void template(double a,double b){
  double temp=a;
  a=b;
  b=temp;
}
void template(char a, char b){
  char temp=a;
  a=b;
  b=a;
}

int main(){
  template(5,10);
  template(5.10,10.5);
  template('a','b');
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog