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.
#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;
}
Comments
Leave a comment