1 / 10

TYPE DATA , VARIABEL & KONSTANTA Dalam C++

TYPE DATA , VARIABEL & KONSTANTA Dalam C++. TIPE DATA. NAMA PENGENAL ( Identifier Name ).

shino
Télécharger la présentation

TYPE DATA , VARIABEL & KONSTANTA Dalam C++

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. TYPE DATA ,VARIABEL &KONSTANTA Dalam C++

  2. TIPE DATA

  3. NAMA PENGENAL (Identifier Name) adalahnama-nama yang ditentukansendiriolehpembuat program. yang nantinyanamatersebutdigunakandalampemrograman. Fungsinyauntukmenyatakan : Variabel, Tipe Data, Konstanta, Fungsi, Label danObyek. AturanPenamaanPengenal : • Karakterpertamaharushurufataugarisbawah. • Karakterberikutnyabolehhuruf, bilangan, ataugarisbawah. • Panjangmaksimal 32 karakter. • Namapengenaltidakbolehsamadengankatakunci (reserved word) • Pengenalbersifat case sensitif. • Hurufkecildanhurufbesar (kapital) padasuatupengenaltidakdianggapsama : Contoh : NAMA, Nama, nama = menyatakanpengenal yang berbeda.

  4. Contoh Penamaan Pengenal: ____________________________________________________________ BenarSalahalasanya ____________________________________________________________ Nama 2semester ( tidakbolehdiawaliangka ) NAMA nama-barang ( tanda – tidakdiperbolehkan ) Nama_barang #barang (simbol # tidakdiperbolehkan ) Kuartal_2 Namabarang ( tidakbolehmengandungspasi ) ____________________________________________________________

  5. Konstanta dan Variabel Konstanta Adalah suatu nilai yang sifatnya tetap. Deklarasi konstanta diawali dengan reserved word const. Bentuk penulisannya : Contoh : const phi=3.14 ; const nama-konstanta = nilai konstanta;

  6. #include <iostream.h> #include <conio.h> void main( ) { const float phi = 3.14285; float luas,keliling, jari_jari; cout << "MasukkanNilaiJari-jari? = ";cin >> jari_jari; luas = phi * jari_jari * jari_jari ; keliling = 2 * phi * jari_jari; clrscr(); cout << "HasilPerhitungan" << '\n'; cout <<"__________________" << '\n'<<'\n'; cout << "Luaslingkaran = " <<phi<<" x "<<jari_jari<<" x "<<jari_jari<<" = "<< luas << '\n'<< '\n'; cout << "Kelilinglingkaran = " << 2 <<" x "<<phi<<" x "<<jari_jari<<" = "<<keliling << '\n'; }

  7.  Variabel • adalahsuatupengenal yang digunakanuntukmenyimpansuatunilaidimananilaidarivariabeltersebutdapatberubah-ubahselamaproses program. • MendeklarasikanVariabel Variabelbelumdapatdigunakandidalam program sebelumdideklarasikanterlebihdahulu. Dengankata lain, deklarasivariabelharusdilakukanterlebihdahulusebelumvariabeltersebutdigunakan. Deklarasi Variabel ini meliputi : • tipe variabel, seperti : integer atau character • nama variabel itu sendiri. Bentuk penulisannya : • Contoh : intjumlah; floatrata_rata; char nama; Tipedata namavariabel;

  8. #include <iostream.h> #include <conio.h> void main() { intnilai; cout<<"MasukanNilaiPertama : "; cin>>nilai; cout<<"MasukanNilaiTerakhir : "; cin>>nilai; clrscr(); cout <<"Nilai yang Tersimpanadalah : "<<nilai <<'\n'; }

  9. #include <iostream.h> #include <conio.h> void main () { char NIM[8],Nama[25] ; intNilai_UTS, Nilai_UAS,Nilai_TUGAS ; float Nilai_Akhir ; cout << " Masukkan NIM :" ; cin >> NIM ; cout << " MasukkanNama :" ; cin>> Nama ; cout << " MasukkanNilai UTS :" ; cin >> Nilai_UTS ; cout << " MasukkanNilai UAS :" ; cin >> Nilai_UAS ; cout << " MasukkanNilai TUGAS :" ; cin >> Nilai_TUGAS ; Nilai_Akhir = (Nilai_UTS * 0.3 + Nilai_UAS * 0.5 + Nilai_TUGAS * 0.2) ; clrscr(); cout << "NIM : "<< NIM << endl ; cout << "NAMA : " << Nama << endl ; cout << "Nilai UTS : " << Nilai_UTS << endl ; cout << "Nilai UAS : "<< Nilai_UAS << endl ; cout << "Nilai TUGAS : "<< Nilai_TUGAS << endl ; cout << "Nilai AKHIR : "<<Nilai_Akhir <<endl ; }

  10. #include <iostream.h> #include <conio.h> void main() { intangka; char huruf; cout <<"MasukanSebuahHuruf :"; cin >> huruf; cout <<"MasukanSebuahangka (0 - 127):"; cin >> angka; clrscr(); cout <<"KODE ASCII" <<'\n'; cout <<"----------" <<'\n'; cout <<"Kode ASCII darihuruf " <<huruf <<" adalah = "<<int(huruf) <<'\n'; cout <<"Karakterdariangka " <<angka <<" adalah = "<<char(angka) <<'\n'; }

More Related