subject

The Distance class will represent a distance in some number of feet and inches. This Distance object must always be positive and never contain an inch value greater than or equal to 12 (12 inches equals 1 foot). It is your job, as the engineer/designer of this Distance class to make sure this is always true. Separate Files
As is commonly done when designing a class, you are to separate your class from the program that will use the class. You will need the following 3 files:
main. cpp: contains the main function and any other global functions used to test your Distance class.
Distance. h: the Distance class header (aka interface) file. Contains the declaration of the Distance class.
Distance. cpp: the Distance class implementation file. Contains the implementations of all Distance member functions.
You will submit all 3 files, main. cpp, Distance. h and Distance. cpp. Here is the Distance. h file you MUST submit:
DO NOT CHANGE THIS FILE IN ANY WAY
// Distance. h file
#include
using namespace std;
class Distance
{
private:
unsigned feet;
double inches;
public:
/* Constructs a default Distance of 0 (0 feet and 0.0 inches)
*/
Distance();
/* Constructs a distance of ft feet and in inches,
unless in >= 12, in which case the values of feet and inches
are adjusted accordingly. A Distance will always be positive.
*/
Distance(unsigned ft, double in);
/* Constructs a distance of 0 ft and in inches,
unless in >= 12, in which case the values of feet and inches
are adjusted accordingly. A Distance will always be positive.
*/
Distance(double in);
/* Returns just the feet portion of the Distance
*/
unsigned getFeet() const;
/* Returns just the inches portion of the Distance
*/
double getInches() const;
/* Returns the entire distance as the equivalent amount of inches.
(e. g., 4 feet 3.5 inches would be returned as 51.5 inches)
*/
double distanceInInches() const;
/* Returns the entire distance as the equivalent amount of feet.
(e. g., 3 feet 6 inches would be returned as 3.5 feet)
*/
double distanceInFeet() const;
/* Returns the entire distance as the equivalent amount of meters.
1 inch equals 0.0254 meters.
(e. g., 2 feet 8.12 inches would be returned as 0.815848 meters)
*/
double distanceInMeters() const;
/* Returns the sum of 2 Distances.
*/
const Distance operator+(const Distance &rhs) const;
/* Returns the difference between 2 Distances.
*/
const Distance operator-(const Distance &rhs) const;
/* Outputs to the stream out the Distance in the format:
feet' inches'' (i. e. 3' 3.41'')
*/
friend ostream & operator<<(ostream &out, const Distance &rhs);
private:
/* Used by the 2 parameterized constructors to convert any negative values to positive and
inches >= 12 to the appropriate number of feet and inches.
*/
void init();
};
Use this main. cpp file for submission. You will want to add your own unit tests of the other public functions, but do not add them to the main. cpp file you are submitting.
int main()
{
Distance d1;
cout << "d1: " << d1 << endl;
Distance d2 = Distance(2, 5.9);
Distance d3 = Distance(3.75);
cout << "d2: " << d2 << endl;
cout << "d3: " << d3 << endl;
//test init helper function
Distance d4 = Distance(5, 19.34);
Distance d5 = Distance(100);
cout << "d4: " << d4 << endl;
cout << "d5: " << d5 << endl;
//test add (<12 inches)
cout << "d4 + d5: " << (d4 + d5) << endl;
//test add (>12 inches)
cout << "d2 + d4: " << (d2 + d4) << endl;
//test sub (0 ft)
cout << "d3 - d1: " << (d3 - d1) << endl;
//test sub (0 ft, negative conversion)
cout << "d1 - d3: " << (d1 - d3) << endl;
//test sub (positive ft & inch)
cout << "d4 - d2: " << (d4 - d2) << endl;
//test sub (negative ft & inch)
cout << "d2 - d4: " << (d2 - d4) << endl;
//test sub (negative ft, positive inch)
cout << "d4 - d5: " << (d4 - d5) << endl;
//test sub (positive ft, negative inch)
cout << "d5 - d2: " << (d5 - d2) << endl;
return 0;
}
Given this main function, if your constructors and operator functions are working correctly, your output will look like:
d1: 0' 0"
d2: 2' 5.9"
d3: 0' 3.75"
d4: 6' 7.34"
d5: 8' 4"
d4 + d5: 14' 11.34"
d2 + d4: 9' 1.24"
d3 - d1: 0' 3.75"
d1 - d3: 0' 3.75"
d4 - d2: 4' 1.44"
d2 - d4: 4' 1.44"
d4 - d5: 1' 8.66"
d5 - d2: 5' 10.1"

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 18:00
Is the following sentence true or false? during meiosis, the two alleles for each gene stay together.
Answers: 3
question
Computers and Technology, 22.06.2019 14:20
Consider a byte-addressable computer with 16mb of main memory, a cache capable of storing a total of 64kb of data and block size of 32 bytes. (a) how many bits in the memory address? (b) how many blocks are in the cache? (c) specify the format of the memory address, including names and sizes, when the cache is: 1. direct-mapped 2. 4-way set associative 3. fully associative
Answers: 2
question
Computers and Technology, 22.06.2019 16:30
Technician a says that a dry sump system uses no oil storage sump under the engine. technician b says that a wet sump system uses no oil storage sump under the engine. who is correct?
Answers: 3
question
Computers and Technology, 22.06.2019 18:30
Word vocabulary words: print, proofread, status line, graphics, font effects, left margin, justification, line spacing, copy/paste, data. review words: font point, bold, save, center, error. fill in the correct word for the definition and then transfer the letters to the appropriate spot by number. some numbers will be found multiple times. you will end up with a quotation about…… what else? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 k 16 17 18 19 20 21 22 23 24 25 8 27 28 29 w 31 32 k 34 35 36 w h 39 40 41 42 8 44 45 46 47 48 49 50 51 52 53 54 55 .1. a software function that records keystrokes on a disk or drive so information can be 5 4 52 9 later retrieved. p n 2. to produce a paper copy of information. 10 7 12u n 3. a display that shows the location of the cursor, pages, etc. 45 46 18 27 36 20 42p4. pictures or images, located in clip art or other files. 6 24 44 28 34 49 555. any mis-stroke of a key. 47 41 48 2 10 n6. allows major changes to the font such as shadow, emboss, etc. 21 25 46 35 23 21 29 14 22 17 n7. a feature that centers lines of text horizontally. 49 53 46 9 51 p8. size of the font 31 16 22 b l 9. a feature that prints designated text darker than the rest to add emphasis. 32 3 . p10. to compare copy on a display screen or printout to the original 24 39 25 23 54 9 50 3 and correct errors. j un 11. a feature that allows text to be aligned at the left 11 12 7 21 16 49 40 46 34 2 and right margins. leftn 12. amount of blank space on the left side of the paper. 8 18 41 6 34 linen 13. number of blank lines between lines of text. 17 4 49 13 1914. any information inputted into the computer. 3 4 46 44 p /p15. feature that duplicates text from one location and places it in another.
Answers: 2
You know the right answer?
The Distance class will represent a distance in some number of feet and inches. This Distance object...
Questions
question
Spanish, 09.02.2021 17:30
question
Mathematics, 09.02.2021 17:30
Questions on the website: 13722367