Here is the main program:
/*This is a console application to introduction to classes. Every program requires a heading, which is below. The fields will vary according to the class or organization you are creating this program. For this class we will use temperature conversions.
What is a variable? Think of a variable as a container that holds items.
Program: Introduction to Classes
Programmer: Mike Kniaziewicz
Date: February 26, 2012
Version: 1.0.0 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Temperature_Class
{
class Program
{
static void Main(string[] args)
{
/*This is where you declare variables to be used I generally place the first letter of the variable type before the variable for readability in the Main function. Here are the formulas we will be using:
C = (F 32) * 5/9
F = C * 9/5 + 32*/
Console.WriteLine(“Enter a temperature in Fahrenheit to convert to Celcius:”);
Class1 fahrenheit = new Class1();
fahrenheit.Sfahrenheit = Console.ReadLine();
Console.WriteLine(“The Fahrenheit you entered is {0} and the degrees in Celsius are {1:F1}”, fahrenheit.Sfahrenheit, fahrenheit.fahrenheit(fahrenheit.Sfahrenheit));
Console.WriteLine(“Enter a temperature in Celcius to convert to Fahrenheit:”);
Class1 celcius = new Class1();
celcius.Scelcius = Console.ReadLine();
Console.WriteLine(“The Celcius you entered is: {0} and the degrees in Fahrenheit are {1:F1} “, celcius.Scelcius,celcius.celcius(celcius.Scelcius) );
Console.ReadKey();
}
}
}
Here is the Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Temperature_Class
{
class Class1
{
public double dfahrenheit, dcelcius;
public string scelcius, sfahrenheit;
public string Scelcius
{
get
{
return scelcius;
}
set
{
scelcius = value;
}
}
public string Sfahrenheit
{
get
{
return sfahrenheit;
}
set
{
sfahrenheit = value;
}
}
//Constructor
public double fahrenheit(string sfahrenheit)
{
dfahrenheit = double.Parse(sfahrenheit);
dcelcius = (dfahrenheit – 32) * 5 / 9 ;
return dcelcius;
}
public double celcius( string scelcius)
{
dcelcius = double.Parse(scelcius);>
dfahrenheit = dcelcius * 9 / 5 + 32;
return dfahrenheit;
}
}
}