Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.61 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Egz1
  4. {
  5.     class Program
  6.     {
  7.         private static int Pobierz_Calkowita()
  8.         {
  9.             int liczba = 0;
  10.             bool test = false;
  11.  
  12.             do
  13.             {
  14.                
  15.                 string x = Console.ReadLine();
  16.                 test = int.TryParse(x, out liczba);
  17.                 if (test == false) Console.WriteLine("****\nTo nie liczba, proboj dalej:");
  18.  
  19.             } while (test == false);
  20.             return (liczba);
  21.  
  22.         }
  23.         static int fib_rek(int f)
  24.         {
  25.             if (f == 0) return 0;
  26.             if (f == 1) return 1;
  27.             else
  28.             {
  29.                 return fib_rek(f - 2) + fib_rek(f - 1);
  30.             }
  31.         }
  32.  
  33.         static void Main(string[] args)
  34.         {
  35.  
  36.             Console.Write("Podaj liczbe Fibonacciego który chcesz obliczyc:");
  37.             int fib = Pobierz_Calkowita();
  38.             int fib_return = fib_rek(fib);
  39.  
  40.             Console.WriteLine("Wynik:{0}",fib_return);
  41.  
  42.             //-------------------------------------------------------------------------------
  43.            
  44.             Console.WriteLine("Wysokosc diamentu:");
  45.             int n = Pobierz_Calkowita();
  46.  
  47.  
  48.             for (int i = 0; i <= n; i++)
  49.             {
  50.                 for (int j = 0; j < (n - i); j++)
  51.                     Console.Write(" ");
  52.  
  53.                 Console.Write("*");
  54.  
  55.                 for (int j = 1; j <= i*2; j++)
  56.                     Console.Write(" ");
  57.  
  58.                 Console.Write("*");
  59.                
  60.  
  61.                 Console.WriteLine();
  62.             }
  63.  
  64.             for (int k = 0; k <= n+1; k++)
  65.             {
  66.                 Console.Write("* ");
  67.             }
  68.  
  69.             Console.WriteLine();
  70.             //-------------------------------------------------------------------------------------------
  71.  
  72.             PojazdSilnikowy a1 = new PojazdSilnikowy();
  73.             a1.PodajPredkosc();
  74.             a1.ZwiekszPredkosc();
  75.             Rower a2= new Rower();
  76.             a2.JazdaBezTrzymanki();
  77.             WozKonny a3 = new WozKonny();
  78.             a3.Kulig();
  79.             Motocykl a4 = new Motocykl();
  80.             a4.NaJednymKole();
  81.             Samochod a5 = new Samochod();
  82.             a5.PodajPredkosc();
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.         }
  90.     }
  91.  
  92.     abstract class aPojazd
  93.     {
  94.         protected string kolor;
  95.         protected int dataProdukcji;
  96.         public abstract void Jazda();
  97.        
  98.  
  99.     }
  100.  
  101.     class PojazdSilnikowy : aPojazd
  102.     {
  103.         protected string marka;
  104.         protected int predkosc;
  105.  
  106.  
  107.         public PojazdSilnikowy()
  108.         {
  109.             Console.WriteLine("Utworzenie obiektu {0}",this.GetType());
  110.  
  111.         }
  112.         public override void Jazda()
  113.         {
  114.             Console.WriteLine("  {0} rusza", this.GetType());
  115.         }
  116.  
  117.         public virtual void PodajPredkosc()
  118.         {
  119.             Console.WriteLine("  Predkosc {0} to :{1}", this.GetType() , predkosc);
  120.         }
  121.  
  122.         public virtual void ZwiekszPredkosc()
  123.         {
  124.             //Console.WriteLine("  O ile zwiekszyc predkosc {0} :",this.GetType());
  125.             //int n = int.Parse(Console.ReadLine());
  126.             predkosc++;
  127.             PodajPredkosc();
  128.         }
  129.     }
  130.  
  131.     class Rower : aPojazd
  132.     {
  133.         protected string typRoweru;
  134.  
  135.         public Rower()
  136.         {
  137.             Console.WriteLine("Utworzenie obiektu {0}", this.GetType());
  138.         }
  139.         public override void Jazda()
  140.         {
  141.             Console.WriteLine("  {0} pedaluje", this.GetType());
  142.         }
  143.         public void JazdaBezTrzymanki()
  144.         {
  145.             Console.WriteLine("  {0} JedzieBezTrzymanki", this.GetType());
  146.         }
  147.  
  148.     }
  149.  
  150.     class WozKonny : aPojazd
  151.     {
  152.         protected string typPodwozia;
  153.  
  154.         public WozKonny()
  155.         {
  156.             Console.WriteLine("Utworzenie obiektu {0}", this.GetType());
  157.         }
  158.         public override void Jazda()
  159.         {
  160.             Console.WriteLine("  {0} wozi", this.GetType());
  161.         }
  162.  
  163.         public void Kulig()
  164.         {
  165.             Console.WriteLine("  {0} KULIG", this.GetType());
  166.         }
  167.     }
  168.  
  169.     class Motocykl : PojazdSilnikowy
  170.     {
  171.         public override void PodajPredkosc()
  172.         {
  173.             Console.WriteLine("  Predkosc motoru {0} to :{1}", this.GetType(), predkosc);
  174.         }
  175.         public override void ZwiekszPredkosc()
  176.         {
  177.             //Console.WriteLine("  O ile zwiekszyc predkosc motoru {0} :", this.GetType());
  178.             //int n = int.Parse(Console.ReadLine());
  179.             predkosc++;
  180.             PodajPredkosc();
  181.         }
  182.  
  183.         public override void Jazda()
  184.         {
  185.             Console.WriteLine("  {0} motocykluje", this.GetType());
  186.         }
  187.         public void NaJednymKole()
  188.         {
  189.             Console.WriteLine("JadeNa1Kole");
  190.         }
  191.     }
  192.  
  193.     class Samochod : PojazdSilnikowy
  194.     {
  195.         protected string typNadwozia;
  196.         private void Drifting()
  197.         {
  198.             Console.WriteLine("Driftuje");
  199.         }
  200.         public override void PodajPredkosc()
  201.         {
  202.             Console.WriteLine("  Predkosc pojazdu silnikowego {0} to :{1}", this.GetType(), predkosc);
  203.         }
  204.         public override void ZwiekszPredkosc()
  205.         {
  206.             //Console.WriteLine("  O ile zwiekszyc predkosc pojazdu silnikowego {0} :", this.GetType());
  207.             //int n = int.Parse(Console.ReadLine());
  208.             predkosc++;
  209.            
  210.             PodajPredkosc();
  211.         }
  212.  
  213.         public override void Jazda()
  214.         {
  215.             Console.WriteLine("  {0} jade", this.GetType());
  216.         }
  217.  
  218.     }
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement