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

Using C#,Create a class called RightTriangle that has one field named area, the

ID: 3870607 • Letter: U

Question

Using C#,Create a class called RightTriangle that has one field named area, the data type of which is double. The class RightTriangle is a derived class of the base class triangle. It has two methods. One is named RTArea which calculates the area of a right triangle. The other one is named Message that will print the value of the field area. It has two constructors. One is a paramterless constructor. When it is called, the field area is initialized in the body of the constructor by assigning a value (such as 10) to it. The other is a constructor having one parameter. When it is called, the field area is initialized by assigning the value of the parameter to it. When an instance of RightTriangle is created by calling the constructor without parameters, the instance of the base class will be created by calling the constructor that has 4 parameters. When an instance of RightTriangle is created by calling the constructor with 1 parameter, the instance of the base class will be created by calling its constructor without parameters.

Explanation / Answer

SourceCode:

using System;

public class Triangle

{

public int area{get;set;}

public static int height{get;set;}

public static int baseval{get;set;}

public Triangle()

{

  

area=10;

}

public Triangle(int area)

{

area=area;

  

}

public Triangle(int a,int b,int c,int d)

{

  

height=a;

baseval=b;

  

}

public void RTArea()

{

area=(height*baseval)/2;

  

}

public void Message()

{

Console.WriteLine("The area of the Triangle is "+area);

}

}

public class RightTriangle:Triangle

{

public RightTriangle()

{

Triangle obj=new Triangle(40,10,0,0);

}

public RightTriangle(int area)

{

Triangle obj=new Triangle();

}

}

public class Test

{

public static void Main()

{

Console.WriteLine("The Area After Calling RightTriangle without parameter");

RightTriangle obj=new RightTriangle();

obj.RTArea();

obj.Message();

Console.WriteLine("The Area After Calling RightTriangle with parameter");

RightTriangle obj1=new RightTriangle(20);

obj1.Message();

}

}

Output:

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