Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.41 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. namespace ConsoleApp5
  7. {
  8. class Car
  9. {
  10. public int Rok;
  11. public string Marka;
  12. private string model;
  13. private int iloscdrzwi;
  14. private string pojemnoscsilnika;
  15. public double sredniespalanie;
  16. // Obliczspalanie ex 9
  17. public double ObliczSpalanie(double dlugosctrasy)
  18. {
  19. return sredniespalanie * dlugosctrasy;
  20. }
  21.  
  22. //ObliczkosztPrzejazdu ex 10
  23. public double ObliczKosztPrzejazdu(double dlugoscTrasy, double cenaPaliwa)
  24. {
  25. double x = ObliczSpalanie(dlugoscTrasy);
  26. return x * cenaPaliwa;
  27. }
  28.  
  29. }
  30. class Osoba
  31. {
  32. public string imie;
  33. public string nazwisko;
  34. public int rokUrodzenia;
  35. public int waga;
  36. public int wzrost;
  37. public bool okulary;
  38. public int plec;
  39. public int obliczwiek()
  40. {
  41. return DateTime.Now.Year - rokUrodzenia;
  42. }
  43. public string przedrostek()
  44. {
  45. if (plec == 0)
  46. {
  47. return "Pan ";
  48. }
  49. else
  50. return "Pani";
  51. }
  52. public string BMI()
  53. {
  54. wzrost = wzrost / 100;
  55. double BMI = waga / (wzrost ^ 2);
  56. Console.WriteLine(BMI);
  57. if (BMI > 30)
  58. {
  59. return "Otyłość";
  60. }
  61. else if (BMI >= 25 & BMI <= 30)
  62. {
  63. return "Nadwaga";
  64. }
  65. else if (BMI >= 18.5 & BMI < 25)
  66. {
  67. return "Norma";
  68. }
  69. else
  70. return "Niedowaga";
  71. }
  72. }
  73. class produkt
  74. {
  75. public string nazwa;
  76. public int cena;
  77. }
  78. //class koszyk
  79. //{
  80. // public string listatowarow;
  81. //}
  82. //public void dokoszyka(produkt x)
  83. //{
  84. // koszyk produkt = new koszyk();
  85. //}
  86. class Zespolone
  87. {
  88. public int x;
  89. public int y;
  90. public void wypisz()
  91. {
  92. if (y >= 0)
  93. {
  94. Console.WriteLine(x + "+" + y+"i");
  95. }
  96. else if (y < 0)
  97. {
  98. Console.WriteLine(x + "-" + y+"i");
  99. }
  100. else
  101. Console.WriteLine(x);
  102. }
  103. public void dodawanie(int p, int q)
  104. {
  105. x = p + x;
  106. y = q + y;
  107. }
  108. public void mnozenie(int p, int q)
  109. {
  110. x = (x * p) - (y * q);
  111. y = (x*q) + (p*y);
  112. }
  113. }
  114. class Program
  115. {
  116. //opisz typ 11
  117. static void OpiszTyp()
  118. {
  119. Console.WriteLine("Jest to typ bez argumentu");
  120. }
  121. static void OpiszTyp(int x)
  122. {
  123. Console.WriteLine("Jest to typ int");
  124. }
  125. static void OpiszTyp(double x, double y)
  126. {
  127. Console.WriteLine("Jest to typ double z 2 zmiennymi");
  128. }
  129. static void OpiszTyp(string x)
  130. {
  131. Console.WriteLine("Jest to typ string");
  132. }
  133.  
  134. static void Main(string[] args)
  135. {
  136. //ex1
  137. string carName = "Mój samochód";
  138. Console.WriteLine(carName);
  139.  
  140. // ex 4
  141. Car car1 = new Car();
  142. car1.Rok = 1999;
  143. car1.Marka = "Pogo";
  144. Console.WriteLine("Car1 = " + car1.Rok + " " + car1.Marka);
  145.  
  146. car1.sredniespalanie = 5;
  147. // ex 5,6
  148. Car car2 = new Car();
  149. car2.Rok = 1;
  150. car2.Marka = "Dino";
  151. Console.WriteLine("Car2 = " + car2.Rok + " " + car2.Marka);
  152. car1 = car2;
  153. Console.WriteLine("Car1 = " + car1.Rok + " " + car1.Marka);
  154. Console.WriteLine("Car2 = " + car2.Rok + " " + car2.Marka);
  155.  
  156. Console.WriteLine("spalanie " + car1.ObliczSpalanie(80));
  157. Console.WriteLine("koszt przejazdu " + car1.ObliczKosztPrzejazdu(10, 900));
  158. OpiszTyp();
  159. OpiszTyp(5);
  160. OpiszTyp(40.2, 50.2);
  161. OpiszTyp("Zdanie");
  162. //Dyrektor
  163. Osoba Dyrektor = new Osoba();
  164. Dyrektor.imie = "Grozna";
  165. Dyrektor.nazwisko = "Wozna";
  166. Dyrektor.plec = 1;
  167.  
  168. Console.WriteLine("Dyrektor " + Dyrektor.przedrostek() + " " + Dyrektor.imie + " " + Dyrektor.nazwisko + " w wieku " + Dyrektor.obliczwiek());
  169. //Pacjent
  170. Osoba Pacjent = new Osoba();
  171. Pacjent.imie = "jan";
  172. Pacjent.nazwisko = "kowalski";
  173. Pacjent.wzrost = 180;
  174. Pacjent.waga = 70;
  175.  
  176. Console.WriteLine("BMI pacjenta wynosi " + Pacjent.BMI());
  177. produkt kanapka = new produkt();
  178. kanapka.cena = 150;
  179. kanapka.nazwa = "kanapka";
  180. //koszyk koszyczek = new koszyk();
  181. //koszyczek.dokoszyka(kanapka);
  182. Zespolone liczba = new Zespolone();
  183. liczba.x = 5;
  184. liczba.y = 2;
  185. liczba.dodawanie(3, 4);
  186. liczba.wypisz();
  187. liczba.mnozenie(3, 4);
  188. liczba.wypisz();
  189. Console.ReadLine();
  190. }
  191. }
  192. }
  193. using System;
  194. using System.Collections.Generic;
  195. using System.Linq;
  196. using System.Text;
  197. using System.Threading.Tasks;
  198.  
  199. namespace produkt_i_koszyk
  200. {
  201. class Program
  202. {
  203. public abstract class SD
  204. {
  205. protected string[] dane;
  206. public int Length
  207. {
  208. get;
  209. protected set;
  210. }
  211. public SD()
  212. {
  213. this.Length = 0;
  214. this.dane = new string[this.Length];
  215. }
  216. }
  217. public class Produkt
  218. {
  219. public string nazwa;
  220. }
  221. public class Koszyk : SD
  222. {
  223. public void Push(string element)
  224. {
  225. this.Length++;
  226. string[] tmp = this.Przepisz(this.dane);
  227. tmp[Length - 1] = element;
  228. dane = tmp;
  229. }
  230.  
  231. protected string[] Przepisz(string[] stara)
  232. {
  233. string[] nowa = new string[stara.Length + 1];
  234. for(int i=0; i < stara.Length; i++)
  235. {
  236. nowa[i] = stara[i];
  237. }
  238. return nowa;
  239. }
  240. public void lista()
  241. {
  242. for (int i = 0; i < Length; i++) {
  243. Console.WriteLine(dane[i]);
  244. }
  245. }
  246. }
  247. static void Main(string[] args)
  248. {
  249. Produkt ziemniak = new Produkt();
  250. ziemniak.nazwa = "Ziemniak";
  251. Produkt makaron = new Produkt();
  252. makaron.nazwa = "Makaron";
  253. Produkt krab = new Produkt();
  254. krab.nazwa = "Krab";
  255. Koszyk koszyk = new Koszyk();
  256. koszyk.Push(makaron.nazwa);
  257. koszyk.Push(ziemniak.nazwa);
  258. koszyk.Push(krab.nazwa);
  259. Console.WriteLine(koszyk.Length);
  260. koszyk.lista();
  261. Console.ReadLine();
  262.  
  263. }
  264. }
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement