Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- convertTemperature (TempScale.CELSIUS, TempScale.FAHRENHEIT, 22)
- enum Conversion
- {
- CelsiusToFahrenheit,
- FahrenheitToCelsius,
- KilosToPounds
- }
- Convert(Conversion conversion, X from);
- enum Units
- {
- Pounds,
- Kilos,
- Celcius,
- Farenheight
- }
- Convert(Unit from, Unit to, X fromAmount);
- Convert(Pounds, Celcius, 5, 10);
- public void ConvertTemperature(TemperatureTypeEnum SourceTemp,
- TemperatureTypeEnum TargetTemp,
- decimal Temperature)
- {}
- interface ITemperature
- {
- CelciusTemperature ToCelcius();
- FarenheitTemperature ToFarenheit();
- }
- struct FarenheitTemperature : ITemperature
- {
- public readonly int Value;
- public FarenheitTemperature(int value)
- {
- this.Value = value;
- }
- public FarenheitTemperature ToFarenheit() { return this; }
- public CelciusTemperature ToCelcius()
- {
- return new CelciusTemperature((this.Value - 32) * 5 / 9);
- }
- }
- struct CelciusTemperature
- {
- public readonly int Value;
- public CelciusTemperature(int value)
- {
- this.Value = value;
- }
- public CelciusTemperature ToCelcius() { return this; }
- public FarenheitTemperature ToFarenheit()
- {
- return new FarenheitTemperature(this.Value * 9 / 5 + 32);
- }
- }
- // Freezing
- Debug.Assert(new FarenheitTemperature(32).ToCelcius().Equals(new CelciusTemperature(0)));
- Debug.Assert(new CelciusTemperature(0).ToFarenheit().Equals(new FarenheitTemperature(32)));
- // crossover
- Debug.Assert(new FarenheitTemperature(-40).ToCelcius().Equals(new CelciusTemperature(-40)));
- Debug.Assert(new CelciusTemperature(-40).ToFarenheit().Equals(new FarenheitTemperature(-40)));
- CelciusTemperature theOutbackInAMidnightOilSong = new CelciusTemperature(45);
- FarenheitTemperature x = theOutbackInAMidnightOilSong; // ERROR: Cannot implicitly convert type 'CelciusTemperature' to 'FarenheitTemperature'
- float LinearConvert(float in, float scale, float add, bool invert);
- public class Temperature
- {
- private double celcius;
- public static Temperature FromFarenheit(double farenheit)
- {
- return new Temperature { Farhenheit = farenheit };
- }
- public static Temperature FromCelcius(double celcius)
- {
- return new Temperature { Celcius = celcius };
- }
- public static Temperature FromKelvin(double kelvin)
- {
- return new Temperature { Kelvin = kelvin };
- }
- private double kelvinToCelcius(double kelvin)
- {
- return 1; // insert formula here
- }
- private double celciusToKelvin(double celcius)
- {
- return 1; // insert formula here
- }
- private double farhenheitToCelcius(double farhenheit)
- {
- return 1; // insert formula here
- }
- private double celciusToFarenheit(double kelvin)
- {
- return 1; // insert formula here
- }
- public double Kelvin
- {
- get { return celciusToKelvin(celcius); }
- set { celcius = kelvinToCelcius(value); }
- }
- public double Celcius
- {
- get { return celcius; }
- set { celcius = value; }
- }
- public double Farhenheit
- {
- get { return celciusToFarenheit(celcius); }
- set { celcius = farhenheitToCelcius(value); }
- }
- }
- $ units 'tempF(-40)' tempC
- -40
- use Convert::Temperature;
- my $c = new Convert::Temperature();
- my $res = $c->from_fahr_to_cel('59');
- double fahrtocel(double tempF){
- return ((tempF-32)*(5/9));
- }
- double celtofahr(double tempC){
- return ((9/5)*tempC + 32);
- }
- function Temperature($value, $input, $output)
- {
- $value = floatval($value);
- if (isset($input, $output) === true)
- {
- switch ($input)
- {
- case 'K': $value = $value - 273.15; break; // Kelvin
- case 'F': $value = ($value - 32) * (5 / 9); break; // Fahrenheit
- case 'R': $value = ($value - 491.67) * (5 / 9); break; // Rankine
- }
- switch ($output)
- {
- case 'K': $value = $value + 273.15; break; // Kelvin
- case 'F': $value = $value * (9 / 5) + 32; break; // Fahrenheit
- case 'R': $value = ($value + 273.15) * (9 / 5); break; // Rankine
- }
- }
- return $value;
- }
Add Comment
Please, Sign In to add comment