Hi i am wondering how to convert inches to feet from the user input? i am doing overload programs with main.cpp, distance.h and distance.cpp.
here is my code
According to your question, inches to feet is simple enough, simply divide by 12. Feet to inches, multiply by 12. So 1 foot equals 12 inches (1 * 12 = 12) and 36 inches equals 3 feet ( 36 / 12 = 3)
As for your code, I'm not seeing a destructor nor am I seeing a copy constructor. These two things are just as important as the constructor. You also need to overload the assignment operator in case you instantiate your class like so:Distance *foo = new Distance();
Also, why are you redefining the ostream shifting operators? (<< and >>) They don't appear to be part of your class and so re-defining them will most likely give you and error at compile time and is a bad idea. Can we also please see the rest of the source code (.h/.hpp and .c/.cpp)? And please use the code tags (the <> button)
It is, but the operator being overloaded doesn't appear to be part of his class. But to that effect, we don't have the header to examine and confirm/deny this.
If it's not an actual member function then the only thing that it would need is to be made a friend function so it can access the private data members. Other then that, overloaded operators don't NEED to be member functions. In fact, you wouldn't even need friend if the overloaded operator calls the getters to retrieve the feet and inches.
Only other things I'd change would be to change the parameters on the function to be different names then the data members. Using the same name for different variables can obfuscate code and make it harder to read.
Oh, and your gettotal() function. If you are storing inches and feet, returning feet*inches won't represent an accurate total for the how many inches the class holds. I'd change that to return (feet * 12 + inches)