Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.81 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 ConsoleApplication1
  8. {
  9.  
  10.  
  11. class Program
  12. {
  13. static int WprowadzLiczbeInt(string TekstDoWprowadzenia)
  14. {
  15. int Liczba = 0;
  16.  
  17. while (true)
  18. {
  19. Console.Write(TekstDoWprowadzenia);
  20. if (int.TryParse(Console.ReadLine(), out Liczba) == true)
  21. {
  22. break;
  23. }
  24. else
  25. {
  26. Console.WriteLine("Co piszesz baranie!");
  27. }
  28. }
  29.  
  30. return Liczba;
  31. }
  32.  
  33. static void Main(string[] args)
  34. {
  35.  
  36.  
  37. Console.WriteLine("Wybierz numer figury, której chcesz obliczyć pole");
  38. Console.WriteLine("1.Koło\n2.Trójkąt\n3.Prostokąt\n4.Wszystkie figury");
  39.  
  40.  
  41. int wybor = WprowadzLiczbeInt("Wybierz opcje z menu=");
  42. switch (wybor)
  43. {
  44.  
  45. case 1:
  46. Console.WriteLine("1.Koło");
  47. Figura kolo = new Kolo();
  48. kolo.WprowadzDane();
  49.  
  50. Console.WriteLine($"Pole = {kolo.ObliczPole()}");
  51.  
  52. break;
  53.  
  54. case 2:
  55. Console.WriteLine("2.Trójkąt");
  56. Figura Trojkat = new Trojkat();
  57. Trojkat.WprowadzDane();
  58.  
  59. Console.WriteLine($"Pole = {Trojkat.ObliczPole()}");
  60. break;
  61.  
  62. case 3:
  63. Console.WriteLine("2.Prostokąt");
  64. Figura Prostokąt = new Prostokąt();
  65. Prostokąt.WprowadzDane();
  66.  
  67. Console.WriteLine($"Pole = {Prostokąt.ObliczPole()}");
  68.  
  69. break;
  70. case 4:
  71. Console.WriteLine("Wszystkie figury");
  72.  
  73.  
  74.  
  75.  
  76. break;
  77. default:
  78. Console.WriteLine("Zły wybór");
  79. break;
  80.  
  81. }
  82.  
  83.  
  84. Console.ReadLine();
  85.  
  86.  
  87.  
  88.  
  89. }
  90. }
  91. }
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. using System;
  104. using System.Collections.Generic;
  105. using System.Linq;
  106. using System.Text;
  107. using System.Threading.Tasks;
  108.  
  109. namespace ConsoleApplication1
  110. {
  111. public class Kolo : Figura
  112. {
  113. private double promien;
  114.  
  115. public Kolo()
  116. {
  117. promien = 0f;
  118. }
  119.  
  120. public Kolo(double promien)
  121. {
  122. if (promien <= 0f)
  123. throw new Exception("Promien nie moze byc <= 0");
  124.  
  125. this.promien = promien;
  126. }
  127.  
  128. public override double ObliczPole()
  129. {
  130. return Math.PI * (promien * promien);
  131. }
  132.  
  133. public override void WprowadzDane()
  134. {
  135. while (true)
  136. {
  137. Console.Write("Podaj promien=");
  138. if (double.TryParse(Console.ReadLine(), out this.promien) && promien > 0)
  139. {
  140. break;
  141. }
  142. else
  143. {
  144. Console.WriteLine("Błędna wartość promienia!");
  145. }
  146. }
  147. }
  148.  
  149.  
  150.  
  151. }
  152. }
  153.  
  154.  
  155. using System;
  156. using System.Collections.Generic;
  157. using System.Linq;
  158. using System.Text;
  159. using System.Threading.Tasks;
  160.  
  161. namespace ConsoleApplication1
  162. {
  163. public abstract class Figura
  164. {
  165. public abstract void WprowadzDane();
  166. public abstract double ObliczPole();
  167.  
  168. }
  169. }
  170.  
  171.  
  172.  
  173.  
  174. using System;
  175. using System.Collections.Generic;
  176. using System.Linq;
  177. using System.Text;
  178. using System.Threading.Tasks;
  179.  
  180. namespace ConsoleApplication1
  181. {
  182. public class Trojkat : Figura
  183. {
  184. private double wysokosc;
  185. private double bok;
  186. public Trojkat()
  187. {
  188. wysokosc = 0f;
  189. bok = 0f;
  190. }
  191.  
  192. public Trojkat(double wysokosc, double bok)
  193. {
  194. if (wysokosc <= 0f)
  195. throw new Exception("Wysokość nie moze byc <= 0");
  196.  
  197. this.wysokosc = wysokosc;
  198.  
  199. if (bok <= 0f)
  200. throw new Exception("Bok nie moze byc <= 0");
  201.  
  202. this.bok = bok;
  203. }
  204.  
  205. public override double ObliczPole()
  206. {
  207. return (wysokosc * bok) * 1/2;
  208. }
  209.  
  210. public override void WprowadzDane()
  211. {
  212. while (true)
  213. {
  214. Console.Write("Podaj wysokosc=");
  215. if (double.TryParse(Console.ReadLine(), out this.wysokosc) && wysokosc > 0)
  216. {
  217. Console.Write("Podaj bok=");
  218. if (double.TryParse(Console.ReadLine(), out this.bok) && bok > 0)
  219. {
  220. break;
  221. }
  222. else
  223. {
  224. Console.WriteLine("Błędna wartość boku!");
  225. }
  226. }
  227. else
  228. {
  229. Console.WriteLine("Błędna wartość wysokości!");
  230. }
  231.  
  232.  
  233.  
  234.  
  235. }
  236. }
  237.  
  238.  
  239.  
  240. }
  241. }
  242.  
  243.  
  244.  
  245.  
  246.  
  247. using System;
  248. using System.Collections.Generic;
  249. using System.Linq;
  250. using System.Text;
  251. using System.Threading.Tasks;
  252.  
  253. namespace ConsoleApplication1
  254. {
  255. public class Prostokąt : Figura
  256. {
  257. private double a;
  258. private double b;
  259. public Prostokąt()
  260. {
  261. a = 0f;
  262. b = 0f;
  263. }
  264.  
  265. public Prostokąt(double a, double b)
  266. {
  267. if (a <= 0f)
  268. throw new Exception("Długość a nie moze byc <= 0");
  269.  
  270. this.a = a;
  271.  
  272. if (b <= 0f)
  273. throw new Exception("Długość b nie moze byc <= 0");
  274.  
  275. this.b = b;
  276. }
  277.  
  278. public override double ObliczPole()
  279. {
  280. return (a * b);
  281. }
  282.  
  283. public override void WprowadzDane()
  284. {
  285. while (true)
  286. {
  287. Console.Write("Podaj długość a=");
  288. if (double.TryParse(Console.ReadLine(), out this.a) && a > 0)
  289. {
  290. Console.Write("Podaj długość b=");
  291. if (double.TryParse(Console.ReadLine(), out this.b) && b > 0)
  292. {
  293. break;
  294. }
  295. else
  296. {
  297. Console.WriteLine("Błędna wartość długości b!");
  298. }
  299. }
  300. else
  301. {
  302. Console.WriteLine("Błędna wartość długości a!");
  303. }
  304.  
  305.  
  306.  
  307.  
  308. }
  309. }
  310.  
  311.  
  312.  
  313. }
  314. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement