Advertisement
fcamuso

Untitled

Aug 22nd, 2020
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 KB | None | 0 0
  1. using System;
  2.  
  3. namespace OOP5_Cerchio
  4. {
  5.  
  6.  
  7.   class Punto
  8.   {
  9.     public double X { get; set; } = 0;
  10.     public double Y { get; set; } = 0;
  11.  
  12.     public Punto( double x, double y) { X = x; Y = y; }
  13.  
  14.     public Punto Clona()
  15.     {
  16.       return new Punto(X, Y);
  17.     }
  18.   }
  19.  
  20.   class Cerchio
  21.   {
  22.  
  23.     public Punto Centro { get; set; } = new Punto(0, 0);
  24.     public int Colore { get; set; } = 0; //default = nero
  25.     public int Spessore { get; set; } = 1;
  26.  
  27.     private double raggio = 1;
  28.     public double Raggio {
  29.       get => raggio;
  30.       set {
  31.         if (value > 0)
  32.           raggio = value;
  33.         else
  34.           throw new ArgumentOutOfRangeException("Il raggio deve essere maggiore di zero");
  35.       }
  36.     }
  37.  
  38.     public Cerchio(double x, double y, double r)
  39.     {
  40.       Centro = new Punto(x, y);
  41.       Raggio = r;
  42.     }
  43.  
  44.     public Cerchio() { }
  45.  
  46.     public Cerchio(Punto p, double r) //: this(p.X, p.Y, r) {}
  47.     {
  48.       Centro = p;
  49.       //Centro.X = 999;
  50.  
  51.       p = new Punto(777, 777);
  52.  
  53.     }
  54.    
  55.     public double Perimetro() { return 2 * Math.PI * raggio; }
  56.     public double Area() { return Math.PI * raggio * raggio; } // o * Math.Pow(raggio,2)
  57.          
  58.   }
  59.   class Program
  60.   {
  61.     static void Main(string[] args)
  62.     {
  63.       Cerchio c1 = new Cerchio(3, -2, 4) {Colore = 0x0000FF, Spessore = 2 };
  64.       Cerchio c1bis = new Cerchio ( x: 3, y:-2, r: 4) {Colore = 0x0000FF, Spessore = 2 };
  65.       Cerchio c2 = new Cerchio() { Centro=new Punto(3, -2), Raggio=4, Colore = 0x0000FF, Spessore = 2 };
  66.      
  67.       Punto x1 = new Punto(3, 8);
  68.       Cerchio c3 = new Cerchio(x1.X, x1.Y, 4);
  69.  
  70.       int raggio = int.Parse(Console.ReadLine());
  71.  
  72.       Cerchio c4 = new Cerchio(x1.Clona(), raggio);
  73.       Console.WriteLine(x1.X);
  74.  
  75.      
  76.  
  77.       Console.WriteLine($"Perimetro di c4={c4.Perimetro()}, area di c4={c4.Area()}");
  78.       Console.WriteLine($"Coordinata x di x1 dopo la creazione dell'oggetto: {x1.X}");
  79.  
  80.       x1.Y = -888;
  81.       Console.WriteLine($"Coordinata y del centro di c4 : {c4.Centro.Y}");
  82.  
  83.  
  84.  
  85.     }
  86.   }
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement