Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- class Program
- {
- static int WprowadzLiczbeInt(string TekstDoWprowadzenia)
- {
- int Liczba = 0;
- while (true)
- {
- Console.Write(TekstDoWprowadzenia);
- if (int.TryParse(Console.ReadLine(), out Liczba) == true)
- {
- break;
- }
- else
- {
- Console.WriteLine("Co piszesz baranie!");
- }
- }
- return Liczba;
- }
- static void Main(string[] args)
- {
- Console.WriteLine("Wybierz numer figury, której chcesz obliczyć pole");
- Console.WriteLine("1.Koło\n2.Trójkąt\n3.Prostokąt\n4.Wszystkie figury");
- int wybor = WprowadzLiczbeInt("Wybierz opcje z menu=");
- switch (wybor)
- {
- case 1:
- Console.WriteLine("1.Koło");
- Figura kolo = new Kolo();
- kolo.WprowadzDane();
- Console.WriteLine($"Pole = {kolo.ObliczPole()}");
- break;
- case 2:
- Console.WriteLine("2.Trójkąt");
- Figura Trojkat = new Trojkat();
- Trojkat.WprowadzDane();
- Console.WriteLine($"Pole = {Trojkat.ObliczPole()}");
- break;
- case 3:
- Console.WriteLine("2.Prostokąt");
- Figura Prostokąt = new Prostokąt();
- Prostokąt.WprowadzDane();
- Console.WriteLine($"Pole = {Prostokąt.ObliczPole()}");
- break;
- case 4:
- Console.WriteLine("Wszystkie figury");
- break;
- default:
- Console.WriteLine("Zły wybór");
- break;
- }
- Console.ReadLine();
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- public class Kolo : Figura
- {
- private double promien;
- public Kolo()
- {
- promien = 0f;
- }
- public Kolo(double promien)
- {
- if (promien <= 0f)
- throw new Exception("Promien nie moze byc <= 0");
- this.promien = promien;
- }
- public override double ObliczPole()
- {
- return Math.PI * (promien * promien);
- }
- public override void WprowadzDane()
- {
- while (true)
- {
- Console.Write("Podaj promien=");
- if (double.TryParse(Console.ReadLine(), out this.promien) && promien > 0)
- {
- break;
- }
- else
- {
- Console.WriteLine("Błędna wartość promienia!");
- }
- }
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- public abstract class Figura
- {
- public abstract void WprowadzDane();
- public abstract double ObliczPole();
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- public class Trojkat : Figura
- {
- private double wysokosc;
- private double bok;
- public Trojkat()
- {
- wysokosc = 0f;
- bok = 0f;
- }
- public Trojkat(double wysokosc, double bok)
- {
- if (wysokosc <= 0f)
- throw new Exception("Wysokość nie moze byc <= 0");
- this.wysokosc = wysokosc;
- if (bok <= 0f)
- throw new Exception("Bok nie moze byc <= 0");
- this.bok = bok;
- }
- public override double ObliczPole()
- {
- return (wysokosc * bok) * 1/2;
- }
- public override void WprowadzDane()
- {
- while (true)
- {
- Console.Write("Podaj wysokosc=");
- if (double.TryParse(Console.ReadLine(), out this.wysokosc) && wysokosc > 0)
- {
- Console.Write("Podaj bok=");
- if (double.TryParse(Console.ReadLine(), out this.bok) && bok > 0)
- {
- break;
- }
- else
- {
- Console.WriteLine("Błędna wartość boku!");
- }
- }
- else
- {
- Console.WriteLine("Błędna wartość wysokości!");
- }
- }
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- public class Prostokąt : Figura
- {
- private double a;
- private double b;
- public Prostokąt()
- {
- a = 0f;
- b = 0f;
- }
- public Prostokąt(double a, double b)
- {
- if (a <= 0f)
- throw new Exception("Długość a nie moze byc <= 0");
- this.a = a;
- if (b <= 0f)
- throw new Exception("Długość b nie moze byc <= 0");
- this.b = b;
- }
- public override double ObliczPole()
- {
- return (a * b);
- }
- public override void WprowadzDane()
- {
- while (true)
- {
- Console.Write("Podaj długość a=");
- if (double.TryParse(Console.ReadLine(), out this.a) && a > 0)
- {
- Console.Write("Podaj długość b=");
- if (double.TryParse(Console.ReadLine(), out this.b) && b > 0)
- {
- break;
- }
- else
- {
- Console.WriteLine("Błędna wartość długości b!");
- }
- }
- else
- {
- Console.WriteLine("Błędna wartość długości a!");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement