daily pastebin goal
39%
SHARE
TWEET

Type Convertion

aminkaiser Dec 10th, 2018 (edited) 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class Distance
  5. {
  6.     int feet;
  7.     float inches;
  8.     float n;
  9. public:
  10.     Distance()
  11.     {
  12.         feet=0;
  13.         inches=0.0;
  14.     }
  15.     Distance(int ft, float in)
  16.     {
  17.         feet=ft;
  18.         inches=in;
  19.     }
  20.     Distance(float meters)
  21.     {
  22.         float fltfeet=3.2808*meters;
  23.         feet=int(fltfeet);
  24.         inches=12*(fltfeet-feet);
  25.     }
  26.     operator float() const
  27.     {
  28.         float fracfeet=inches/12;
  29.         fracfeet+=static_cast<float>(feet);
  30.         return fracfeet/3.0808;
  31.  
  32.     }
  33.  
  34.     void Getdata()
  35.     {
  36.         cout<<"\nEnter Feet : ";
  37.         cin>>feet;
  38.         cout<<"\nEnter Inches : ";
  39.         cin>>inches;
  40.     }
  41.  
  42.     void showdist() const
  43.     {
  44.         cout<<feet<<"\'-'"<<inches<<"'\'";
  45.     }
  46. };
  47.  
  48.  
  49. int main()
  50. {
  51.     float mtrs;
  52.     Distance D1(2.35);
  53.     cout<<"\nDistance1= ";
  54.     D1.showdist();
  55.     mtrs=static_cast<float>(D1);
  56.     cout<<"\nDistance1 = "<<mtrs<<"Meters\n";
  57.     Distance dist2(5,10.25);
  58.     mtrs=dist2;
  59.     cout<<"\nDist2 = "<<mtrs<<"Meters\n";
  60.     dist2=mtrs;
  61.     return 0;
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top