Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace esercitazione_Switch_Enum
- {
- enum ShapeType { Square=1, Triangle, Rectangle}
- class Program
- {
- #region Testo Esercizio
- // Esercizio:
- //Create il seguente enum con questi valori:
- //ShapeType: Square, Triangle, Rectangle
- //Scrivete questi 3 metodi.Il primo stampa una di queste 3 figure in base all'agomento passato
- //PrintShape(ShapeType t)
- //Square
- //***
- //***
- //Triangle
- //*
- //**
- //***
- //Rectangle
- //****
- //****
- //Gli altri 2 sono overloading del primo e lo richiamano "convertendo" quello che gli passate in ShapeType:
- //PrintShape(int t) //2
- //PrintShape(string shapeName) //"rect"
- #endregion
- static void PrintChar(int n, char car)
- {
- for (int i = 0; i < n; i++)
- {
- Console.Write(car);
- }
- }
- static void PrintCharAndSpace(int lato, int h, char c)
- {
- for (int i = 0; i < h-2; i++)
- {
- Console.WriteLine("\n");
- PrintChar(1, c);
- PrintChar(lato - 2, ' ');
- PrintChar(1, c);
- ;
- }
- Console.WriteLine("\n");
- }
- static void PrintSquare()
- {
- PrintRect(10, 4);
- }
- static void PrintRect(int lato=14, int altezza=3)
- {
- PrintChar(lato, '*');
- PrintCharAndSpace(lato, altezza, '*');
- PrintChar(lato, '*');
- }
- static void PrintAngle()
- {
- int altezza = 5;
- for (int i = 1; i <= altezza; i++)
- {
- PrintChar(i, '*');
- Console.WriteLine("");
- }
- }
- static void PrintShape(ShapeType Shape)
- {
- switch (Shape)
- {
- case ShapeType.Square:
- PrintSquare();
- break;
- case ShapeType.Triangle:
- PrintAngle();
- break;
- case ShapeType.Rectangle:
- PrintRect();
- break;
- }
- }
- static void PrintShape(int choice)
- {
- ShapeType Shape = (ShapeType)choice;
- PrintShape(Shape);
- }
- static void PrintShape(string choice)
- {
- ShapeType Shape=0;
- switch (choice)
- {
- case "Quadrato":
- Shape = ShapeType.Square;
- break;
- case "Triangolo":
- Shape = ShapeType.Triangle;
- break;
- case "Rettangolo":
- Shape = ShapeType.Rectangle;
- break;
- }
- PrintShape(Shape);
- }
- static void Main(string[] args)
- {
- Console.WriteLine("Che figura vuoi stampare?: \n1)Quadrato \n2)Triangolo \n3)Rettangolo");
- string choice = Console.ReadLine();
- switch (choice)
- {
- case "1":
- case "2":
- case "3":
- PrintShape(int.Parse(choice));
- break;
- default:
- PrintShape(choice);
- break;
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment