Question: C#. For this task you are asked to create a number of conversion classes, all of which inherit from the provided abstract class Converter. This
C#. For this task you are asked to create a number of conversion classes, all of which inherit from the providedabstract class Converter. This allows our menu-based conversion program to be effortlessly extended to support different conversions with minimal extra code. You must use the sample code provided.
The public classes you have to write for this exercise are:
MetresToCentimetres (centimetres = 100 * metres)
CelsiusToFahrenheit (fahrenheit = celsius * 9 / 5 + 32)
MilesToKilometres (kilometres = miles * 1.609344)
DegreesToRadians (radians = degrees * Math.PI / 180)
Each of these classes must inherit from the provided Converter class and override its three methods. See the Week 8 lecture for more information on inheritance and overriding.
The three methods you will need to override are:
string From()
This method returns a string indicating the unit this converter converts from. For example, the MetresToCentimetres class will return "Metres".
string To()
This method returns a string indicating the unit this converter converts to. For example, the MetresToCentimetres class will return "Centimetres".
float Convert(float value)
This method converts 'value' to whatever this converter converts things to and returns the result. For example:
Converter converter = new MetresToCentimeters(); Console.WriteLine("1 metre in centimetres is {0}", converter.Convert(1)); will print "1 metre in centimetres is 100".
A Main() method is provided to show an example of a menu-based converter. Note that part of the code is commented out:
// Uncomment these to test out new classes as you implement them //converters.Add(new MetresToCentimetres()); //converters.Add(new CelsiusToFahrenheit()); //converters.Add(new MilesToKilometres()); //converters.Add(new DegreesToRadians());
When you write a new conversion class, you can them uncomment the line for that class and it will be added to the menu. When all 4 are uncommented, the program should look like this:
Conversion Menu -------------------
1. Metres to Centimetres 2. Celsius to Fahrenheit 3. Miles to Kilometres 4. Degrees to Radians
Choose a converter (or type 0 to exit): 1 Converting from Metres to Centimetres
Enter input (Metres): 1 Result (Centimetres): 100
Conversion Menu -------------------
1. Metres to Centimetres 2. Celsius to Fahrenheit 3. Miles to Kilometres 4. Degrees to Radians
Choose a converter (or type 0 to exit): 2 Converting from Celsius to Fahrenheit
Enter input (Celsius): 50 Result (Fahrenheit): 106
Conversion Menu -------------------
1. Metres to Centimetres 2. Celsius to Fahrenheit 3. Miles to Kilometres 4. Degrees to Radians
Choose a converter (or type 0 to exit): 3 Converting from Miles to Kilometres
Enter input (Miles): 6000 Result (Kilometres): 9656.064
Conversion Menu -------------------
1. Metres to Centimetres 2. Celsius to Fahrenheit 3. Miles to Kilometres 4. Degrees to Radians
Choose a converter (or type 0 to exit): 4 Converting from Degrees to Radians
Enter input (Degrees): 360 Result (Radians): 6.283185
Conversion Menu -------------------
1. Metres to Centimetres 2. Celsius to Fahrenheit 3. Miles to Kilometres 4. Degrees to Radians
Choose a converter (or type 0 to exit):
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
