Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication2
- {
- class Program
- {
- static void Main(string[] args)
- {
- koszyk KoszykJana = new koszyk();
- KoszykJana.DodajeProdukt("Jabłko", 3);
- Console.ReadKey();
- KoszykJana.DodajeProdukt("jablko", 3);
- KoszykJana.DodajeProdukt("chleb", 4);
- KoszykJana.Ilosc();
- KoszykJana.Suma();
- Console.ReadKey();
- }
- }
- }
- .....................................................................................................
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication2
- {
- class produkt
- {
- public string nazwa;
- public int cena;
- }
- }
- ....................................................................................................................................
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication2
- {
- class koszyk
- {
- public List<produkt> lista = new List<produkt>();
- public void DodajeProdukt(string nazwaP, int cenaP)
- {
- produkt produktTemp = new produkt();
- produktTemp.cena = cenaP;
- produktTemp.nazwa = nazwaP;
- lista.Add(produktTemp);
- Console.WriteLine("dodano produkt: {0}, cena): {1}", nazwaP, cenaP);
- }
- public void Ilosc()
- {
- Console.WriteLine(lista.Count);
- }
- public void Suma()
- {
- double suma = 0;
- foreach(var element in lista)
- {
- suma +=element.cena;
- }
- Console.WriteLine(suma);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement