Question #322359

Create a class named Distance that has feets (as int) and inches (as float). The class has Getdist (int, float) to get the specified value in object, Showdist () to display distance object in feets’ inches” format. Write main () function to create two distance objects. Get the value in two objects and display all objects.

Expert's answer

#include <iostream>

using namespace std;

class Distance
{
	int feets;
	float inches;

public:
	void Getdist(int feets, float inches)
	{
		this->feets = feets;
		this->inches = inches;
	}

	void Showdist()
	{
		cout << feets << "' " << inches << "''" << endl;
	}
};

int main()
{
	Distance distance1;
	distance1.Getdist(10, 8.2);
	Distance distance2;
	distance2.Getdist(5, 7.9);
	distance1.Showdist();
	distance2.Showdist();
	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!

LATEST TUTORIALS
APPROVED BY CLIENTS