Advertisement
fcamuso

Untitled

Aug 18th, 2020
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 KB | None | 0 0
  1. using System;
  2.  
  3. namespace OOP5_Cerchio
  4. {
  5.  
  6.   class Punto
  7.   {
  8.     public double X { get; set; } = 0;
  9.     public double Y { get; set; } = 0;
  10.  
  11.     public Punto( double x, double y) { X = x; Y = y; }
  12.   }
  13.  
  14.   class Cerchio
  15.   {
  16.  
  17.     public Punto Centro { get; set; } = new Punto(0, 0);
  18.     public int Colore { get; set; } = 0; //default = nero
  19.     public int Spessore { get; set; } = 1;
  20.  
  21.     private double raggio = 1;
  22.     public double Raggio {
  23.       get => raggio;
  24.       set {
  25.         if (value > 0)
  26.           raggio = value;
  27.         else
  28.           throw new ArgumentOutOfRangeException("Il raggio deve essere maggiore di zero");
  29.       }
  30.     }
  31.  
  32.     public Cerchio(double x, double y, double r)
  33.     {
  34.       Centro = new Punto(x, y);
  35.       Raggio = r;
  36.     }
  37.  
  38.     public Cerchio() { }
  39.  
  40.     public double Perimetro() { return 2 * Math.PI * raggio; }
  41.     public double Area() { return Math.PI * raggio * raggio; } // o * Math.Pow(raggio,2)
  42.          
  43.   }
  44.   class Program
  45.   {
  46.     static void Main(string[] args)
  47.     {
  48.       Cerchio c1 = new Cerchio(3, -2, 4) {Colore = 0x0000FF, Spessore = 2 };
  49.       Cerchio c1bis = new Cerchio ( x: 3, y:-2, r: 4) {Colore = 0x0000FF, Spessore = 2 };
  50.       Cerchio c2 = new Cerchio() { Centro=new Punto(3, -2), Raggio=4, Colore = 0x0000FF, Spessore = 2 };
  51.      
  52.       Console.WriteLine($"Perimetro di c1={c1.Perimetro()}, area di c2={c2.Area()}");
  53.  
  54.       Punto x1 = new Punto(3, 8);
  55.       Cerchio c3 = new Cerchio(x1.X, x1.Y, 4);
  56.       //Cerchio c4 = new Cerchio(x1, 4);
  57.  
  58.     }
  59.   }
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement