C++ Class Definition Create objects for English measurements

Description

C++ Class Definition Create objects for English measurements

#include <iostream>
using namespace std;
class Measure// w ww  .j a v  a2 s .c  o  m
{
   private:
   int feet;
   float inches;
   public:
   void setdist(int ft, float in)  //set Measure to args
   { feet = ft; inches = in; }
   void getdist()              //get length from user
   {
      cout << "\nEnter feet: ";  cin >> feet;
      cout << "Enter inches: ";  cin >> inches;
   }
   void showdist()
   { 
       cout << feet << "\'-" << inches << '\"'; 
   }
};
int main()
{
   Measure dist1, dist2;
   dist1.setdist(11, 6.25);       //set dist1
   dist2.getdist();               //get dist2 from user
   //display lengths
   cout << "\ndist1 = ";  dist1.showdist();
   cout << "\ndist2 = ";  dist2.showdist();
   cout << endl;
   return 0;
}



PreviousNext

Related