Advertisement
Guest User

Untitled

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