Guest User

Untitled

a guest
Dec 15th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 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 kalkulacka
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Console.WriteLine("Daniel Nosek");
  14. Console.WriteLine("Výpočet obvodu a obsahu - trojúhelník, pravidelný šestiúhelník");
  15. Console.WriteLine("Zvolte si obrazec:");
  16. Console.WriteLine("1 - trojúhelník");
  17. Console.WriteLine("2 - pravidelný šestiúhelník");
  18.  
  19. int VolbaObrazce = int.Parse(Console.ReadLine());
  20. double obvod = 0;
  21. double obsah = 0;
  22.  
  23. bool prepocitat = false;
  24.  
  25. do
  26. {
  27. Console.Clear();
  28.  
  29. switch (VolbaObrazce)
  30. {
  31. case 1:
  32. double a = PrectiPromennou("Zadejte délku strany a:");
  33. double b = PrectiPromennou("Zadejte délku strany b:");
  34. double c = PrectiPromennou("Zadejte délku strany c:");
  35.  
  36. obvod = ObvodTrojuhelniku(a, b, c);
  37. obsah = ObsahTrojuhelniku(a, b, c);
  38. break;
  39.  
  40. case 2:
  41. double d = PrectiPromennou("Zadejte délku strany d:");
  42.  
  43. obvod = ObvodSestiuhelniku(d);
  44. obsah = ObsahSestiuhelniku(d);
  45. break;
  46. default:
  47. {
  48. Console.WriteLine("Neplatná volba");
  49. }
  50. return;
  51. }
  52.  
  53. // vysledky, zaokrouhleny na dve desetinna mista
  54. Console.WriteLine("obvod: " + Math.Round(obvod, 2));
  55. Console.WriteLine("obsah: " + Math.Round(obsah, 2));
  56.  
  57. /* loop pro pripad kdy uzivatel chce vypocet znova s jinymi hodnotami
  58. promenna recalculate musi byt rovna 1, jinak se program vypne */
  59. prepocitat = PrectiPromennou("Pro výpočet s jinými rozměry stiskněte 1:") == 1;
  60. }
  61. while (prepocitat);
  62. }
  63.  
  64. /*Puvodne jsem pouzival pri cases
  65. Console.WriteLine("Zadejte délku strany x:");
  66. double x = double.Parse(Console.ReadLine());
  67. nicmene resit to takhle mi prijde jednodussi.*/
  68. static double PrectiPromennou(string text)
  69. {
  70. Console.Write(text);
  71. return double.Parse(Console.ReadLine());
  72. }
  73.  
  74. /// <summary>
  75. /// Vypocet obvodu pomoci souctu stran
  76. /// </summary>
  77. /// <param name="a">delka strany a</param>
  78. /// <param name="b">delka strany b</param>
  79. /// <param name="c">delka strany c</param>
  80. /// <returns>obvod trojuhelniku</returns>
  81. static double ObvodTrojuhelniku(double a, double b, double c)
  82. {
  83. return a + b + c;
  84. }
  85.  
  86. /// <summary>
  87. /// Vypocet obsahu pomoci heronova vzorce
  88. /// </summary>
  89. /// <param name="a">delka strany a</param>
  90. /// <param name="b">delka strany b</param>
  91. /// <param name="c">delka strany c</param>
  92. /// <returns>obsah trojuhelniku</returns>
  93. static double ObsahTrojuhelniku(double a, double b, double c)
  94. {
  95. double s = (a + b + c) / 2;
  96. return Math.Sqrt(s * (s - a) * (s - b) * (s - c));
  97. }
  98.  
  99. /// <summary>
  100. /// Vypocet obvodu pomoci soucinu stran
  101. /// </summary>
  102. /// <param name="d">delka strany d</param>
  103. /// <returns>obvod sestiuhelniku</returns>
  104. static double ObvodSestiuhelniku(double d)
  105. {
  106. return 6 * d;
  107. }
  108.  
  109. /// <summary>
  110. /// vypocet obsahu
  111. /// </summary>
  112. /// <param name="d">delka strany d</param>
  113. /// <returns>obsah sestiuhelniku</returns>
  114. static double ObsahSestiuhelniku(double d)
  115. {
  116. return ((3 * Math.Sqrt(3) * Math.Pow(d, 2))) / 2;
  117. }
  118.  
  119. }
Add Comment
Please, Sign In to add comment