Answer to Question #322359 in C++ for saim

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.

1
Expert's answer
2022-06-29T13:48:30-0400
#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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog