Question: Create a Shape class with the following properties: Top, Left, Width, Height, and Color. The Color must be of type ConsoleColor while the others are

Create a Shape class with the following properties: Top, Left, Width, Height, and Color.

The Color must be of type ConsoleColor while the others are all integers. Make sure the integers are all >= 0 and < Console.WindowHeight or Console.WindowWidth (pick the appropriate one for the property). Make a constructor that takes values for all the properties in the order show above. In addition, make an abstract Draw method.

Create two additional classes: Rectangle, and a Triangle. These classes must each inherit from Shape and implement the Draw method. The Triangle class must have the same size width and height so make its constructor accept a single integer for size (e.g. not a Width and Height).

The Triangle class draws a right triangle. Example: Triangle of size 5

*

**

***

****

*****

You may need to use properties and methods from the Console class: https://msdn.microsoft.com/en-us/library/system.console

CursorLeft: Gets or sets the column position of the cursor within the buffer area.

CursorTop: Gets or sets the row position of the cursor within the buffer area.

ForegroundColor: Gets or sets the foreground color of the console.

Also Write, WriteLine, Clear

Add the following class to your project then test all the classes in main:

 public class Circle : Shape { private int mRadius; public int Radius { get { return mRadius; } set { if (value >= 0) mRadius = value; else throw new Exception("Radius must be >= 0"); } } public Circle(int CenterX, int CenterY, int aRadius, ConsoleColor aColor) : base(CenterY - aRadius, CenterX - aRadius, 2 * aRadius, 2 * aRadius, aColor) { Radius = aRadius; } public override void Draw() { Console.CursorTop = Top; // Top half of circle for (int i = 2; i <= Width; i = i + 2) { Console.CursorLeft = Left; for (int col = 0; col < (Width - i) / 2; col++) Console.CursorLeft++; for (int col = 0; col < i; col++) Console.Write(""); Console.WriteLine(); } // Bottom half of circle for (int i = Width; i >= 2; i = i - 2) { Console.CursorLeft = Left; // draw spaces for (int col = 0; col < (Width - i) / 2; col++) Console.CursorLeft++; // draw blocks for (int col = 0; col < i; col++) Console.Write(""); Console.WriteLine(); } } } 

http://puu.sh/y21ko/86f6f8c221.png

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!