Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need desperate help with this C# program. I\'m trying to return a method to a

ID: 3765319 • Letter: I

Question

I need desperate help with this C# program.
I'm trying to return a method to a method. Please Help !!!
THANKS !!!


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Lab_12_Height_2
{
class Height
{
public Height()
{
}
public Height(int Foot, int Inch)
{
this.Foot = Foot;
this.Inch = Inch;
return;
}
  
public Height(int Foot)
{
this.Foot = Foot;
}


public Height(Height myHeight1)
{
myHeight4 = myHeight4;
}


public int Foot { get; internal set; }
public int Inch { get; internal set; }
public HeightTest myHeight1 { get; internal set; }
public HeightTest myHeight4 { get; internal set; }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


public class HeightTest
{
static void Main(string[] args)
{
Height myHeight1 = new Height(5, 7);
Console.WriteLine("My height 1: {0} ft. {1} in.", myHeight1.Foot, myHeight1.Inch);
Height myHeight2 = new Height(5);
Console.WriteLine("My height 2: {0} ft. {1} in.", myHeight2.Foot, myHeight2.Inch);
Height myHeight3 = new Height();
Console.WriteLine("My height 3: {0} ft. {1} in.", myHeight3.Foot, myHeight3.Inch);
Height myHeight4 = new Height(myHeight1);
Console.WriteLine("My height 4: {0} ft. {1} in.", myHeight4.Foot, myHeight4.Inch);

Console.WriteLine("Press any key to continue. . .");
Console.ReadKey();
}
}
}

*** My Output ***

My height 1: 5 ft. 7 in.
My height 2: 5 ft. 0 in.
My height 3: 0 ft. 0 in.
My height 4: 0 ft. 0 in.
Press any key to continue . . .

*** Expected output ***

My height 1: 5 ft. 7 in.
My height 2: 5 ft. 0 in.
My height 3: 0 ft. 0 in.
My height 4: 5 ft. 7 in.
Press any key to continue . . .

Explanation / Answer

Error in the constructor

public Height(Height myHeight1)
{
myHeight4 = myHeight4;
}

Change it to


        public Height(Height myHeight1)
        {
            this.Foot = myHeight1.Foot;
            this.Inch = myHeight1.Inch;
        }

------output-----

My height 1: 5 ft. 7 in.
My height 2: 5 ft. 0 in.
My height 3: 0 ft. 0 in.
My height 4: 5 ft. 7 in.
Press any key to continue. . .

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote