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

The Main Objective is to use inheritance and method overriding. Write a C# progr

ID: 3841795 • Letter: T

Question

The Main Objective is to use inheritance and method overriding.

Write a C# program that implements the following: Create a class named Figure. a. This class is characterized by the following attributes: - A private integer attribute called length. - A private integer attribute called width. - A private integer attribute called area. b. The class Figure includes also a constructor with two arguments: The first argument is used to set the value of length The second argument is used to set the value of width The value of area is set-in by the following formula: (area = length * width.) c. Overload the operator + to add two Figures as follows: - Newlength= 2*length of Figure 1 if length of Figure 1 is equal of length of Figure2 else Newlength=0 - New Width = 2*width of Figure1 if Width of Figure1 is equal of Width of Figure 2 else Newlength=0 d. The class Figure includes also a method PrintInformation to Display all information about a Figure. The main method of your program, implements the following: - Creates an object Figure1. The values of its different attributes are as follows: length = 10, width=20 - Creates an object Figure2. The values of its different attributes are as follow s: length = 20, width = 30 - Creates an object Figure3=Figure1 + Figure2. - Displays information of Figure1; - Displays information of Figure2; - Displays information of Figure3: The program result looks like the following:

Explanation / Answer

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

namespace CheggOperatorOverloading1
{
class Figure
{
int length, width, area;
public Figure(){ }
public Figure(int len,int wid)
{
length = len;
width = wid;
}
public void PrintInformation()
{
area = length * width;
Console.WriteLine("Figure, "+"Length = "+length+","+"Width = "+width+","+"Area = "+area );
}

public static Figure operator +(Figure Figure1, Figure Figure2)
{
Figure NewLength= new Figure();
Figure NewWidth= new Figure();
if (Figure1.length != Figure2.length)
{
NewLength.length = 2 * Figure1.length;
return NewLength;
}
else if (Figure1.width == Figure2.width)
{
NewWidth.width = 2 * Figure1.width;
return NewWidth;
}
else if (Figure1.length == Figure2.length)
{
NewLength.length = Figure1.length + Figure2.length;
return NewLength;
}
else if (Figure1.width != Figure2.width)
{
NewWidth.width =2* Figure1.width +Figure2.width ;
return NewWidth;
}
else
{
NewLength.length = 0;
return NewLength;
}

}

}
class Program
{
static void Main(string[] args)
{
Figure Figure3 = new Figure();
Figure Figure1=new Figure (10,20);
Figure Figure2 = new Figure(20,30);

Figure1.PrintInformation();

Figure2.PrintInformation();

Figure3 = Figure1 + Figure2;
Figure3.PrintInformation();   
Console.ReadKey();
}
}
}

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