代写C基础作业，使用Object Oriented Programming的思想，实现一个简易转换器。
Write a C17 (not C++) console application that converts distances to its equivalents in metric and imperial measure.
Your program should prompt the user to enter a number followed by a unit type. The program then prints out the distance in metres, followed by a table of the equivalent distances in metric and imperial units.
Only one input line! Do not prompt for the number and unit type with separate prompts. Use a single input line.
- 22 km
- 12 hands
- 26 nautical miles
- 42 Gm
- 34 nanometres
You must code your solution with the following restrictions:
- The source code, must be C, not C++.
- Must compile in Microsoft Visual C with /std:c17
- You must submit a complete Visual Studio 2019 or later solution (ZIPPED).
- Output messages should match the order and content of the demo program precisely.
- The executable file must be named ‘distances.exe’
- Do not worry about input overflow (numbers that are too large), that is an issue beyond the scope of this project.
Follow the input-compute-output pattern.
- the number representing the distance
- the name of the specified units
We will use a concept from mathematics called normalization, where the input value is normalized to a common unit, then the output is generated from the normalized unit. For example, a conversion from centimetres to inches would normalize centimetres to metres (the basic unit of metric measurement), then convert from metres to inches. 33 centimetres 0.33 metres 0.33 0.0254 = 12.992 inches.
A table of SI units (metric) and their equivalent imperial units.
Don’t code straight to the final program - work your way there in steps. Here is a development plan you can try:
- Read a real number and a single word. Output that number and that word. Test to see that it accepts fractions (e.g., 3.5, 42.1, 3.0, etc.)
- Output the correct number of metres for that input number and single-word type. Test every conversion - with and without fractions. What are your test values? Pick boundary values like 1 ym, 1 Ym, 4.2 twips, etc.
- Output the table of conversions. Test again with your same values.
- Align the output columns.
- Make the input case insensitive (input can be upper or lower case, or any mix), but only for imperial unit names.
- Allow units to be plurals. (e.g., yards, inches, feet, metres)
- Allow units for inches or feet to be the symbols
- Check for non-numeric input (report, then quit if found).
- Check for no matching unit type (e.g., ‘10 kg’ should produce an error, then quit).
- Handle the multiple word types.
- Handles any amount of whitespace in between the words.
- Correct the output so that numbers greater than 1012 or less than 1012 are printed in scientific notation with 6 digits of accuracy, otherwise with 3 decimal places.
NOTICE! All of the features of one difficulty level must be completed before we mark the next group (i.e., we will not mark yellow features, if the green features are incomplete.
- Prompt displayed
- Input is on a single line
- Accepts real numbers
- Conversion to metres is correct
- Metric table values are correct
- Imperial table values are correct
- Units are displayed in the correct order
- Table outputs in two columns
- Input is case insensitive
- Plurals are correctly handled
- Reports non-numeric input and quits.
- Switches between scientific and fixed notation correctly.
- Reports no matching unit type
- Handles multi-word types (between the number and the newline)
- Handles any number of whitespaces in between the words (not \n)
- Non-functional code requirements
- Indentifying the correct unit type is not just a great, big, ‘if’ statement.
- Output table is not just a great, big, ‘if’ statement.
- Non-functional requirements
- Visual Studio project doesn’t generate a program named ‘distances.exe’
- Doesn’t compile as a Visual Studio C project
- Penalties from C & C++ Grading Guide v2.3.0
- Late submission (days)
- Submit entire Visual Studio project directory to Fanshawe Online
- a. Delete all debug and release directories.
- b. Submit in a .ZIP, .7z archive file.