The imperial system of measurements

Assignment Help C/C++ Programming
Reference no: EM13165681

The Imperial system of measurements uses feet and inches for length, where 1 foot is equal to 12 inches. Write
a class named Imperial that will represent distance measurements in feet and inches. Your class should
include the following:
Attributes:
• A single private integer value that will maintain the measurement in units of 1/16 of an inch

Constructors:

  • The default constructor should initialize the value to zero

• A constructor that will take a single integer argument representing a whole number of feet
• A constructor that will take two integer arguments representing feet and inches respectively
• A constructor that will take three integer arguments representing feet, inches and inch-fractions

Methods:
• fp: will take no arguments and return the number of inches as a double-precision floating-point
value
• cm: will take no arguments and return the value of the Imperial measurement in centimeters as a
double precision floating-point value
• getValue: void method that will take three reference arguments and return the feet, inches and
fractions of inches

Operators:
• Overload the << operator as a non-member friend of the class. The operator should work with any
stream and display the Imperial measurement as feet, inches and fractions of an inch as follows (all
punctuation and spaces as shown):
2' 3 5/16"
Display any non-zero fractional inch values in reduced form. i.e., 4/16 would be displayed as 1/4.
Do not display zero fractional-inch values. Do not display zero feet values.

Write a main program to test the correct operation of your class. Include the following code (at a minimum):

Imperial m1;
Imperial m2(43);
Imperial m3(0,4);
Imperial m4(1,3,6);
Imperial m5(0,0,12);
Imperial m6(4,0,5);
Imperial m7(0,3,2);
Imperial m8(12,3,0);
cout << m1 << endl;
cout << m2 << endl;
cout << m3 << endl;
cout << m4 << endl;
cout << m5 << endl;
cout << m6 << endl;
cout << m7 << endl;
cout << m8 << endl;
int feet, inches, fractions;
m4.getValue(feet,inches,fractions);
cout << feet << ',' << inches << ',' << fractions << endl;
cout << m5.fp() << endl;
cout << m4.cm() << endl;

Example output:
0"
43' 0"
4"
1' 3 3/8"
3/4"
4' 5/16"
3 1/8"
12' 3"
1,3,6
0.75
39.0525

Reference no: EM13165681

Questions Cloud

Search for the value needle in the array : Search for the value needle in the array range given by [hay_begin ... hay_end), using the Linear Search algorithm. This function will return a pointer to the needle value if it is found, or a null pointer if needle is not found.
A java program where the user designates : a java program where the user designates how many games they would like to play (for example user inputs 10 games) then they play the game, if lets say there is a tie after 10 games the game continues until either the user of the computer wins by 2
What happens when you assign : What happens when you assign 340,282,343,598.33 to a Single variable? Assuming that the variable in question is named sngNumber and you execute the statement MessageBox.Show
Supposed to swap numbers : The program is supposed to swap numbers, but I am stuck something is wrong! It does not swap them it repeats the second number, please help to fix! Thanks, this is in C++.
The imperial system of measurements : The Imperial system of measurements uses feet and inches for length, where 1 foot is equal to 12 inches. Write a class named Imperial that will represent distance measurements in feet and inches. Your class should include the following.
What do the loops print : What do the following loops print? Work out the answer by tracing the code, not by using the computer. a. int s = 1; for (int n = 1; n
The ieee 754 single precision binary representation : What would be the IEEE 754 single precision binary representation of the floating point value -314159265. 3589 ? Express your final answer as an 8-hex-digit number and explain how your answer was obtained for full credit.
Child process to take the role of the number guesser : Write a program in C that takes a number between 1 and 1024 as input on the command line, and then forks a child process to take the role of the number guesser
Assume that a student table in a university : Assume that a student table in a university database has an index on StudentID (the primary key). and additional indexes on Major, Age, Marital status, and HomeZipCode.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Program that uses an instance of the timeoff

Write a program that uses an instance of the TimeOff class you designed in Programming Challenge 5. The program should ask the user to enter the number of months an employee has worked for the company. It should then use the TimeOff object to calc..

  Write the code

Write a program that allows an instructor to keep a grade book. Each students has scores for exams, homework assignments, and quizzes.

  Using an abstract class with only pure virtual functions

Using an abstract class with only pure virtual functions, create three small classes unrelated by inheritance---clases Building, Car and Bicycle. Give each class some uique appropriate attributes and behaviors that it does not have in common with oth..

  Reads from the external file input.txt

Program that reads from the external file input.txt, counts the letters in every word, replaces the word by that number, and then writes the numbers to an external file output.tx

  The factorial of a positive integer n, denoted by n!

Write a program that computes the sequence of factorial values: 1! = 1, 2! = 2, 3! = 6, 4! = 24, 5! = 120, 6! = 720, ....

  Make 2-dimensional array

make 2-dimensional array a bit of life and bringing them from the abstract to the concrete realms

  A linked list of your song structure in cd

The CD object should have a data member that is a linked list of your song structure that you have in CD.  The CD class needs a function that allows it to add a song to the object, that function would then append the song to that instance of the link..

  Difference between a constant pointer

Explain the difference between a constant pointer to non-constant data and a non-constant pointer to constant data. Show the syntax to declare them.

  C program to randomly generate more than ten ip address

Write C or C++ program which Randomly generates more than 10 IP addresses written in decimal format and write results in text file (e.g. Dec_IPAddresses.txt)

  Change temperature fahrenheit to celsius and kelvin

Write a program in c++ that takes the temperature in Fahrenheit and convert it to Celsius And Kelvin:

  Write a pseudocode statement

Assume that a program has two string variables named str1 and str2. Write a pseudocode statement that assigns an all uppercase version of str1 to the str2 variable. is str.add(str1,str2) part of it?

  Reads in a list of integers

Write a program in C++ that reads in a list of integers into and array with base type int. Provide the facility to either read this array from the keyboard or from a file, at the user's option. If the user chooses file input, the program should reque..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd