Answer to Question #186603 in C++ for RAHUL SINGH

Question #186603

Write a program which has a class template for determining the largest and the smallest number


from a list of numbers. Use a constructor for input and appropriate data members and member


functions in support of your answer.


1
Expert's answer
2021-05-02T18:13:34-0400


#include <iostream>
using namespace std;



template <typename T>
class A
{
 public:
        int a[10];
        A(T arr[], int s);
}  ;
template<typename T>
A<T>::A(T arr[], int s)
{
    cout<<"\nEnter elements of array ";
    for(int i=0;i<s;i++)
    {
        cin>>arr[i];
    }
    for (int i = 0; i < s - 1; i++)
        for (int j = s - 1; i < j; j--)
            if (arr[j] < arr[j - 1])
              swap(arr[j], arr[j - 1]);
    cout<<"\nSmallest number of array is "<<arr[0];
    cout<<"\nLargest number of array is "<<arr[s-1];
}




int main() {
    int n,arr[10];
    cout<<"Enter number of elements in the array ";
    cin>>n;
    A<int> b(arr,n);


  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS