EXERCISE - 12

A) Write a C++ program to illustrate template class.
B) Write a program to illustrate class templates with multiple parameters.
A) AIM: Write a C++ program to illustrate templateclass.
SOURCE CODE:
#include<iostream>
using namespace std;
template<class T>
class Data
{
    public:
        Data(T a)
        {
            cout<<"Value of a is:"<<a<<endl;
        }
};
int main()
{
    Data <int>i(5);
    Data <char>c('R');
    Data <double>d(8.467);
}
OUTPUT:
Value of a is:5
Value of a is:R
Value of a is:8.467

B) AIM: Write a program to illustrate class templates with multipleparameters.
SOURCE CODE:
#include<iostream>
using namespace std;
template<class T1,class T2>
class Data
{
    public:
        Data(T1 a,T2 b)
        {
            cout<<"Values are:"<<a<<"\t"<<b<<endl;
        }
};
int main()
{
    Data <int,char>i(5,'R');
    Data <char,double>c('R',8.467);
    Data <double,int>d(8.467,5);
}
OUTPUT:
Values are: 5    R
Values are: R    8.467
Values are: 8.467        5