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

Question #187303

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-04-29T23:53:30-0400
#include<iostream>
using namespace std;


class tamplate{
    public:
        static int t;
       int numbers[100];
        tamplate(){    //constructor of class
            cout<<"Enter how many no. in the list";
            cin>>t;
            
            cout << "Enter no. of  numbers: " << endl;
            for (int i = 0; i < t; ++i) {
                cin >> numbers[i];
            }
        }
        int largest(){
            int n = sizeof(numbers) / sizeof(numbers[0]);
            sort(numbers, numbers + n, greater<int>());
            return numbers[0];
        }
        int smallest(){
            int n = sizeof(numbers) / sizeof(numbers[0]);
            sort(numbers, numbers + n, greater<int>());
            return numbers[t-1];
        }
};


int main(){
    tamplate obj();
    cout<<"largest no. in the list is"<<obj.largest()<<"  and smallest no. in the list is"<<obj.smallest();
    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