Answer to Question #211440 in C++ for Hemambar

Question #211440

Write a program that calculates the average of up to 10 English distances input by the user.

Create an array of objects of the Distance class with the data members as feets and inches to

calculate the average create a member function called avgDistance(). (Hint: 12 inches = 1 Feet)


1
Expert's answer
2021-06-29T00:10:55-0400
#include <iostream> 




using namespace std;




class Distance {
private:
	float feets;
	float inches;
public:
	Distance(){}
	Distance(float feets){
		this->inches=12*feets;
	}
	float getInches(){
		return this->inches;
	}


};


float avgDistance(Distance distance[]){
	float total=0;
	for(int i=0;i<10;i++){
		total+=distance[i].getInches();
	}
	return total/10.0;
}
int main (){
	Distance distance[10];
	float feets;
	for(int i=0;i<10;i++){
		cout<<"Enter english distance "<<(i+1)<<" (in feet): ";
		cin>>feets;
		distance[i]=Distance(feets);
	}
	cout<<"\nThe average is: "<<avgDistance(distance)<< " inches\n\n";
	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