Create a C console application for this questionThe followin
Create a C# console application for this question.The following program defines class Height. This class has two publicly accessible instance variables foot and inch. Since there is no control on access to these variables, outside code can store any value in them. For example, we can store -8 in foot and 14 in inch as shown in the program:
// CSC153_A13P01
using System;
publicclassHeight
{
publicint foot;
publicint inch;
}
publicclassHeightTest
{
staticvoid Main(string[] args)
{
Height myHeight1 = newHeight();
myHeight1.foot = 5;
myHeight1.inch = 7;
Console.WriteLine(\"My height 1: {0} ft. {1} in.\", myHeight1.foot, myHeight1.inch);
Height myHeight2 = newHeight();
myHeight2.foot = -8;
myHeight2.inch = 14;
Console.WriteLine(\"My height 2: {0} ft. {1} in.\", myHeight2.foot, myHeight2.inch);
}
}
Output of the program above:
My height 1: 5 ft. 7 in.
My height 2: -8 ft. 14 in.
Press any key to continue . . .
Modify the program above by makingfoot and inch private. Add publicly accessible properties to get and set these instance variables. No negative value can be stored in both of these variables. Also, no value 12 or higher can be stored in inch. Also, modify the Main method of the HightTest class to access the properties instead of the instance variables.
The following is the expected output after the modifications.
My height 1: 5 ft. 7 in.
My height 2: 0 ft. 0 in.
Press any key to continue . . .
Solution
using System;
public class Height
{
//declare private variables
private int foot;
private int inch;
//to set height
public void setHeight(int f, int i )
{
//condition to check foot is positive
if (f>0)
foot= f;
else
foot= 0;
//condition to check inch is positive and less than 12
if(i>0 && i<12)
inch = i;
else
inch=0;
}
//to get foot
public int getFoot( )
{
return foot;
}
//to get inch
public int getInch( )
{
return inch;
}
}
public class HeightTest
{
static void Main(string[] args)
{
Height myHeight1 = new Height();
//to set height
myHeight1.setHeight(5,7);
//to print height
Console.WriteLine(\"My height 1: {0} ft {1} in.\",myHeight1.getFoot(),myHeight1.getInch());
Height myHeight2 = new Height();
//to set height
myHeight2.setHeight(-8,14);
//to print height
Console.WriteLine(\"My height 2: {0} ft {1} in.\", myHeight2.getFoot(),myHeight2.getInch());
}
}

