C++ Class Template for the Array Class.
CODING:
#include<iostream.h>
#include<conio.h>
int i=0;
template <class t>
class array
{
t a[5];
public:
void set()
{
if(i<5)
{
cout<<'['<<i<<']';
cin>>a[i++];
set();
}
}
void disp()
{
if(i>0)
{
cout<<a[--i];
disp();}
}
};
void main()
{
clrscr();
array <int> a1;
cout<<"ENTRE ONE DIGIT:\n";
a1.set();
cout<<"NUMBER:";a1.disp();
array <char> a2;
cout<<"\nENTRE ONE CHARACTER:\n";
a2.set();
cout<<"STRING:";a2.disp();
getch();
}
CODING:
#include<iostream.h>
#include<conio.h>
int i=0;
template <class t>
class array
{
t a[5];
public:
void set()
{
if(i<5)
{
cout<<'['<<i<<']';
cin>>a[i++];
set();
}
}
void disp()
{
if(i>0)
{
cout<<a[--i];
disp();}
}
};
void main()
{
clrscr();
array <int> a1;
cout<<"ENTRE ONE DIGIT:\n";
a1.set();
cout<<"NUMBER:";a1.disp();
array <char> a2;
cout<<"\nENTRE ONE CHARACTER:\n";
a2.set();
cout<<"STRING:";a2.disp();
getch();
}
Comments
Post a Comment