Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago