Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Egz1
- {
- class Program
- {
- private static int Pobierz_Calkowita()
- {
- int liczba = 0;
- bool test = false;
- do
- {
- string x = Console.ReadLine();
- test = int.TryParse(x, out liczba);
- if (test == false) Console.WriteLine("****\nTo nie liczba, proboj dalej:");
- } while (test == false);
- return (liczba);
- }
- static int fib_rek(int f)
- {
- if (f == 0) return 0;
- if (f == 1) return 1;
- else
- {
- return fib_rek(f - 2) + fib_rek(f - 1);
- }
- }
- static void Main(string[] args)
- {
- Console.Write("Podaj liczbe Fibonacciego który chcesz obliczyc:");
- int fib = Pobierz_Calkowita();
- int fib_return = fib_rek(fib);
- Console.WriteLine("Wynik:{0}",fib_return);
- //-------------------------------------------------------------------------------
- Console.WriteLine("Wysokosc diamentu:");
- int n = Pobierz_Calkowita();
- for (int i = 0; i <= n; i++)
- {
- for (int j = 0; j < (n - i); j++)
- Console.Write(" ");
- Console.Write("*");
- for (int j = 1; j <= i*2; j++)
- Console.Write(" ");
- Console.Write("*");
- Console.WriteLine();
- }
- for (int k = 0; k <= n+1; k++)
- {
- Console.Write("* ");
- }
- Console.WriteLine();
- //-------------------------------------------------------------------------------------------
- PojazdSilnikowy a1 = new PojazdSilnikowy();
- a1.PodajPredkosc();
- a1.ZwiekszPredkosc();
- Rower a2= new Rower();
- a2.JazdaBezTrzymanki();
- WozKonny a3 = new WozKonny();
- a3.Kulig();
- Motocykl a4 = new Motocykl();
- a4.NaJednymKole();
- Samochod a5 = new Samochod();
- a5.PodajPredkosc();
- }
- }
- abstract class aPojazd
- {
- protected string kolor;
- protected int dataProdukcji;
- public abstract void Jazda();
- }
- class PojazdSilnikowy : aPojazd
- {
- protected string marka;
- protected int predkosc;
- public PojazdSilnikowy()
- {
- Console.WriteLine("Utworzenie obiektu {0}",this.GetType());
- }
- public override void Jazda()
- {
- Console.WriteLine(" {0} rusza", this.GetType());
- }
- public virtual void PodajPredkosc()
- {
- Console.WriteLine(" Predkosc {0} to :{1}", this.GetType() , predkosc);
- }
- public virtual void ZwiekszPredkosc()
- {
- //Console.WriteLine(" O ile zwiekszyc predkosc {0} :",this.GetType());
- //int n = int.Parse(Console.ReadLine());
- predkosc++;
- PodajPredkosc();
- }
- }
- class Rower : aPojazd
- {
- protected string typRoweru;
- public Rower()
- {
- Console.WriteLine("Utworzenie obiektu {0}", this.GetType());
- }
- public override void Jazda()
- {
- Console.WriteLine(" {0} pedaluje", this.GetType());
- }
- public void JazdaBezTrzymanki()
- {
- Console.WriteLine(" {0} JedzieBezTrzymanki", this.GetType());
- }
- }
- class WozKonny : aPojazd
- {
- protected string typPodwozia;
- public WozKonny()
- {
- Console.WriteLine("Utworzenie obiektu {0}", this.GetType());
- }
- public override void Jazda()
- {
- Console.WriteLine(" {0} wozi", this.GetType());
- }
- public void Kulig()
- {
- Console.WriteLine(" {0} KULIG", this.GetType());
- }
- }
- class Motocykl : PojazdSilnikowy
- {
- public override void PodajPredkosc()
- {
- Console.WriteLine(" Predkosc motoru {0} to :{1}", this.GetType(), predkosc);
- }
- public override void ZwiekszPredkosc()
- {
- //Console.WriteLine(" O ile zwiekszyc predkosc motoru {0} :", this.GetType());
- //int n = int.Parse(Console.ReadLine());
- predkosc++;
- PodajPredkosc();
- }
- public override void Jazda()
- {
- Console.WriteLine(" {0} motocykluje", this.GetType());
- }
- public void NaJednymKole()
- {
- Console.WriteLine("JadeNa1Kole");
- }
- }
- class Samochod : PojazdSilnikowy
- {
- protected string typNadwozia;
- private void Drifting()
- {
- Console.WriteLine("Driftuje");
- }
- public override void PodajPredkosc()
- {
- Console.WriteLine(" Predkosc pojazdu silnikowego {0} to :{1}", this.GetType(), predkosc);
- }
- public override void ZwiekszPredkosc()
- {
- //Console.WriteLine(" O ile zwiekszyc predkosc pojazdu silnikowego {0} :", this.GetType());
- //int n = int.Parse(Console.ReadLine());
- predkosc++;
- PodajPredkosc();
- }
- public override void Jazda()
- {
- Console.WriteLine(" {0} jade", this.GetType());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement