AssoAndrea

ESERCIZIO

Nov 12th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 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 esercitazione_Switch_Enum
  8. {
  9. enum ShapeType { Square=1, Triangle, Rectangle}
  10.  
  11. class Program
  12. {
  13. #region Testo Esercizio
  14. // Esercizio:
  15. //Create il seguente enum con questi valori:
  16. //ShapeType: Square, Triangle, Rectangle
  17.  
  18. //Scrivete questi 3 metodi.Il primo stampa una di queste 3 figure in base all'agomento passato
  19. //PrintShape(ShapeType t)
  20.  
  21. //Square
  22. //***
  23.  
  24. //***
  25.  
  26. //Triangle
  27.  
  28. //*
  29.  
  30. //**
  31.  
  32. //***
  33.  
  34. //Rectangle
  35.  
  36. //****
  37.  
  38. //****
  39.  
  40. //Gli altri 2 sono overloading del primo e lo richiamano "convertendo" quello che gli passate in ShapeType:
  41. //PrintShape(int t) //2
  42.  
  43. //PrintShape(string shapeName) //"rect"
  44. #endregion
  45.  
  46. static void PrintChar(int n, char car)
  47. {
  48. for (int i = 0; i < n; i++)
  49. {
  50. Console.Write(car);
  51. }
  52. }
  53. static void PrintCharAndSpace(int lato, int h, char c)
  54. {
  55. for (int i = 0; i < h-2; i++)
  56. {
  57. Console.WriteLine("\n");
  58. PrintChar(1, c);
  59. PrintChar(lato - 2, ' ');
  60. PrintChar(1, c);
  61. ;
  62. }
  63. Console.WriteLine("\n");
  64. }
  65. static void PrintSquare()
  66. {
  67. PrintRect(10, 4);
  68.  
  69. }
  70. static void PrintRect(int lato=14, int altezza=3)
  71. {
  72. PrintChar(lato, '*');
  73. PrintCharAndSpace(lato, altezza, '*');
  74. PrintChar(lato, '*');
  75.  
  76. }
  77. static void PrintAngle()
  78. {
  79. int altezza = 5;
  80. for (int i = 1; i <= altezza; i++)
  81. {
  82. PrintChar(i, '*');
  83. Console.WriteLine("");
  84. }
  85.  
  86. }
  87. static void PrintShape(ShapeType Shape)
  88. {
  89. switch (Shape)
  90. {
  91. case ShapeType.Square:
  92. PrintSquare();
  93. break;
  94. case ShapeType.Triangle:
  95. PrintAngle();
  96. break;
  97. case ShapeType.Rectangle:
  98. PrintRect();
  99. break;
  100. }
  101. }
  102. static void PrintShape(int choice)
  103. {
  104. ShapeType Shape = (ShapeType)choice;
  105. PrintShape(Shape);
  106.  
  107. }
  108. static void PrintShape(string choice)
  109. {
  110. ShapeType Shape=0;
  111. switch (choice)
  112. {
  113. case "Quadrato":
  114. Shape = ShapeType.Square;
  115. break;
  116. case "Triangolo":
  117. Shape = ShapeType.Triangle;
  118. break;
  119. case "Rettangolo":
  120. Shape = ShapeType.Rectangle;
  121. break;
  122. }
  123. PrintShape(Shape);
  124. }
  125. static void Main(string[] args)
  126. {
  127.  
  128. Console.WriteLine("Che figura vuoi stampare?: \n1)Quadrato \n2)Triangolo \n3)Rettangolo");
  129. string choice = Console.ReadLine();
  130. switch (choice)
  131. {
  132. case "1":
  133. case "2":
  134. case "3":
  135. PrintShape(int.Parse(choice));
  136. break;
  137. default:
  138. PrintShape(choice);
  139. break;
  140. }
  141.  
  142.  
  143.  
  144.  
  145. Console.ReadLine();
  146. }
  147. }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment