Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class Distance
- {
- int feet;
- float inches;
- float n;
- public:
- Distance()
- {
- feet=0;
- inches=0.0;
- }
- Distance(int ft, float in)
- {
- feet=ft;
- inches=in;
- }
- Distance(float meters)
- {
- float fltfeet=3.2808*meters;
- feet=int(fltfeet);
- inches=12*(fltfeet-feet);
- }
- operator float() const
- {
- float fracfeet=inches/12;
- fracfeet+=static_cast<float>(feet);
- return fracfeet/3.0808;
- }
- void Getdata()
- {
- cout<<"\nEnter Feet : ";
- cin>>feet;
- cout<<"\nEnter Inches : ";
- cin>>inches;
- }
- void showdist() const
- {
- cout<<feet<<"\'-'"<<inches<<"'\'";
- }
- };
- int main()
- {
- float mtrs;
- Distance D1(2.35);
- cout<<"\nDistance1= ";
- D1.showdist();
- mtrs=static_cast<float>(D1);
- cout<<"\nDistance1 = "<<mtrs<<"Meters\n";
- Distance dist2(5,10.25);
- mtrs=dist2;
- cout<<"\nDist2 = "<<mtrs<<"Meters\n";
- dist2=mtrs;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement