Answer to Question #188655 in C++ for DIGANTARAG BHATTAC

Question #188655

Create a class: “Question 1” with data members: 1D integer array of maximum size: 100, n (int). Create a dynamic constructor which takes input of n and n no. of array elements. Apart from taking input this class also displays the maximum and minimum elements from the given array elements.


1
Expert's answer
2021-05-04T01:54:09-0400
#include <iostream>
#include <string>




using namespace std;


class Question1{
private:
	//1D integer array of maximum size: 100, n (int). 
	int integers[100];
	int n;
public:
	Question1(int n){
		this->n=n;
	}
	void input(){
		for(int i=0;i<n;i++){
			cout<<"Enter value "<<(i+1)<<": ";
			cin>>this->integers[i];
		}
	}
	void display(){
		int max=this->integers[0];
		int min=this->integers[0];
		for(int i=0;i<n;i++){
			if(max<this->integers[i]){
				max=this->integers[i];
			}
			if(min>this->integers[i]){
				min=this->integers[i];
			}
		}
		cout<<"The minimum element is: "<<min<<"\n";
		cout<<"The maximum element is: "<<max<<"\n";
			
	}
};


int main(){
	Question1 question1(5);
	question1.input();
	question1.display();


	system("pause");
	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