Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.04 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 kolo3
  8. {
  9.  
  10. class Program
  11. {
  12. public void getType() { Console.WriteLine("Wczytano void"); }
  13. public void getType(int a) { Console.WriteLine("Wczytano integer"); }
  14. public void getType(string a) { Console.WriteLine("Wczytano string"); }
  15. public void getType(int a, string b) { Console.WriteLine("Wczytano integer & string"); }
  16. public void getType(bool a) { Console.WriteLine("Wczytano Boolean"); }
  17. public void getType(int a, int b, bool c) { Console.WriteLine("Wczytano 2 x integer & Boolean"); }
  18.  
  19. //#################################################################//
  20.  
  21. public enum typTrasy {krotka = 8, dluga = 13}
  22. class Samochod
  23. {
  24. private float pojemnoscSilnika;
  25. private string nrVIN;
  26. public int rocznik;
  27. public string nazwa;
  28. public float srednieSpalanie;
  29.  
  30. private Samochod() { }
  31. public void Create(float _a, string _b, int _c, string _d, float _e)
  32. {
  33. this.pojemnoscSilnika = _a;
  34. this.nrVIN = _b;
  35. this.rocznik = _c;
  36. this.nazwa = _d;
  37. this.srednieSpalanie = _e;
  38. }
  39. public void ObliczSpalanie(int lenght, typTrasy trasa )
  40. {
  41. Console.WriteLine("Spalanie tego samocodu to: {0}", (this.srednieSpalanie * lenght * ((int)trasa / 10)));
  42. }
  43. }
  44. //#################################################################//
  45.  
  46. class Kalkulator
  47. {
  48. private int a, b;
  49. public Kalkulator() { }
  50. public Kalkulator(int _a)
  51. {
  52. this.a = _a;
  53. }
  54. public Kalkulator(int _a, int _b)
  55. {
  56. this.a = _a;
  57. this.b = _b;
  58. }
  59. private int Dodaj(){ return this.a + this.b; }
  60. private int Odejmij() { return this.a - this.b; }
  61. private int Dziel() { return (int)(this.a / this.b); }
  62. private int Pomnuz() { return this.a * this.b; }
  63.  
  64. }
  65. class DziwnyKalkulator : Kalkulator
  66. {
  67. public int a, b, c;
  68. public DziwnyKalkulator() { }
  69. public DziwnyKalkulator(int _a)
  70. {
  71. this.a = _a;
  72. }
  73. public DziwnyKalkulator(int _a, int _b)
  74. {
  75. this.a = _a;
  76. this.b = _b;
  77. }
  78. public DziwnyKalkulator(int _a, int _b, int _c)
  79. {
  80. this.a = _a;
  81. this.b = _b;
  82. this.c = _c;
  83. }
  84. public int Dodawanie(int x, int y)
  85. {
  86. return x + y;
  87. }
  88. public void DodawanieModulo26()
  89. {
  90. Console.WriteLine("{0}", (this.a % 26 + this.b % 26) % 26);
  91. }
  92. public void Pierwiastkowanie()
  93. {
  94. Console.WriteLine("{0}", Math.Sqrt(this.a));
  95. }
  96. public void PodwojneDodawanie()
  97. {
  98. Console.WriteLine("{0}", this.Dodawanie(a, Dodawanie(b, c)));
  99. }
  100. }
  101. //#################################################################//
  102. class Pracownik
  103. {
  104. public string imie;
  105. public string nazwisko;
  106. public double zarobki;
  107. public Pracownik() { }
  108. public Pracownik(string _imie, string _nazwisko, double _zarobki)
  109. {
  110. this.imie = _imie;
  111. this.nazwisko = _nazwisko;
  112. this.zarobki = _zarobki;
  113. }
  114. public virtual void Pracuj()
  115. {
  116. Console.WriteLine("Pracownik teraz pracuje");
  117. }
  118.  
  119. }
  120. class Skrzypek : Pracownik
  121. {
  122. public Skrzypek(string imie, string nazwisko, double zarobki)
  123. : base(imie, nazwisko, zarobki)
  124. {
  125. base.imie = imie;
  126. base.nazwisko = nazwisko;
  127. base.zarobki = zarobki;
  128. }
  129.  
  130. public override void Pracuj()
  131. {
  132. Console.WriteLine("Skrzypek skrzypi");
  133. }
  134. }
  135. class Ksiegowa : Pracownik
  136. {
  137. public Ksiegowa(string imie, string nazwisko, double zarobki)
  138. : base(imie, nazwisko, zarobki)
  139. {
  140. base.imie = imie;
  141. base.nazwisko = nazwisko;
  142. base.zarobki = zarobki;
  143. }
  144.  
  145. public override void Pracuj()
  146. {
  147. Console.WriteLine("Księgowa się obija");
  148. }
  149. }
  150. class Sprzedawca : Pracownik
  151. {
  152. public Sprzedawca(string imie, string nazwisko, double zarobki)
  153. : base(imie, nazwisko, zarobki)
  154. {
  155. base.imie = imie;
  156. base.nazwisko = nazwisko;
  157. base.zarobki = zarobki;
  158. }
  159.  
  160. public override void Pracuj()
  161. {
  162. Console.WriteLine("Sprzedawca się sprzedaje");
  163. }
  164. //#################################################################//
  165. interface IClonable
  166. {
  167. Object Clone();
  168. }
  169. interface IFigure
  170. {
  171. string ToString();
  172. void LiczObwod();
  173. }
  174. class Punkt : IClonable, IFigure
  175. {
  176. public int x, y;
  177. public Punkt () { }
  178. public Punkt(int _x, int _y) { this.x = _x; this.y = _y; }
  179. public object Clone()
  180. {
  181. return this.MemberwiseClone();
  182. }
  183. public override string ToString()
  184. {
  185. return "To jest punkt o współrzędnych <" + x.ToString() + y.ToString() + ">";
  186. }
  187. public void LiczFigure()
  188. {
  189. Console.WriteLine("Obwod = 0");
  190. }
  191. }
  192. class Kolo : IClonable, IFigure
  193. {
  194. public int srodek_x, srodek_y, promien;
  195. public Kolo() { }
  196. public Kolo(int _a, int _b, int _c) { this.srodek_x = _a; this.srodek_y = _b; this.promien = _c; }
  197. public object Clone()
  198. {
  199. return this.MemberwiseClone();
  200. }
  201. public override string ToString()
  202. {
  203. return "To jest punkt o srodku <" + srodek_x.ToString() + srodek_y.ToString() + "> i promieniu r = " + promien.ToString();
  204. }
  205. public void LiczFigure()
  206. {
  207. Console.WriteLine("Obwod = {0}", (2 * Math.PI * this.promien) );
  208. }
  209. }
  210. class Kwadrat : IClonable, IFigure
  211. {
  212. public int a_x, a_y, b_x, b_y, c_x, c_y, d_x, d_y;
  213. public Kwadrat() { }
  214. public Kwadrat(int _a, int _b, int _c, int _d, int _e, int _f, int _g, int _h)
  215. {
  216. this.a_x = _a; this.a_y = _b;
  217. this.b_x = _c; this.b_y = _d;
  218. this.c_x = _e; this.c_y = _f;
  219. this.d_x = _g; this.d_y = _h;
  220. }
  221. public object Clone()
  222. {
  223. return this.MemberwiseClone();
  224. }
  225. public override string ToString()
  226. {
  227. return "To jest punkt o naroznikach <" + a_x.ToString() + a_y.ToString() + "> <" + b_x.ToString() + b_y.ToString()
  228. + "> <" + c_x.ToString() + c_y.ToString() + "> <" + d_x.ToString() + d_y.ToString();
  229. }
  230. public void LiczFigure()
  231. {
  232. int obwod = (this.a_x - this.d_x) + (this.b_y - this.a_y) + (this.c_y - this.d_y) + (this.b_x - this.c_x);
  233. Console.WriteLine("Obwod = {0}", obwod);
  234. }
  235. }
  236. }
  237. static void Main(string[] args)
  238. {
  239. //#################################################################//
  240.  
  241. Type cars = typeof(Samochod);
  242. Samochod car = (Samochod)Activator.CreateInstance(cars, true);
  243.  
  244. car.Create(1.4F, "a", 1234, "b", 1.1F);
  245. car.ObliczSpalanie(100, typTrasy.dluga);
  246. //#################################################################//
  247.  
  248. Type abc = typeof(Program);
  249. Program one = (Program)Activator.CreateInstance(abc, true);
  250. one.getType(true);
  251. one.getType(1, "napis");
  252. one.getType(1, 1, true);
  253. one.getType("napis");
  254. one.getType(1);
  255. //#################################################################//
  256.  
  257. DziwnyKalkulator k = new DziwnyKalkulator(100);
  258. k.Pierwiastkowanie();
  259. DziwnyKalkulator k2 = new DziwnyKalkulator(40, 1);
  260. k2.DodawanieModulo26();
  261. DziwnyKalkulator k3 = new DziwnyKalkulator(40, 1, 7);
  262. k3.PodwojneDodawanie();
  263. //#################################################################//
  264.  
  265. List<Pracownik> LISTA = new List<Pracownik>();
  266. LISTA.Add(new Skrzypek("andrzej", "nie ma", 33.3));
  267. LISTA.Add(new Sprzedawca("janusz", "abc", 66.6));
  268. LISTA.Add(new Ksiegowa("mariola", "xdxd", 99.9));
  269. foreach (Pracownik NaLiscie in LISTA)
  270. {
  271. NaLiscie.Pracuj();
  272. }
  273. Console.ReadKey();
  274. }
  275. }
  276. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement