Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ИЗЧЕРТАВАНЕ НА ПРАВОЪГЪЛНИК И ТРИЪГЪЛНИК СЪС ЗВЕЗДИЧКА
- //ИНТЕРФЕЙС DRAWABLE:
- public interface Drawable
- {
- void Draw();
- }
- //КЛАС RECTANGLE:
- public class Rectangle : Drawable
- {
- private int Width;
- private int Height;
- public Rectangle(int Width, int Height)
- {
- this.Width = Width;
- this.Height = Height;
- }
- public void Draw()
- {
- DrawLine(this.Width, '*', '*');
- for (int i = 1; i < this.Height - 1; ++i)
- DrawLine(this.Width, '*', ' ');
- DrawLine(this.Width, '*', '*');
- }
- private void DrawLine(int width, char end, char mid)
- {
- Console.Write(end);
- for (int i = 1; i < width - 1; ++i)
- Console.Write(mid);
- Console.WriteLine(end);
- }
- }
- //КЛАС TRIANGLE:
- public class Triangle : Drawable
- {
- private int Side;
- public Triangle(int Side)
- {
- this.Side = Side;
- }
- public void Draw()
- {
- for (var row = 1; row <= this.Side; row++)
- {
- Console.Write("*");
- for (var col = 1; col < row; col++)
- {
- Console.Write(" *");
- }
- Console.WriteLine();
- }
- }
- }
- //ГЛАВНА ПРОГРАМА:
- public class Program
- {
- static void Main(string[] args)
- {
- Drawable rect = new Rectangle(5,10);
- Console.WriteLine("Drawing rectangle like this:");
- rect.Draw();
- Drawable tr = new Triangle(5);
- Console.WriteLine("Drawing triangle like this:");
- tr.Draw();
- }
- }
- //РЕЗУЛТАТ:
- Drawing rectangle like this:
- *****
- * *
- * *
- * *
- * *
- * *
- * *
- * *
- * *
- *****
- Drawing triangle like this:
- *
- * *
- * * *
- * * * *
- * * * * *
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement