Facebook
From Queen Capybara, 3 Years ago, written in C#.
This paste is a reply to Untitled from Big Pudu - view diff
Embed
Download Paste or View Raw
Hits: 158
  1. //To wklejasz w funkcji main
  2. Console.WriteLine("Please enter radius: ");
  3. double a = double.Parse(Console.ReadLine());
  4. Console.WriteLine("Please enter generatix: ");
  5. double b = double.Parse(Console.ReadLine());
  6.  
  7. //zadanie 2
  8. try
  9. {
  10.   Console.WriteLine("Cone field: " + PolePowCalkStozka(a, b));
  11. }
  12. catch (DivideByZeroException e)
  13. {
  14.   Console.WriteLine("Values can't be 0");
  15. }
  16. catch (InvalidOperationException e)
  17. {
  18.   Console.WriteLine("Values must be >0");
  19. }
  20. catch (DataMisalignedException)
  21. {
  22.   Console.WriteLine("You entered incorrect parameters");
  23. }
  24.  
  25.  
  26.  
  27. // a to poza funkcją main
  28. public static double PolePowCalkStozka(double promien, double tworzaca)
  29. {
  30.   double height = Math.Sqrt(Math.Pow(tworzaca, 2) - Math.Pow(promien, 2));
  31.   double field;
  32.  
  33.  
  34.   if (promien < 0 || tworzaca < 0)
  35.   {
  36.     throw new System.InvalidOperationException();
  37.   }
  38.   else if(promien+height<tworzaca || promien+tworzaca<height || height + tworzaca < promien)
  39.   {
  40.     throw new System.DataMisalignedException();
  41.   }
  42.   else if(promien==0 || tworzaca == 0)
  43.   {
  44.     throw new System.DivideByZeroException();
  45.   }
  46.   else
  47.   {
  48.     field = (Math.PI * promien) * (promien + tworzaca);
  49.     return field;
  50.   }
  51. }
  52.