Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace esercizio_enum
  8. {
  9.     enum ShapeType { Square, Triangle, Rectangle, Last }
  10.     class Program
  11.     {
  12.  
  13.  
  14.  
  15.  
  16.         static void PrintShape(ShapeType t)
  17.         {
  18.             int height;
  19.             int width;
  20.             switch (t)
  21.             {
  22.                 case ShapeType.Square:
  23.                     width = 3;
  24.                     height = 2;
  25.                     PrintRect(height, width);
  26.                     break;
  27.                 case ShapeType.Triangle:
  28.                     height = 3;
  29.                     PrintTriangle(height);
  30.                     break;
  31.                 case ShapeType.Rectangle:
  32.                     width = 4;
  33.                     height = 2;
  34.                     PrintRect(height, width);
  35.                     break;
  36.             }
  37.  
  38.         }
  39.  
  40.         static void PrintShape(int t)
  41.         {
  42.             int height;
  43.             int width;
  44.             switch (t)
  45.             {
  46.                 case 0:
  47.                     width = 3;
  48.                     height = 2;
  49.                     PrintRect(height, width);
  50.                     Console.WriteLine("test se funziona conversione");
  51.                     break;
  52.                 case 1:
  53.                     height = 3;
  54.                     PrintTriangle(height);
  55.                     Console.WriteLine("test se funziona conversione");
  56.                     break;
  57.                 case 2:
  58.                     width = 4;
  59.                     height = 2;
  60.                     PrintRect(height, width);
  61.                     Console.WriteLine("test se funziona conversione");
  62.                     break;
  63.             }
  64.  
  65.         }
  66.  
  67.         static void PrintShape(string shape)
  68.         {
  69.             int height;
  70.             int width;
  71.  
  72.             switch (shape.ToLower())
  73.             {
  74.                 case "square":
  75.                     width = 3;
  76.                     height = 2;
  77.                     PrintRect(height, width);
  78.                     break;
  79.                 case "triangle":
  80.                     height = 3;
  81.                     PrintTriangle(height);
  82.                     break;
  83.                 case "rectangle":
  84.                     width = 4;
  85.                     height = 2;
  86.                     PrintRect(height, width);
  87.                     break;
  88.             }
  89.  
  90.         }
  91.  
  92.         static void PrintAst(int n)
  93.         {
  94.             for (int i = 0; i < n; i++)
  95.             {
  96.                 Console.Write("*");
  97.             }
  98.         }
  99.  
  100.         static void PrintTriangle(int width)
  101.         {
  102.             for (int i = 1; i <= width; i++)
  103.             {
  104.                 PrintAst(i);
  105.                 Console.WriteLine("\n");
  106.             }
  107.         }
  108.  
  109.         static void PrintSquare(int width)
  110.         {
  111.             PrintRect(width, width);
  112.         }
  113.         static void PrintRect(int height, int width)
  114.         {
  115.             for (int i = 0; i < height; i++)
  116.             {
  117.                 PrintAst(width);
  118.                 Console.WriteLine("\n");
  119.             }
  120.         }
  121.  
  122.         static void Main(string[] args)
  123.         {
  124.             //PrintRect(2, 4);
  125.             //PrintAst(3);
  126.             Console.WriteLine("Regole: Puoi digitare un numero, o il nome associato per disegnare");
  127.             Console.WriteLine("0)Square, 1)Triangle 2)Rectangle");
  128.             Console.WriteLine("cosa vuoi disegnare?");
  129.  
  130.             string a = Console.ReadLine();
  131.             int test;
  132.  
  133.             if (a.Length == 1)
  134.             {
  135.                 test = int.Parse(a);
  136.                 PrintShape(test);
  137.  
  138.             }
  139.             else
  140.             {
  141.                 PrintShape(a);
  142.             }
  143.  
  144.             //PrintShape(a);
  145.             //PrintSquare(4);
  146.  
  147.             //PrintTriangle(3);
  148.             Console.ReadLine();
  149.         }
  150.     }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement