1 / 10

OOP

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 ;

Download Presentation

OOP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OOP C# ile basit sınıf uygulamaları

  2. 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); } } }

  3. 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(); } } }

  4. 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; } } }

  5. 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(); } } }

  6. 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()); } } } } }

  7. 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(); } } }

  8. HOMEWORK Taketwomatrixfromtheuserusingthematrixclassandprogram Then Describe a newclassnamed as “calc” it calculatessumanddifference of thematrices

  9. 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)); }

  10. HOMEWORK • Write a classbelongstofollow: • Describe an arrayits size=listbox.ıtems.count • Describe a function as named “sort” • Thefunctionsorts of thearray

More Related