Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- const float M2F = 3.28;
- class Distance{
- private:
- int feet;
- float inches;
- public:
- Distance(): feet(0), inches(0.0) {}
- Distance(float meters){
- float frac_feet = meters * M2F;
- feet = frac_feet;
- inches = (frac_feet - feet) * 12;
- }
- ~Distance() {}
- operator float(){
- return (feet + inches / 12) / M2F;
- }
- void read() { cin >> feet >> inches;}
- void show(){
- cout.setf(ios::fixed);
- cout << feet << " feet " << setprecision(2) << inches << " inches" << endl;
- }
- };
- int main(){
- cout.setf(ios::fixed);
- float meters;
- cout << "Enter METER value: ";
- cin >> meters;
- Distance D;
- D = meters;
- D.show();
- cout << "Enter FEET and INCHES: ";
- D.read();
- meters = D;
- cout << meters << setprecision(2) << " meters" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement