Create a class called Distance containing two members feet and inches. This class represents distance measured in feet and inches. For this class, provide the following functions: a. A no-argument constructor that initializes the data members to some fixed values. b. A 2-argument constructor to initialize the values of feet and inches to the values sent from the calling function at the time of creation of an object of type Distance. c. Add distance function to add two distances: Feet and inches of both objects should add in their corresponding members 12 inches constitute one foot. Make sure that the result of addition doesn’t violate this rule.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Create a class called Distance containing two members feet and inches. This class represents distance measured in feet and inches. For this class, provide the following functions:
a. A no-argument constructor that initializes the data members to some fixed values.
b. A 2-argument constructor to initialize the values of feet and inches to the values sent from the calling function at the time of creation of an object of type Distance.
c. Add distance function to add two distances: Feet and inches of both objects should add in their corresponding members 12 inches constitute one foot. Make sure that the result of addition doesn’t violate this rule.
d. Is greater: should return a variable of type bool to indicate whether 1st distance is greater than 2nd or not.
e. Is smaller: should return a variable of type bool to indicate whether 1st distance is smaller than 2nd or not.
f. Is greater equal: should return a variable of type bool to indicate whether 1st distance is greater than or equal to 2nd or not.
g. Is smaller equal: should return a variable of type bool to indicate whether 1st distance is smaller than or equal to 2nd or not.
h. Is equal: should return a variable of type bool to indicate whether 1st distance is equal to the 2nd distance or not.
i. Is not equal: should return a true value if both the distances are not equal and return a false if both are equal.
Write the main function to test this class
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images