Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This programming project will allow the user to create a table of unit conversions, where the user specifies: ? the dimension (example: length) ? the

This programming project will allow the user to create a table of unit conversions, where the user

specifies:

? the dimension (example: length)

? the starting unit (example: ft)

? ending unit (example: m)

? the starting value (example: 0)

? the ending value (example: 10)

? the increment (1)

? the number of digits after the decimal point for the starting unit (example: 1)

? the number of digits after the decimal point for the ending unit (example: 3)

For the example above, the output might be similar to the table shown below:

Length (ft) Length (m)

0.0 0.000

1.0 0.305

2.0 0.610

3.0 0.914

4.0 1.219

5.0 1.524

6.0 1.829

7.0 2.134

8.0 2.438

9.0 2.743

10.0 3.048

Program Requirements:

1. The program should provide an initial description.

2. The user should be prompted to enter the dimension (length, mass, or time).

3. The user should be given a choice of initial units and final units for each dimension as

follows:

? Length: m, ft, cm or in

? Mass: kg, g or slug

? Time: h, min or s

Note that the initial unit cannot be the same as the final unit, but there are still many possible

conversions. For example, with length there are 12 possible conversions

m to ft ft to m cm to m in to m

m to cm ft to cm cm to ft in to ft

m to in ft to in cm to in in to cm

Similarly, there are multiple conversion possibilities for mass and time.

4. The units should be read as strings and any combination of uppercase and lowercase letters

can be used. The user should be able to use the full unit name (plural or singular) or the

symbol (for example, meters, meter or m). Use a function to convert the input unit to all

lowercase letters. Only the unit symbol should be used in the table.

5. There are many sources for conversion factors. Use the conversion factors in the unit

conversion program Digital Dutch (https://www.digitaldutch.com/unitconverter/length.htm).

An example is shown below. If a value of 1 ft is entered and converted to m, we see that the

conversion factor is 0.3048.

6. The table should include a heading with the dimension name and the units. The number of

digits displayed must match the users specifications. The table should be right justified and

all decimal points should be aligned. See the sample table on the previous page.

7. The program should calculate the number of lines in the table based on the user inputs

specifying starting value, ending value and increment. The number of lines in the table must

be at least 3, but not more than 25. If the ending value is not a multiple of the increment, the

table should end with the last possible value before the ending value specified. For example,

if the user specifies the following value:

Starting value: 10

Ending value: 100

Increment: 20

The program should determine that 5 lines are needed and that the last value in the table

should be 90 (not 110).

8. Use loops allow the user to correct any bad inputs (and provide a suitable error message). Bad

inputs should include:

? Choice of dimension (length, mass or time)

? Choice of units (with correct spelling) for each dimension

? Starting and ending unit cannot be the same

? Number of digits > 0

? Starting value, increment and ending value must all be positive.

? Number of lines in the table must be from 3 to 25. If this condition fails, the user should

re-enter the starting value, increment and ending value.

9. Efficiency: The program must be efficient or else it could become exceeding long and

significant grade penalties will apply. For example, a poorly written program might repeat the

code for generating a table dozens of times for the many possible conversions. An efficient

program would only have one set of instructions to generate a table and the table would use

the assigned values for dimension, units, digits, starting value, etc.

10. Give the user the option of re-running the program (use a do while loop).

11. The program should use at least 3 functions, including:

a. Function to convert a string to all lower case.

b. Function that returns the appropriate conversion factor based on the starting unit and

ending unit.

c. Function of your choice (it must be useful and well-designed).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions