TonyTroev

Figure's area, perimeter or both

Dec 4th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 32.75 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _02_Experiment
  5. {
  6.     class Program
  7.     {
  8.         static public void Main()
  9.         {
  10.             Console.Write("What figure you want to work with (Triangle / Rectangle / Circle / Square) ");
  11.             string figure = Console.ReadLine().ToLower();
  12.             if (figure == "triangle")
  13.             {
  14.                 Triangle triangle = new Triangle();
  15.             }
  16.             else if (figure == "rectangle")
  17.             {
  18.                 Rectangle rectangle = new Rectangle();
  19.             }
  20.             else if (figure == "circle")
  21.             {
  22.                 Circle circle = new Circle();
  23.                 for (int i = 0; i < 1; i++)
  24.                 {
  25.                     Console.Write("Your input is a (Radius / Diameter) ");
  26.                     string input = Console.ReadLine().ToLower();
  27.                     double diaOrRad = 0;
  28.  
  29.                     if (input == "diameter")
  30.                     {
  31.                         try
  32.                         {
  33.                             Console.Write("Diameter's values is: ");
  34.                             diaOrRad += double.Parse(Console.ReadLine());
  35.                             if (Verification.TooSmallValues(diaOrRad))
  36.                             {
  37.                                 i--;
  38.                                 continue;
  39.                             }
  40.                             else
  41.                             {
  42.                                 circle.Radius = diaOrRad / 2;
  43.                             }
  44.                             circle.Choose();
  45.                         }
  46.                         catch (FormatException)
  47.                         {
  48.                             Console.WriteLine("Please enter numbers for the element's value!\n");
  49.                             i--;
  50.                             continue;
  51.                         }
  52.                     }
  53.                     else if (input == "radius")
  54.                     {
  55.                         try
  56.                         {
  57.                             Console.Write("Radius' values is: ");
  58.                             diaOrRad += double.Parse(Console.ReadLine());
  59.                             if (Verification.TooSmallValues(diaOrRad))
  60.                             {
  61.                                 i--;
  62.                                 continue;
  63.                             }
  64.                             else
  65.                             {
  66.                                 circle.Radius = diaOrRad;
  67.                             }
  68.                             circle.Choose();
  69.                         }
  70.                         catch
  71.                         {
  72.                             Console.WriteLine("Please enter numbers for the element's value!\n");
  73.                             i--;
  74.                             continue;
  75.                         }
  76.                     }
  77.                     else
  78.                     {
  79.                         Console.WriteLine("\nPlease choose for your input one of the " +
  80.                             "options we have presented you in the upper line!\n");
  81.                         i--;
  82.                         continue;
  83.                     }
  84.                 }
  85.             }
  86.             else if (figure == "square")
  87.             {
  88.                 Square square = new Square();
  89.                 for (int i = 0; i < 1; i++)
  90.                 {
  91.                     Console.Write("Your input is a (Side / Diagonal) ");
  92.                     string input = Console.ReadLine().ToLower();
  93.                     double sideOrDia = 0;
  94.  
  95.                     if (input == "side")
  96.                     {
  97.                         try
  98.                         {
  99.                             Console.Write("Side's values is: ");
  100.                             sideOrDia += double.Parse(Console.ReadLine());
  101.                             if (Verification.TooSmallValues(sideOrDia))
  102.                             {
  103.                                 i--;
  104.                                 continue;
  105.                             }
  106.                             else
  107.                             {
  108.                                 square.Side = sideOrDia;
  109.                             }
  110.                             square.Choose();
  111.                         }
  112.                         catch (FormatException)
  113.                         {
  114.                             Console.WriteLine("Please enter numbers for the element's value!\n");
  115.                             i--;
  116.                             continue;
  117.                         }
  118.                     }
  119.                     else if (input == "diagonal")
  120.                     {
  121.                         try
  122.                         {
  123.                             Console.Write("Diagonal's value is: ");
  124.                             sideOrDia += double.Parse(Console.ReadLine());
  125.                             if (Verification.TooSmallValues(sideOrDia))
  126.                             {
  127.                                 i--;
  128.                                 continue;
  129.                             }
  130.                             else
  131.                             {
  132.                                 square.Diagonal = sideOrDia;
  133.                             }
  134.                             square.Choose();
  135.                         }
  136.                         catch
  137.                         {
  138.                             Console.WriteLine("Please enter numbers for the element's value!\n");
  139.                             i--;
  140.                             continue;
  141.                         }
  142.                     }
  143.                     else
  144.                     {
  145.                         Console.WriteLine("\nPlease choose for your input one of the " +
  146.                             "options we have presented you in the upper line!\n");
  147.                         i--;
  148.                         continue;
  149.                     }
  150.                 }
  151.             }
  152.  
  153.         }
  154.     }
  155.  
  156.     static class Verification
  157.     {
  158.         static public bool FirstUnequalityTheorem(double side1, double side2, double side3)
  159.         {
  160.             if (side1 < side2 + side3 && side2 < side1 + side3 && side3 < side1 + side2)
  161.             {
  162.                 return true;
  163.             }
  164.             else
  165.             {
  166.                 return false;
  167.             }
  168.         }
  169.  
  170.         static public bool TooSmallValues(double value)
  171.         {
  172.             if (value <= 0)
  173.             {
  174.                 Console.WriteLine("\nYou have entered too small values! Please enter again the type of your input with a correct value!\n");
  175.                 return true;
  176.             }
  177.             else
  178.             {
  179.                 return false;
  180.             }
  181.         }
  182.     }
  183. class Triangle
  184.     {
  185.         private double area;
  186.         private double perimeter;
  187.         private static int count = 0;
  188.  
  189.         public Triangle()
  190.         {
  191.             Console.Write("You want to find (Area / Perimeter / Both) of a triangle: ");
  192.             string faceOrArea = Console.ReadLine().ToLower();
  193.  
  194.             if (faceOrArea == "area")
  195.             {
  196.                 Area();
  197.             }
  198.             else if (faceOrArea == "perimeter")
  199.             {
  200.                 Perimeter();
  201.             }
  202.             else if (faceOrArea == "both")
  203.             {
  204.                 AreaAndPerimeter();
  205.             }
  206.             else
  207.             {
  208.                 Console.WriteLine("\nPlease choose for your input one of the options we have presented you in the upper line!\n");
  209.             }
  210.         }
  211.  
  212.         private void AreaAndPerimeter()
  213.         {
  214.             string[] order = new string[] { "a", "b", "c" };
  215.             double[] values = new double[3];
  216.  
  217.             Console.WriteLine("\nEnter the values of the three sides of the triangle:");
  218.  
  219.             for (int i = 0; i < 3; i++)
  220.             {
  221.                 Console.Write($"{order[i]} = ");
  222.                 values[i] = double.Parse(Console.ReadLine());
  223.  
  224.                 if (Verification.TooSmallValues(values[i]))
  225.                 {
  226.                     i--;
  227.                     continue;
  228.                 }
  229.             }
  230.  
  231.             if (Verification.FirstUnequalityTheorem(values[0], values[1], values[2]))
  232.             {
  233.                 perimeter = values[0] + values[1] + values[2];
  234.                 area = HeronFormula(values[0], values[1], values[2]);
  235.                 Console.WriteLine("\nThe perimeter of that triangle is: {0:N2} and his area is {1:N2}", perimeter, area);
  236.             }
  237.             else
  238.             {
  239.                 Console.WriteLine("\nIt is impossible to exist such a triangle according to the UNEQUALITY THEOREM ONE!\n");
  240.                 StartAgain();
  241.             }
  242.         }
  243.  
  244.         private void Perimeter()
  245.         {
  246.             string[] order = new string[] { "a", "b", "c" };
  247.             double[] values = new double[3];
  248.  
  249.             Console.Write("\nEnter the values of the three sides of the triangle: \n");
  250.  
  251.             for (int i = 0; i < 3; i++)
  252.             {
  253.                 Console.Write($"{order[i]} = ");
  254.                 values[i] = double.Parse(Console.ReadLine());
  255.  
  256.                 if (Verification.TooSmallValues(values[i]))
  257.                 {
  258.                     i--;
  259.                     continue;
  260.                 }
  261.             }
  262.  
  263.             if (Verification.FirstUnequalityTheorem(values[0], values[1], values[2]))
  264.             {
  265.                 perimeter = values[0] + values[1] + values[2];
  266.                 Console.WriteLine("\nThe perimeter of that triangle is: {0:N2}", perimeter);
  267.             }
  268.             else
  269.             {
  270.                 Console.WriteLine("\nIt is impossible to exist such a triangle according to the UNEQUALITY THEOREM ONE!\n");
  271.                 StartAgain();
  272.             }
  273.         }
  274.  
  275.         private void Area()
  276.         {
  277.             string[] order = new string[] { "first", "second", "third" };
  278.             string[] elements = new string[3];
  279.             double[] values = new double[3];
  280.  
  281.             for (int i = 0; i < 3; i++)
  282.             {
  283.                 Console.Write($"Your {order[i]} input is a (Side / Height / Angle) ");
  284.                 elements[i] = Console.ReadLine().ToLower();
  285.  
  286.                 //Wrong element input;
  287.                 if (!(elements[i] == "side" || elements[i] == "height" || elements[i] == "angle"))
  288.                 {
  289.                     Console.WriteLine("\nPlease choose for your input one of the options we have presented you in the upper line!\n");
  290.                     i--;
  291.                     continue;
  292.                 }
  293.  
  294.                 Console.Write("Its vaue is ");
  295.                 values[i] = double.Parse(Console.ReadLine());
  296.  
  297.                 //Wrong value input;
  298.                 if (Verification.TooSmallValues(values[i]))
  299.                 {
  300.                     i--;
  301.                     continue;
  302.                 }
  303.                 //Wrong angle value input;
  304.                 else if (elements[i] == "angle" && (values[i] <= 0 || values[i] >= 180))
  305.                 {
  306.                     Console.WriteLine("\nYou have impossible values for angle in a triangle! Please enter again the type of your input with a correct value!\n");
  307.                     i--;
  308.                     continue;
  309.                 }
  310.  
  311.                 //Area found by a base side and its height:
  312.                 if ((elements[0] == "side" || elements[1] == "side") && (elements[0] == "height" || elements[1] == "height"))
  313.                 {
  314.                     area = BaseAndHeight(values[Array.IndexOf(elements, "side")], values[Array.IndexOf(elements, "height")]);
  315.                     if (area != 0)
  316.                     {
  317.                         Console.WriteLine("The area of that triangle is: {0:N2}", area);
  318.                         break;
  319.                     }
  320.                     else
  321.                     {
  322.                         Console.Write("Do you know the base side of that triangle (Yes / No) ");
  323.                         string ifKnow = Console.ReadLine().ToLower();
  324.                         if (ifKnow == "yes")
  325.                         {
  326.                             Console.Write("Its vaue is ");
  327.                             double sideIfKnow = double.Parse(Console.ReadLine());
  328.                             area = BaseAndHeight(sideIfKnow, values[Array.IndexOf(elements, "height")]);
  329.                             Console.WriteLine("The area of that triangle is: {0:N2}", area);
  330.                             break;
  331.                         }
  332.                         else
  333.                         {
  334.                             Console.WriteLine("There is no such a formula to calculate the triangle's area using your input data.");
  335.                             StartAgain();
  336.                         }
  337.                     }
  338.                 }
  339.             }
  340.  
  341.             //Finding out how many the sides in the triangle are:
  342.             int numOfSides = 0;
  343.             foreach (string element in elements)
  344.             {
  345.                 if (element == "side")
  346.                 {
  347.                     numOfSides++;
  348.                 }
  349.             }
  350.  
  351.             //Area of a rectangular triangle:
  352.             //Area found by an angle and the other two sides:
  353.             bool predict = elements.Contains("angle");
  354.             if (predict)
  355.             {
  356.  
  357.                 //Area of a rectangular triangle:
  358.                 double angle = values[Array.IndexOf(elements, "angle")];
  359.                 if (angle == 90 && numOfSides == 2)
  360.                 {
  361.                     area = RectangularTriangle(values[Array.IndexOf(elements, "side")], values[Array.LastIndexOf(elements, "side")]);
  362.                     Console.WriteLine("The area of that triangle is: {0:N2}", area);
  363.                 }
  364.  
  365.                 //Area found by an angle and the other two sides:
  366.                 else if (angle != 90 && numOfSides == 2)
  367.                 {
  368.                     area = AngleAndTwoSides(values[Array.IndexOf(elements, "angle")], values[Array.IndexOf(elements, "side")], values[Array.LastIndexOf(elements, "side")]);
  369.                     Console.WriteLine("The area of that triangle is: {0:N2}", area);
  370.                 }
  371.             }
  372.  
  373.             //Area found using The Heron's formula and checking the first unequality theorem:
  374.             else
  375.             {
  376.                 if (numOfSides == 3)
  377.                 {
  378.                     if (Verification.FirstUnequalityTheorem(values[0], values[1], values[2]))
  379.                     {
  380.                         area = HeronFormula(values[0], values[1], values[2]);
  381.                         Console.WriteLine("The area of that triangle is: {0:N2}", area);
  382.                     }
  383.                     else
  384.                     {
  385.                         Console.WriteLine("\nIt is impossible to exist such a triangle according to the UNEQUALITY THEOREM ONE!\n");
  386.                         StartAgain();
  387.                     }
  388.                 }
  389.                 else if (numOfSides != 3 && area == 0)
  390.                 {
  391.                     Console.WriteLine("There is no way to calculate the area of the triangle!");
  392.                     StartAgain();
  393.                 }
  394.             }
  395.         }
  396.  
  397.         private double BaseAndHeight(double side, double height)
  398.         {
  399.             Console.Write("Is this the base side of the height (Yes / No) ");
  400.             string yesOrNo = Console.ReadLine().ToLower();
  401.             if (yesOrNo == "yes")
  402.             {
  403.                 return side * height / 2;
  404.             }
  405.             else if (yesOrNo == "no")
  406.             {
  407.                 return 0.0;
  408.             }
  409.             else
  410.             {
  411.                 Console.WriteLine("You entered incorrect values");
  412.                 StartAgain();
  413.                 return 0.0;
  414.             }
  415.         }
  416.  
  417.         private double RectangularTriangle(double side1, double side2)
  418.         {
  419.             Console.WriteLine("Do these two sides form the right angle (Yes / No) ");
  420.             string yesOrNo = Console.ReadLine().ToLower();
  421.             if (yesOrNo == "yes")
  422.             {
  423.                 return side1 * side2 / 2;
  424.             }
  425.             else
  426.             {
  427.                 StartAgain();
  428.                 return 0.0;
  429.             }
  430.         }
  431.  
  432.         private double AngleAndTwoSides(double angle, double side1, double side2)
  433.         {
  434.             Console.Write("Is this angle between the two other sides (Yes / No) ");
  435.             string yesOrNo = Console.ReadLine().ToLower();
  436.             if (yesOrNo == "yes")
  437.             {
  438.                 return side1 * side2 * Math.Abs(Math.Sin(angle * Math.PI / 180)) / 2;
  439.             }
  440.             else
  441.             {
  442.                 StartAgain();
  443.                 return 0.0;
  444.             }
  445.         }
  446.  
  447.         private double HeronFormula(double side1, double side2, double side3)
  448.         {
  449.             double halfPerimeter = (side1 + side2 + side3) / 2;
  450.             return Math.Sqrt(halfPerimeter * (halfPerimeter - side1) * (halfPerimeter - side2) * (halfPerimeter - side3));
  451.         }
  452.  
  453.         static public void StartAgain()
  454.         {
  455.             Console.Write("Do you want to start from the beginning (Yes / No) ");
  456.             string startAgain = Console.ReadLine().ToLower();
  457.             if (startAgain == "yes")
  458.             {
  459.                 Console.Clear();
  460.                 Program.Main();
  461.             }
  462.             else if (startAgain == "no")
  463.             {
  464.                 Console.WriteLine("Thank you for the time spent.");
  465.             }
  466.             else
  467.             {
  468.                 Console.WriteLine("\nPlease choose for your input one of the options we have presented you in the upper line!\n");
  469.                 StartAgain();
  470.             }
  471.         }
  472.  
  473.         private void End(bool end)
  474.         {
  475.             if (end == true)
  476.             {
  477.                 Console.WriteLine("\nThank you for your participation!");
  478.             }
  479.         }
  480.  
  481.         ~Triangle()
  482.         {
  483.             bool end = true;
  484.             if (count > 0)
  485.             {
  486.                 end = false;
  487.             }
  488.             End(end);
  489.             count++;
  490.         }
  491.     }
  492. class Square
  493.     {
  494.         private double area;
  495.         private double perimeter;
  496.         private double diagonal;
  497.         private double side;
  498.  
  499.         public double Side
  500.         {
  501.             get
  502.             {
  503.                 return side;
  504.             }
  505.             set
  506.             {
  507.                 side += value;
  508.             }
  509.         }
  510.  
  511.         public double Diagonal
  512.         {
  513.             get
  514.             {
  515.                 return diagonal;
  516.             }
  517.             set
  518.             {
  519.                 diagonal += value;
  520.             }
  521.         }
  522.  
  523.         public void Choose()
  524.         {
  525.             for (int i = 0; i < 1; i++)
  526.             {
  527.                 Console.Write("You want to find (Area / Perimeter / Both) of a circle: ");
  528.                 string faceOrArea = Console.ReadLine().ToLower();
  529.  
  530.                 if (faceOrArea == "area")
  531.                 {
  532.                     Area();
  533.                 }
  534.                 else if (faceOrArea == "perimeter")
  535.                 {
  536.                     Perimeter();
  537.                 }
  538.                 else if (faceOrArea == "both")
  539.                 {
  540.                     AreaAndPerimeter();
  541.                 }
  542.                 else
  543.                 {
  544.                     Console.WriteLine("\nPlease choose for your input one of the options we have presented you in the upper line!\n");
  545.                 }
  546.             }
  547.  
  548.  
  549.         }
  550.         private void Area()
  551.         {
  552.             area = Math.Pow(side, 2);
  553.             Console.WriteLine(area);
  554.         }
  555.         private void Perimeter()
  556.         {
  557.             perimeter = 4 * side;
  558.             Console.WriteLine(perimeter);
  559.         }
  560.         private void AreaAndPerimeter()
  561.         {
  562.             area = Math.Pow(side, 2);
  563.             perimeter = 4 * side;
  564.             Console.WriteLine("The area of the square is: {0:N2}", area);
  565.             Console.WriteLine("The perimeter of the square is: {0:N2}", perimeter);
  566.         }
  567.     }
  568. class Rectangle
  569.     {
  570.         private static double area;
  571.         private static double perimeter;
  572.         private static int count = 0;
  573.  
  574.         public Rectangle()
  575.         {
  576.             Console.Write("You want to find (Area / Perimeter / Both) of a rectangle: ");
  577.             string faceOrArea = Console.ReadLine().ToLower();
  578.  
  579.             for (int i = 0; i < 1; i++)
  580.             {
  581.                 if (faceOrArea == "area")
  582.                 {
  583.                     Area();
  584.                 }
  585.                 else if (faceOrArea == "perimeter")
  586.                 {
  587.                     Perimeter();
  588.                 }
  589.                 else if (faceOrArea == "both")
  590.                 {
  591.                     AreaAndPerimeter();
  592.                 }
  593.                 else
  594.                 {
  595.                     Console.WriteLine("\nPlease choose for your input one of the options we have presented you in the upper line!\n");
  596.                     i--;
  597.                     continue;
  598.                 }
  599.             }
  600.         }
  601.  
  602.         private void Area()
  603.         {
  604.             string[] order = new string[] { "first", "second" };
  605.             string[] elements = new string[2];
  606.             double[] values = new double[2];
  607.  
  608.             for (int i = 0; i < 2; i++)
  609.             {
  610.                 Console.Write($"Your {order[i]} input is a (Side / Perimeter / Diagonal) ");
  611.                 elements[i] = Console.ReadLine().ToLower();
  612.  
  613.                 //Wrong element input;
  614.                 if (!(elements[i] == "side" || elements[i] == "perimeter" || elements[i] == "diagonal"))
  615.                 {
  616.                     Console.WriteLine("\nPlease choose for your input one of the options we have presented you in the upper line!\n");
  617.                     i--;
  618.                     continue;
  619.                 }
  620.  
  621.                 Console.Write("Its vaue is ");
  622.                 try
  623.                 {
  624.                     values[i] = double.Parse(Console.ReadLine());
  625.  
  626.                     //Wrong value input;
  627.                     if (Verification.TooSmallValues(values[i]))
  628.                     {
  629.                         i--;
  630.                         continue;
  631.                     }
  632.                 }
  633.                 catch (FormatException)
  634.                 {
  635.                     Console.WriteLine("Please enter numbers for the element's value!\n");
  636.                     i--;
  637.                     continue;
  638.                 }
  639.             }
  640.  
  641.             if (elements[0] == "side" && elements[1] == "side")
  642.             {
  643.                 area = AreaOfTwoSides(values[0], values[1]);
  644.             }
  645.             else if ((elements[0] == "perimeter" || elements[1] == "perimeter") && (elements[0] == "side" || elements[1] == "side"))
  646.             {
  647.                 area = AreaOfPerimeterAndSide(values[Array.IndexOf(elements, "perimeter")], values[Array.IndexOf(elements, "side")]);
  648.             }
  649.             else if ((elements[0] == "diagonal" || elements[1] == "diagonal") && (elements[0] == "side" || elements[1] == "side"))
  650.             {
  651.                 area = AreaOfDiagonalAndSide(values[Array.IndexOf(elements, "diagonal")], values[Array.IndexOf(elements, "side")]);
  652.             }
  653.             else
  654.             {
  655.                 Console.WriteLine("There is no such a formula to calculate the rectangle's area using your input data.");
  656.             }
  657.  
  658.             if (area != 0)
  659.             {
  660.                 Console.WriteLine("The area of the rectangle is: {0:N2}", area);
  661.             }
  662.             else
  663.             {
  664.                 Console.WriteLine("Something with your input was wrong!");
  665.                 StartAgain();
  666.             }
  667.         }
  668.  
  669.         private void Perimeter()
  670.         {
  671.             string[] order = new string[] { "a", "b" };
  672.             double[] values = new double[2];
  673.  
  674.             Console.Write("\nEnter the values of two adjacent sides of the rectangle:\n");
  675.  
  676.             for (int i = 0; i < 2; i++)
  677.             {
  678.                 try
  679.                 {
  680.                     Console.Write($"{order[i]} = ");
  681.                     values[i] = double.Parse(Console.ReadLine());
  682.  
  683.                     if (Verification.TooSmallValues(values[i]))
  684.                     {
  685.                         i--;
  686.                         continue;
  687.                     }
  688.                 }
  689.                 catch (FormatException)
  690.                 {
  691.                     Console.WriteLine("Please enter numbers for the element's value!\n");
  692.                     i--;
  693.                     continue;
  694.                 }
  695.             }
  696.             perimeter = PerimeterOfTwoSides(values[0], values[1]);
  697.             if (perimeter != 0)
  698.             {
  699.                 Console.WriteLine("The perimeter of the rectangle is: {0:N2}", perimeter);
  700.             }
  701.             else
  702.             {
  703.                 Console.WriteLine("Something with your input was wrong!");
  704.                 StartAgain();
  705.             }
  706.         }
  707.  
  708.         private void AreaAndPerimeter()
  709.         {
  710.             string[] order = new string[] { "a", "b" };
  711.             double[] values = new double[2];
  712.  
  713.             Console.Write("\nEnter the values of two adjacent sides of the rectangle:\n");
  714.  
  715.             for (int i = 0; i < 2; i++)
  716.             {
  717.                 try
  718.                 {
  719.                     Console.Write($"{order[i]} = ");
  720.                     values[i] = double.Parse(Console.ReadLine());
  721.  
  722.                     if (Verification.TooSmallValues(values[i]))
  723.                     {
  724.                         i--;
  725.                         continue;
  726.                     }
  727.                 }
  728.                 catch (FormatException)
  729.                 {
  730.                     Console.WriteLine("Please enter numbers for the element's value!\n");
  731.                     i--;
  732.                     continue;
  733.                 }
  734.             }
  735.             area = AreaOfTwoSides(values[0], values[1]);
  736.             if (area != 0)
  737.             {
  738.                 perimeter = 2 * (values[0] + values[1]);
  739.                 Console.WriteLine("The area of the rectangle is: {0:N2}", area);
  740.                 Console.WriteLine("The perimeter of the rectangle is: {0:N2}", perimeter);
  741.             }
  742.  
  743.         }
  744.  
  745.         private double AreaOfDiagonalAndSide(double d, double side)
  746.         {
  747.             double faceRect = side * Math.Sqrt(Math.Pow(d, 2) - Math.Pow(side, 2));
  748.             if (d > side)
  749.             {
  750.                 return faceRect;
  751.             }
  752.             else
  753.             {
  754.                 Console.WriteLine("\nYou have entered impossible values for the diagonal!");
  755.                 StartAgain();
  756.                 return 0.0;
  757.             }
  758.         }
  759.  
  760.         private double AreaOfPerimeterAndSide(double p, double side)
  761.         {
  762.             if (p <= 2 * side)
  763.             {
  764.                 Console.WriteLine("You have entered an incorrect input!");
  765.                 return 0.0;
  766.             }
  767.             else
  768.             {
  769.                 return (p * side - 2 * Math.Pow(side, 2)) / 2;
  770.             }
  771.         }
  772.  
  773.         private double AreaOfTwoSides(double side1, double side2)
  774.         {
  775.             if (side1 == side2)
  776.             {
  777.                 Console.Write("\nYou entered two equal values. Do you agree with your input (Yes / No) ");
  778.                 string square = Console.ReadLine().ToLower();
  779.                 if (square == "yes")
  780.                 {
  781.                     return side1 * side2;
  782.                 }
  783.                 else
  784.                 {
  785.                     StartAgain();
  786.                     return 0.0;
  787.                 }
  788.             }
  789.             else
  790.             {
  791.                 return side1 * side2;
  792.             }
  793.         }
  794.  
  795.         private double PerimeterOfTwoSides(double side1, double side2)
  796.         {
  797.             if (side1 == side2)
  798.             {
  799.                 Console.Write("\nYou entered two equal values. Do you agree with your input (Yes / No) ");
  800.                 string square = Console.ReadLine().ToLower();
  801.                 if (square == "yes")
  802.                 {
  803.                     return 2 * (side1 + side2);
  804.                 }
  805.                 else
  806.                 {
  807.                     StartAgain();
  808.                     return 0.0;
  809.                 }
  810.             }
  811.             else
  812.             {
  813.                 return 2 * (side1 + side2);
  814.             }
  815.         }
  816.  
  817.         static public void StartAgain()
  818.         {
  819.             Console.Write("\nDo you want to start from the beginning (Yes / No) ");
  820.             string startAgain = Console.ReadLine().ToLower();
  821.             if (startAgain == "yes")
  822.             {
  823.                 Console.Clear();
  824.                 Program.Main();
  825.             }
  826.             else if (startAgain == "no")
  827.             {
  828.                 Console.WriteLine("Thank you for the time spent.");
  829.             }
  830.             else
  831.             {
  832.                 Console.WriteLine("\nPlease choose for your input one of the options we have presented you in the upper line!\n");
  833.                 StartAgain();
  834.             }
  835.         }
  836.  
  837.         private void End(bool end)
  838.         {
  839.             if (end == true)
  840.             {
  841.                 Console.WriteLine("\nThank you for your participation!");
  842.             }
  843.         }
  844.  
  845.         ~Rectangle()
  846.         {
  847.             bool end = true;
  848.             if(count > 0)
  849.             {
  850.                 end = false;
  851.             }
  852.             End(end);
  853.             count++;
  854.         }
  855.     }
  856. class Circle
  857.     {
  858.         private double area;
  859.         private double perimeter;
  860.         private double radius;
  861.         private static int count = 0;
  862.  
  863.         public double Radius
  864.         {
  865.             get
  866.             {
  867.                 return radius;
  868.             }
  869.             set
  870.             {
  871.                 radius += value;
  872.             }
  873.         }
  874.  
  875.         public void Choose()
  876.         {
  877.             for (int i = 0; i < 1; i++)
  878.             {
  879.                 Console.Write("You want to find (Area / Perimeter / Both) of a circle: ");
  880.                 string faceOrArea = Console.ReadLine().ToLower();
  881.  
  882.                 if (faceOrArea == "area")
  883.                 {
  884.                     Area();
  885.                 }
  886.                 else if (faceOrArea == "perimeter")
  887.                 {
  888.                     Perimeter();
  889.                 }
  890.                 else if (faceOrArea == "both")
  891.                 {
  892.                     AreaAndPerimeter();
  893.                 }
  894.                 else
  895.                 {
  896.                     Console.WriteLine("\nPlease choose for your input one of the options we have presented you in the upper line!\n");
  897.                 }
  898.             }
  899.         }
  900.  
  901.         private void Area()
  902.         {
  903.             area = Math.PI * Math.Pow(radius, 2);
  904.             if (area != 0)
  905.             {
  906.                 Console.WriteLine("The area of the circle is: {0:N2}", area);
  907.             }
  908.             else
  909.             {
  910.                 Console.WriteLine("Something with your input was wrong!");
  911.                 StartAgain();
  912.             }
  913.         }
  914.  
  915.         private void Perimeter()
  916.         {
  917.             perimeter = 2 * Math.PI * radius;
  918.             if (perimeter != 0)
  919.             {
  920.                 Console.WriteLine("The perimeter of the circle is: {0:N2}", perimeter);
  921.             }
  922.             else
  923.             {
  924.                 Console.WriteLine("Something with your input was wrong!");
  925.                 StartAgain();
  926.             }
  927.         }
  928.  
  929.         private void AreaAndPerimeter()
  930.         {
  931.             area = Math.PI * Math.Pow(radius, 2);
  932.             perimeter = 2 * Math.PI * radius;
  933.             if (area != 0 && perimeter != 0)
  934.             {
  935.                 Console.WriteLine("The area of the circle is: {0:N2}", area);
  936.                 Console.WriteLine("The perimeter of the circle is: {0:N2}", perimeter);
  937.             }
  938.             else
  939.             {
  940.                 Console.WriteLine("\nSomething with your input was wrong!");
  941.                 StartAgain();
  942.             }
  943.         }
  944.  
  945.         static public void StartAgain()
  946.         {
  947.             Console.Write("Do you want to start from the beginning (Yes / No) ");
  948.             string startAgain = Console.ReadLine().ToLower();
  949.             if (startAgain == "yes")
  950.             {
  951.                 Console.Clear();
  952.                 Program.Main();
  953.             }
  954.             else if (startAgain == "no")
  955.             {
  956.                 Console.WriteLine("Thank you for the time spent.");
  957.             }
  958.             else
  959.             {
  960.                 Console.WriteLine("\nPlease choose for your input one of the options we have presented you in the upper line!\n");
  961.                 StartAgain();
  962.             }
  963.         }
  964.  
  965.         private void End(bool end)
  966.         {
  967.             if (end == true)
  968.             {
  969.                 Console.WriteLine("\nThank you for your participation!");
  970.             }
  971.         }
  972.  
  973.         ~Circle()
  974.         {
  975.             bool end = true;
  976.             if (count > 0)
  977.             {
  978.                 end = false;
  979.             }
  980.             End(end);
  981.             count++;
  982.         }
  983.     }
  984. }
Advertisement
Add Comment
Please, Sign In to add comment