bala bala

18
 Menulis Program C++ Pertama Anda

Upload: ascopvt

Post on 05-Oct-2015

223 views

Category:

Documents


0 download

DESCRIPTION

bala bala

TRANSCRIPT

  • Menulis Program C++ Pertama Anda

  • Memahami Konsep C++

    Penggunaan C++, begitu menyebar cepat sekali. Hampir semua program yang dibuat untuk PC memakai bahasa C++.

    Contoh : Sistem Operasi Windows, Linux, Microsoft Office, OpenOffice.

  • Apa itu Program ?

    Sebuah Program C++ adalah sebuah file teks yang berisikan serangkaian perintah C++ yang diletakkan bersamaan menurut aturan grammar C++.

    Ekstensi file C++ .cpp

    Seperti Microsoft Word .doc

    Batch MS DOS .bat

  • Tujuan Pemrograman C++ adalah untuk menuliskan serangkaian perintah yang dapat dikonversikan ke dalam bahasa mesin.

  • Bagaimana caranya saya memprogram ?

    Dibutuhkan 2 program :

    - Sebuah editor untuk menulis source code file .cpp

    - Sebuah compiler yang mengkonversikan ke dalam bahasa mesin (.exe)

    Tool Environment :

    - Visual C++ .net ($250)

    - Dev-C++ (Free) www.bloodshed.net

  • Installing Dev-C++

    Klik 2x file devcpp4980.exe

    Klik Next

    Default directory, c:\dev-cpp

    Space HardDisk harus cukup untuk menginstall program

    Klik Install

    Klik Close

  • Setting the Options

    Pilih Tools Compiler Options

    Choose the Settings tab

    Choose Code Generation from the menu on the left, pastikan Enable Exception Handling telah enabled

    Choose linker and pastikan Generate Debugging Information telah enabled

    Klik OK

  • Membuat Program C++ Pertama Anda Memasukkan Code C++

    Klik Start Programs Bloodshed Dev-C++ Dev-C++

    Pilih File New Source File

    Tuliskan Program Berikut :

  • //

    // Program untuk mengkonversi temperatur suhu dari derajat Celcius

    // ke satuan derajar Fahrenheit

    // Fahrenheit = Celsius * (212 - 32)/100 + 32

    //

    #include

    #include

    #include

    using namespace std;

    int main(int nNumberofArgs, char* pszArgs[])

    {

  • // Masukkan temperatur dalam satuan celcius

    int celsius;

    cout > celsius;

    // Menghitung faktor konversi celcius

    // ke fahrenheit

    int factor;

    factor = 212 - 32;

    // menggunakan faktor konversi untuk mengubah

    // Celcius ke nilai Fahrenheit

    int fahrenheit;

    fahrenheit = factor * celsius/100 + 32;

  • // Output Hasil

    cout

  • Pilih Save As dibawah menu File. Dan ketikkan nama program lalu tekan Enter.

  • Building Your Program

    Pilih Execute Compile dari menu atau tekan F9

  • Mengeksekusi Program

    Klik Execute Run atau tekan Ctrl-F10.

    Setelah di eksekusi akan tampil :

    Enter the temperature in Celsius:100

    Fahrenheit value is:212

    Press any key to continue . . .

  • Format Dasar Program C++

    //

    // Template - provides a template to be used as the starting

    // point

    //

    // the following include files define the majority of

    // functions that any given program will need

    #include

    #include

    #include

    using namespace std;

    int main(int nNumberofArgs, char* pszArgs[])

    {

    // your C++ code starts here

    // wait until user is ready before terminating program

    // to allow the user to see the program results

    system(PAUSE);

    return 0;

    }

  • Komentar C++

    Sebuah komentar C++ di awali dengan tanda double slash (//)

  • Menuliskan Deklarasi

    Contoh : int nCelsius

  • Membangkitkan Output

    Line yang diawali dengan cout dan cin dikenal sebagai statemen input/output (I/O Statements)

    First I/O Statements Enter the temperature in Celsius to cout

    Baris berikutnya Extract nilai dari device input C++ and store kan ke variabel integer Celscius