Advertisement
kot025

HW - Calculator.cs

Jun 12th, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.85 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 ConsoleApplicationHW
  8. {
  9.     class Calculator
  10.     {
  11.         public static DegreeValue Minus(DegreeValue v1, DegreeValue v2)
  12.         {
  13.             return v1 - v2;
  14.         }
  15.         public static DegreeValue Plus(DegreeValue v1, DegreeValue v2)
  16.         {
  17.             return v1 + v2;
  18.         }
  19.         public static DegreeValue Multiply(DegreeValue v1, int factor)
  20.         {
  21.             return v1 * factor;
  22.         }
  23.         public static DegreeValue Multiply(int factor, DegreeValue v1)
  24.         {
  25.             return v1 * factor;
  26.         }
  27.         public static DegreeValue Divide(DegreeValue v1, int devisor)
  28.         {
  29.             return v1 / devisor;
  30.         }
  31.         public static DegreeValue Flip(DegreeValue v1)
  32.         {
  33.             return new DegreeValue(0, 0, -(v1.Degrees * 3600 + v1.Minutes * 60 + v1.Seconds));
  34.         }
  35.         public static double Sin(DegreeValue v1)
  36.         {
  37.             double rad = Math.PI / 180 * (v1.Degrees + (double)v1.Minutes / 60 + (double)v1.Seconds / 3600);
  38.             return Math.Sin(rad);
  39.         }
  40.         public static double Cos(DegreeValue v1)
  41.         {
  42.             double rad = Math.PI / 180 * (v1.Degrees + (double)v1.Minutes / 60 + (double)v1.Seconds / 3600);
  43.             return Math.Cos(rad);
  44.         }
  45.         public static double Tg(DegreeValue v1)
  46.         {
  47.             if ((v1.ToSeconds() != 90 * 3600) && (v1.ToSeconds() != 270 * 3600))
  48.             {
  49.                 double rad = Math.PI / 180 * (v1.Degrees + (double)v1.Minutes / 60 + (double)v1.Seconds / 3600);
  50.                 return Math.Tan(rad);
  51.             }
  52.             else if (v1.ToSeconds() == 90 * 3600)
  53.             {
  54.                 return double.PositiveInfinity;
  55.             }
  56.             else
  57.             {
  58.                 return double.NegativeInfinity;
  59.             }
  60.         }
  61.         public static double Ctg(DegreeValue v1)
  62.         {
  63.             if ((v1.ToSeconds() != 0) && (v1.ToSeconds() != 180 * 3600))
  64.             {
  65.                 double rad = Math.PI / 180 * (v1.Degrees + (double)v1.Minutes / 60 + (double)v1.Seconds / 3600);
  66.                 return (double)1 / Math.Tan(rad);
  67.             }
  68.             else if (v1.ToSeconds() == 0)
  69.             {
  70.                 return double.PositiveInfinity;
  71.             }
  72.             else
  73.             {
  74.                 return double.NegativeInfinity;
  75.             }
  76.         }
  77.         public static DegreeValue ArcSin(double sin)
  78.         {
  79.             if (sin >= -1 && sin <= 1)
  80.             {
  81.                 int sec = (int)Math.Round(Math.Asin(sin) * 3600 * 180 / Math.PI);
  82.                 DegreeValue res = new DegreeValue(0, 0, sec);
  83.                 return res;
  84.             }
  85.             else
  86.             {
  87.                 return null;
  88.             }
  89.         }
  90.         public static DegreeValue ArcCos(double cos)
  91.         {
  92.             if (cos >= -1 && cos <= 1)
  93.             {
  94.                 int sec = (int)Math.Round(Math.Acos(cos) * 3600 * 180 / Math.PI);
  95.                 DegreeValue res = new DegreeValue(0, 0, sec);
  96.                 return res;
  97.             }
  98.             else
  99.             {
  100.                 return null;
  101.             }
  102.         }
  103.         public static DegreeValue ArcTg(double tg)
  104.         {
  105.                 int sec = (int)Math.Round(Math.Atan(tg)*3600*180/Math.PI);
  106.                 return new DegreeValue(0, 0, sec);
  107.         }
  108.         public static DegreeValue ArcCtg(double ctg)
  109.         {
  110.             if (ctg != double.NegativeInfinity)
  111.             {
  112.                 int sec = (int)Math.Round(Math.Atan(1 / ctg) * 3600 * 180 / Math.PI);
  113.                 return new DegreeValue(0, 0, sec);
  114.             }
  115.             else
  116.             {
  117.                 return new DegreeValue(180);
  118.             }
  119.         }
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement