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.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter11: Introduction To Classes
Section11.4: A Case Study: Constructing A Date Class
Problem 3E
icon
Related questions
Question

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

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. AddDistance 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. isGreater: should return a variable of type bool to indicate whether 1st distance is greater than
2nd or not.
e. issmaller: should return a variable of type bool to indicate whether 1st distance is smaller than
2nd or not.
f. isGreaterEqual: should return a variable of type bool to indicate whether 1st distance is greater
than or equal to 2nd or not.
g. isSmallerEqual: should return a variable of type bool to indicate whether 1st distance is smaller
than or equal to 2nd or not.
h. isEqual: should return a variable of type bool to indicate whether 1st distance is equal to the 2nd
distance or not.
i. isNotEqual: should return a true value if both the distances are not equal and return a false if
both are equal.
Write a main function to test this class.
Transcribed Image Text: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. AddDistance 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. isGreater: should return a variable of type bool to indicate whether 1st distance is greater than 2nd or not. e. issmaller: should return a variable of type bool to indicate whether 1st distance is smaller than 2nd or not. f. isGreaterEqual: should return a variable of type bool to indicate whether 1st distance is greater than or equal to 2nd or not. g. isSmallerEqual: should return a variable of type bool to indicate whether 1st distance is smaller than or equal to 2nd or not. h. isEqual: should return a variable of type bool to indicate whether 1st distance is equal to the 2nd distance or not. i. isNotEqual: should return a true value if both the distances are not equal and return a false if both are equal. Write a main function to test this class.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage