100 likes | 253 Views
OOP. C# ile basit sınıf uygulamaları. AddNewItem -> Class. using System ; using System . Collections . Generic ; using System . Linq ; using System . Text ; namespace ConsoleApplication1 { class Vehicle { public string producer ; public string model; public int pyear ;
E N D
OOP C# ile basit sınıf uygulamaları
AddNewItem->Class usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; namespace ConsoleApplication1 { classVehicle { publicstringproducer; publicstring model; publicintpyear; publicstringccolor; publicint km; publicintspd; //methods publicvoidincreasespd() { spd = spd + 10; Console.WriteLine("your speed is: " + spd); } publicvoiddecreasespd() { spd = spd - 10; Console.WriteLine("your speed is: " + spd); } } }
Program.cs usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; namespace ConsoleApplication1 { class Program { staticvoidMain(string[] args) { Vehiclemycar =newVehicle(); mycar.spd = 0; mycar.producer = "BMW"; mycar.model = "X6"; mycar.pyear = 2011; mycar.km = 10000; Console.WriteLine("producer: " + mycar.producer + " model:" + mycar.model); mycar.increasespd(); mycar.increasespd(); mycar.decreasespd(); Console.WriteLine("your speed is: " + mycar.spd); Console.ReadLine(); } } }
Calculater usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; namespacecalc { classcalculater { public intcoll(int a, int b) { return a + b; } publicintsub(int a, int b) { return a - b; } publicintdiv(int a, int b) { return a / b; } publicintmul(int a, int b) { return a * b; } } }
Program.cs usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; namespacecalc { class Program { staticvoidMain(string[] args) { calculaterclc = newcalculater(); Console.WriteLine("x number:"); int x = Convert.ToInt16(Console.ReadLine()); Console.WriteLine("y number:"); int y = Convert.ToInt16(Console.ReadLine()); Console.WriteLine("x+y=:"+ clc.coll(x,y)); Console.WriteLine("x-y=:" + clc.sub(x,y)); if (y == 0) Console.WriteLine("the result is undefined"); else Console.WriteLine("x/y=:" + clc.div(x,y)); Console.WriteLine("x*y=:" + clc.mul(x,y)); Console.ReadLine(); } } }
Matrix usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; namespacematrix { class matris { public int[,] matrs = new int[3, 3]; publicvoidmatrisal(){ int i,j; for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { matrs[i,j] = Convert.ToInt16(Console.ReadLine()); } } } } }
Program.cs usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; namespace uyg3 { class Program { staticvoidMain(string[] args) { matris dizi1 = new matris(); matris dizi2 = new matris(); Console.WriteLine(“firstmatrix"); dizi1.matrisal(); Console.WriteLine(“secondmatrix"); dizi2.matrisal(); Console.ReadLine(); } } }
HOMEWORK Taketwomatrixfromtheuserusingthematrixclassandprogram Then Describe a newclassnamed as “calc” it calculatessumanddifference of thematrices
Randomclass private void button1_Click(object sender, EventArgs e) { Randomrnd = newRandom(); intrastt = rnd.Next(1, 5); listBox1.Items.Add(rastt.ToString()); } private void button2_Click(object sender, EventArgs e) { doublea = Convert.ToDouble(listBox1.SelectedItem); if (a % 2 == 0) even.Items.Add(Convert.ToString(a)); else odd.Items.Add(Convert.ToString(a)); }
HOMEWORK • Write a classbelongstofollow: • Describe an arrayits size=listbox.ıtems.count • Describe a function as named “sort” • Thefunctionsorts of thearray