Write a program to showing use of non-type parameter in function template


 

/* Write a program to showing use of non-type parameter in function template*/

#include<iostream.h>

#include<conio.h>

template<class t>

void display(t a,t b,char operation)

{

switch(operation)

{

case ‘+’:

cout<<a<<operation<<b<<‘='<<a+b<<endl;

break;

case ‘-‘:

cout<<a<<operation<<b<<‘='<<a-b<<endl;

break;

case ‘*’:

cout<<a<<operation<<b<<‘='<<a*b<<endl;

break;

case ‘/’:

cout<<a<<operation<<b<<‘='<<a/b<<endl;

break;

default:

cout<<“define operation”;

}}

void main()

{

clrscr();

display(20,40,’+’);

display(3.5,1.5,’-‘);

display(‘c’,’d’,’+’);

getch();

}

/* output:

20+40=60

3.5-1.5=2

c+d=199*/

Related Posts

Comments are closed.