Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 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 ConsoleApplication2
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13.  
  14. koszyk KoszykJana = new koszyk();
  15.  
  16. KoszykJana.DodajeProdukt("Jabłko", 3);
  17.  
  18. Console.ReadKey();
  19.  
  20.  
  21. KoszykJana.DodajeProdukt("jablko", 3);
  22. KoszykJana.DodajeProdukt("chleb", 4);
  23.  
  24. KoszykJana.Ilosc();
  25. KoszykJana.Suma();
  26. Console.ReadKey();
  27. }
  28. }
  29. }
  30. .....................................................................................................
  31. using System;
  32. using System.Collections.Generic;
  33. using System.Linq;
  34. using System.Text;
  35. using System.Threading.Tasks;
  36.  
  37. namespace ConsoleApplication2
  38. {
  39. class produkt
  40. {
  41.  
  42. public string nazwa;
  43. public int cena;
  44.  
  45.  
  46. }
  47. }
  48. ....................................................................................................................................
  49. using System;
  50. using System.Collections.Generic;
  51. using System.Linq;
  52. using System.Text;
  53. using System.Threading.Tasks;
  54.  
  55. namespace ConsoleApplication2
  56. {
  57. class koszyk
  58. {
  59.  
  60. public List<produkt> lista = new List<produkt>();
  61.  
  62. public void DodajeProdukt(string nazwaP, int cenaP)
  63. {
  64. produkt produktTemp = new produkt();
  65. produktTemp.cena = cenaP;
  66. produktTemp.nazwa = nazwaP;
  67. lista.Add(produktTemp);
  68. Console.WriteLine("dodano produkt: {0}, cena): {1}", nazwaP, cenaP);
  69.  
  70. }
  71.  
  72. public void Ilosc()
  73. {
  74. Console.WriteLine(lista.Count);
  75.  
  76. }
  77.  
  78. public void Suma()
  79. {
  80.  
  81. double suma = 0;
  82. foreach(var element in lista)
  83. {
  84. suma +=element.cena;
  85. }
  86. Console.WriteLine(suma);
  87. }
  88.  
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement