1 / 28

program

jjhgvjhvfgherhuijjinnnnnnh

eliani47
Download Presentation

program

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. SSK 1013-ASAS PENGATURCARAAN TOPIK 2 & 3 : PEMBOLEHUBAH, JENIS DATA DAN OPERATOR ARITMETIK ANIS ELIANI BINTI ABDUL RAHMAN

  2. C# adalahbahasapengaturcaraan yang berorientasikanobjek. • MUDAHuntukdipelajari.

  3. RUANGAN PENGISTIHARAN (DECLARATION) • CLASS • CLASS METHODS • CLASS ATTRIBUTES • MAIN METHOD • STATEMENTS & EXPRESSIONS • COMMENTS STRUKTUR ASAS PENGATURCARAAN C#

  4. KOMEN /PENERANGAN HEADER : PREPROCESSOR RUANG PROGRAM CLASSS PROGRAM KOMEN /PENERANGAN STRUKTUR ASAS PROGRAM

  5. PEMBOLEHUBAH

  6. Pembolehubahadalahsalahsatujenispengecam. • Pembolehubahadalahpengecam yang nilainyabolehberubahsemasaperlaksanaanaturcara. • Iamestidiisytiharkansebelumbolehdigunakan. • Contohpengisytiharanpembolehubah: • int x; • float balance; • char ch; • int y; • Bolehdigabungkanjikamempunyaijenis data yang sama: • intx, y, z; • char ch, chr; • float f, balance; PEMBOLEHUBAH

  7. Contohpengisytiharanpembolehubah: int x; doublebalance; charch; int y; Bolehdigabungkanjikamempunyaijenis data yang sama: int x, y, z; char ch, chr; double f, balance; PEMBOLEHUBAH

  8. PERATURAN MENAMAKAN • Panjangaksaradari 1 hingga 255 aksara • Bolehterdiridaripadahuruf & digit • Tidakbolehterdiridaripadaruangkosongdanperkataaanrizab/khasataukeyword. keywordadalahperkataan yang sudahmempunyaifungsi-fungsitertentudanbukan variable. •  Nama yang bermaknadanmudah • Nombor, underscore atausimboltidakdibenarkansebelum variable. Jarakantara variable dengan variable juga tidakdibenarkan. • Setiap variable mestilahbermuladarihurufbarulahbolehdiletakkannombordan underscore. PEMBOLEHUBAH

  9. Naming Variables – Examples Proper names: -     name -     first_Name -     name2 Improper names (will lead to compilation error): -     1 (digit) -     if (keyword) -     2name(starts with a digit) PEMBOLEHUBAH

  10. Contohnama yang sesuaiuntukpembolehubah -    noPertama -    umur -    nama_pelajar -    NoKedua PEMBOLEHUBAH

  11. And here are some examples for badly named variables (although the names are correct from the C# compiler’s perspective): -     _firstName (starts with _) -     last_name (contains _) -     AGE (is written with capital letters) -     Start_Index (starts with capital letter and contains _) -     lastNegativeNumber_Index (contains _) -     a37 (the name is not descriptive and does not clearly provide the purpose of the variable) -     fullName23, fullName24, etc. (it is not appropriate for a variable name to contain digits unless that would improve variable use clarity) PEMBOLEHUBAH

  12. JENIS-JENIS DATA

  13. NILAI TETAP /CONSTANT • The constants refer to fixed values that the program may not alter during its execution. These fixed values are also called literals. • Constants can be of any of the basic data types like an integer constant, a floating constant, a character constant, or a string literal. • The constants are treated just like regular variables except that their values cannot be modified after their definition. • Constants are defined using the const keyword. Syntax for defining a constant is: • const<data_type> <constant_name> = value; • EXAMPLE : constdouble pi = 3.14159;

  14. OPERATOR ARITMETIK (+, -, *, /) • Assume variable A holds 10 and variable B holds 20 then:

  15. OPERATOR PRECEDENCE • KEUTAMAAN PROSES MENGIKUT OPERATOR • Operator precedence determines the grouping of terms in an expression. This affects evaluation of an expression. • Certain operators have higher precedence than others; for example, the multiplication operator has higher precedence than the addition operator. • For example x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has higher precedence than +, so the first evaluation takes place for 3*2 and then 7 is added into it.

  16. OPERATOR PRECEDENCE KEUTAMAAN PROSES MENGIKUT OPERATOR So, 7 + 3 * 2 = ?

  17. ASSIGNMENT / UMPUKAN • Cara yang paling lazimdigunakanuntukmendapatkannilaipembolehubahadalahdenganmenggunakanumpukan. • Tanda‘=’ disebutpengendaliumpukan. • Sintaks: • Variable_name= ungkapan; • Contoh : • name = "John Smith"; • age = 25;

  18. ASSIGNMENT OPERATORS

  19. CONTOH ATURCARA MENGGUNAKAN PELBAGAI JENIS DATA & OPERATOR ARITMETIK CONTOH SOALAN : KIRA HASIL TAMBAH, TOLAK, DARAB DAN BAHAGI BAGI 2 NOMBOR

  20. ATURCARA CONSOLE

  21. OUTPUT

  22. ATURCARA MENGGUNA WPF

  23. KOD ATURCARA UNTUK BUTANG TAMBAH

  24. private void Button_Click_1(object sender, RoutedEventArgs e) { int nombor1; int nombor2; inthasil; nombor1 = int.Parse(nilai1.Text); nombor2 = int.Parse(nilai2.Text); hasil = nombor1 + nombor2; result.Text = ("Hasiltambahialah ") + hasil; }

  25. SEKIAN....

More Related