Write a program to create a class template for the ‘Array’ class. |
#include<iostream.h>
#include<conio.h>
template<class
t>
class
arrays
{
t *p;
public:
void setdata(t val)
{
p= new t[5];
for(int i=0;i<5;i++)
p[i]=val;
}
void printdata()
{
for(int i=0;i<5;i++)
cout<<"\n"<<p[i];
}
};
void
main()
{
clrscr();
arrays<int>o1;
o1.setdata(5);
o1.printdata();
arrays<float>o2;
o2.setdata(1.2);
o2.printdata();
getch();
}
|