Answer to Question #213492 in C++ for Srikanth Kodamasim

Question #213492
  1. Create two classes IntArray to store the set of integer numbers and FloatArray to store decimal numbers. Add a member function read() for both classes for reading inputs. Create two objects ‘x’ for IntArray and ‘y’ for FloatArray. Read the inputs for x and y. Using a friend function maxmin(x,y), display the maximum and minimum among the set of integers and decimal numbers.
1
Expert's answer
2021-07-04T17:12:08-0400
#include <iostream>



using namespace std;


class FloatArray;


//Create two classes IntArray to store the set of integer numbers and FloatArray to store decimal numbers.
class IntArray{
private:
	int numbers[5];
public:
	//Add a member function read() for both classes for reading inputs. 
	void read(){
		for(int i=0;i<5;i++){
			cout<<"Enter integer value "<<(i+1)<<": ";
			cin>>numbers[i];	
		}
	}
	friend void maxmin(IntArray x,FloatArray y);
};
class FloatArray{
private:
	float numbers[5];
public:
	//Add a member function read() for both classes for reading inputs. 
	void read(){
		for(int i=0;i<5;i++){
			cout<<"Enter decimal value "<<(i+1)<<": ";
			cin>>numbers[i];	
		}
	}
	//Using a friend function maxmin(x,y), display the maximum and 
	//minimum among the set of integers and decimal numbers.
	friend void maxmin(IntArray x,FloatArray y);
};


void maxmin(IntArray x,FloatArray y){
	float min=x.numbers[0];
	float max=x.numbers[0];
	for(int i=0;i<5;i++){
		if(x.numbers[i]<min){
			min=x.numbers[i];
		}
		if(y.numbers[i]<min){
			min=y.numbers[i];
		}
		if(x.numbers[i]>max){
			max=x.numbers[i];
		}
		if(y.numbers[i]>max){
			max=y.numbers[i];
		}
	}
	cout<<"\nThe minimum value is: "<<min<<"\n";
	cout<<"\nThe maximum value is: "<<max<<"\n";
}


int main () {


	//Create two objects ‘x’ for IntArray and ‘y’ for FloatArray. 
	//Read the inputs for x and y. 
	IntArray x;
	FloatArray y;
	x.read();
	cout<<"\n";
	y.read();
	maxmin(x,y);


	//Delay
	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