Advertisement
UniQuet0p1

Untitled

Sep 30th, 2021
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.Design;
  4. using MenuSystem;
  5.  
  6.  
  7. namespace ConsoleApp
  8. {
  9. class Program
  10. {
  11. private static double CalculatorCurrentDisplay = 0.0;
  12.  
  13. static void Main(string[] args)
  14. {
  15. Console.Clear();
  16.  
  17.  
  18. var mainMenu = new Menu("Calculator", EMenuLevel.Root);
  19. mainMenu.AddMenuItems(new List<MenuItem>()
  20. {
  21. new MenuItem("1", "Binary operations", SubmenuBinary),
  22. new MenuItem("2", "Unary operations", SubmenuUnary),
  23. });
  24.  
  25. mainMenu.Run();
  26. }
  27.  
  28. public static string MethodA()
  29. {
  30. Console.WriteLine("Method A!!!!!");
  31. return "";
  32. }
  33.  
  34. public static string SubmenuBinary()
  35. {
  36. var menu = new Menu("Binary", EMenuLevel.First);
  37. menu.AddMenuItems(new List<MenuItem>()
  38. {
  39. new MenuItem("+", "+", Add),
  40. new MenuItem("-", "-", Subtract),
  41. new MenuItem("/", "/", Divide),
  42. new MenuItem("*", "*", Multiplication),
  43. new MenuItem("x ^ y", "x ^ y", X_power_Y)
  44.  
  45. });
  46. var res = menu.Run();
  47. return res;
  48. }
  49.  
  50. public static string Add()
  51. {
  52. // CalculatorCurrentDisplay
  53. Console.WriteLine("Current value: " + CalculatorCurrentDisplay);
  54. Console.WriteLine("plus");
  55. Console.Write("number: ");
  56. var n = Console.ReadLine()?.Trim();
  57. double.TryParse(n, out var converted);
  58.  
  59. CalculatorCurrentDisplay = CalculatorCurrentDisplay + converted;
  60. Console.WriteLine("= " + CalculatorCurrentDisplay);
  61.  
  62. return "";
  63. }
  64.  
  65. public static string Subtract() //Minuse
  66. {
  67. // CalculatorCurrentDisplay
  68. Console.WriteLine("Current value: " + CalculatorCurrentDisplay);
  69. Console.WriteLine("minuse");
  70. Console.Write("number: ");
  71. var n = Console.ReadLine()?.Trim();
  72. double.TryParse(n, out var converted);
  73.  
  74. CalculatorCurrentDisplay = CalculatorCurrentDisplay - converted;
  75. Console.WriteLine("= " + CalculatorCurrentDisplay);
  76.  
  77. return "";
  78. }
  79.  
  80. public static string Divide() //Деление
  81. {
  82. // CalculatorCurrentDisplay
  83. Console.WriteLine("Current value: " + CalculatorCurrentDisplay);
  84. Console.WriteLine("divide");
  85. Console.Write("number: ");
  86. var n = Console.ReadLine()?.Trim();
  87. double.TryParse(n, out var converted);
  88.  
  89. CalculatorCurrentDisplay = CalculatorCurrentDisplay / converted;
  90. Console.WriteLine("= " + CalculatorCurrentDisplay);
  91.  
  92. return "";
  93. }
  94.  
  95. public static string Multiplication() //Умножение
  96. {
  97. // CalculatorCurrentDisplay
  98. Console.WriteLine("Current value: " + CalculatorCurrentDisplay);
  99. Console.WriteLine("multiplication");
  100. Console.Write("number: ");
  101. var n = Console.ReadLine()?.Trim();
  102. double.TryParse(n, out var converted);
  103.  
  104. CalculatorCurrentDisplay = CalculatorCurrentDisplay * converted;
  105. Console.WriteLine("= " + CalculatorCurrentDisplay);
  106.  
  107.  
  108. return "";
  109. }
  110.  
  111. public static string X_power_Y() //x в степени y
  112. {
  113. // CalculatorCurrentDisplay
  114. Console.WriteLine("Current value: " + CalculatorCurrentDisplay);
  115. Console.WriteLine("X_power_Y");
  116. Console.Write("number: ");
  117. var n = Console.ReadLine()?.Trim();
  118. double.TryParse(n, out var converted);
  119.  
  120. CalculatorCurrentDisplay = Math.Pow(CalculatorCurrentDisplay,converted);
  121. Console.WriteLine("= " + CalculatorCurrentDisplay);
  122.  
  123.  
  124. return "";
  125. }
  126.  
  127. public static string SubmenuUnary()
  128. {
  129. var menu = new Menu("Unary", EMenuLevel.First);
  130. menu.AddMenuItems(new List<MenuItem>()
  131. {
  132. new MenuItem("Negate", "Negate", Negative),
  133. new MenuItem("Square", "Square", Square),
  134. new MenuItem("Root", "Root", Root),
  135. new MenuItem("Abs_Value", "Abs_Value", Abs_Value),
  136. });
  137. var res = menu.Run();
  138. return res;
  139. }
  140.  
  141. public static string Negative() //Негативное число
  142. {
  143. // CalculatorCurrentDisplay
  144. Console.WriteLine("Current value: " + CalculatorCurrentDisplay);
  145. Console.WriteLine("negative");
  146. Console.Write("number: ");
  147.  
  148. CalculatorCurrentDisplay = CalculatorCurrentDisplay * (-1);
  149. Console.WriteLine("= " + CalculatorCurrentDisplay);
  150.  
  151. return "";
  152. }
  153.  
  154. public static string Square() //Возводим в квадрат
  155. {
  156. // CalculatorCurrentDisplay
  157. Console.WriteLine("Current value: " + CalculatorCurrentDisplay);
  158. Console.WriteLine("square");
  159. Console.Write("number: ");
  160.  
  161. CalculatorCurrentDisplay = CalculatorCurrentDisplay * CalculatorCurrentDisplay;
  162. Console.WriteLine("= " + CalculatorCurrentDisplay);
  163.  
  164. return "";
  165. }
  166.  
  167. public static string Root() //Корень
  168. {
  169. // CalculatorCurrentDisplay
  170. Console.WriteLine("Current value: " + CalculatorCurrentDisplay);
  171. Console.WriteLine("sqrt");
  172. Console.Write("number: ");
  173.  
  174. CalculatorCurrentDisplay = Math.Sqrt(CalculatorCurrentDisplay);
  175. Console.WriteLine("= " + CalculatorCurrentDisplay);
  176.  
  177. return "";
  178. }
  179.  
  180. public static string Abs_Value() //Из отрицательного в положительное, из положительного в положительное
  181. {
  182. // CalculatorCurrentDisplay
  183. Console.WriteLine("Current value: " + CalculatorCurrentDisplay);
  184. Console.WriteLine("abs_value");
  185. Console.Write("number: ");
  186.  
  187. CalculatorCurrentDisplay = Math.Abs(CalculatorCurrentDisplay);
  188. Console.WriteLine("= " + CalculatorCurrentDisplay);
  189.  
  190. return "";
  191. }
  192. }
  193. }
  194.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement