Tuesday, March 17, 2015

program to demonstrate the use of function template. (C plusplus or C++)

Aim: Write a program to demonstrate the use of function template.
Ans:

#include<iostream.h>
#include<conio.h>
template<class T>
void  out(T x[])
{
            int i;
            for( i=0;i<5;i++)
                        cout<<x[i];
                        cout<<"\n";
}
void  main()
{
            int n[10],x;
            char  o[10];
            float  m[10];
            clrscr();
            cout<<"Enter 5 integers values:\n";
            for(int  i=0;i<5;i++)
            {
                        cin>>n[i];
            }
            cout<<"Enter 5 float values:\n";
            for(int j=0;j<5;j++)
            {
                        cin>>m[j];
            }
            cout<<"Enter 5 charcter values:\n";
            for(int k=0;k<5;k++)
            {
                        cin>>o[k];
            }
            cout<<"The output is:\n";
            out(n);
            out(m);
            out(o);
            getch();
}



No comments:

Post a Comment