Find largest element in given number using "Template class". C++

#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<intl;
    l.input();
    l.calculation();
    l.display();

    largest<floatf;
    f.input();
    f.calculation();
    f.display();

return 0;
SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment