#include<iostream>
#include<string.h>
using namespace std;
template<class A>
class largest
{
A *a;
int n;
public:
void input();
void calculation();
void display();
};
template<class A>
void largest<A>::input()
{ a=new A [n];
cout<<"enter numbers to be :";
cin>>n;
cout<<"enter n numbers "<<endl;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
}
template<class A>
void largest<A>::calculation(){
A temp;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
template<class A>
void largest<A>::display()
{ cout<<"largest number is ";
cout<<a[n-1];
}
int main()
{
largest<int> l;
l.input();
l.calculation();
l.display();
largest<float> f;
f.input();
f.calculation();
f.display();
return 0;
}
0 comments:
Post a Comment