Program C++ Modul 4 – Kombinasi Operator Bagian II

Video Modul 4

Source Code:
/* Modul 4

Operator Aritmatika, Logika, Bitwise dan Ternary

Nama : Rizqia Wulan Sari

NIM : 49013098

Jurusan : TKJMD

==================================================*/

#include
<iostream>
//file header iostream

using
namespace std; //std namespace

int main() //fungsi utama

{

    int a, b, c, d, e, f, g, i; //deklarasi variabel bertipe integer

    cout << “=====================================\n”; //perintah output

    cout << ” Nama    : Rizqia Wulan Sari\n”; //perintah output

    cout << ” NIM    : 49013098\n”; //perintah output

    cout << “=====================================\n” << endl; //perintah output

    cout << ” Operator Aritmatika\n”; //perintah output

    cout << “=====================================\n”; //perintah output

    cout << ” Masukkan nilai a = “; //perintah output

    cin >> a; //perintah input nilai a

    cout << ” Masukkan nilai b = “; //perintah output

    cin >> b; //perintah input nilai b

    d = (a+b)%2; //inisialisasi nilai d = a ditambah b modulus 2

    cout << ” Nilai (a+b)%2 = “ << d << endl << endl; //perintah output nilai d

    cout << ” Operator Logika\n”; //perintah output

    cout << “=====================================\n”; //perintah output

    cout << ” Masukkan angka 1 atau 0 = “; //perintah output

    cin >> c; //perintah input nilai c

    cout << ” Nilai d = “ << d << endl; //perintah output

    cout << ” Nilai c && d = “ << (c&&d) << endl; //perintah output

    cout << ” Nilai c || d = “ << (c||d) << endl; //perintah output

    cout << ” Nilai !c = “ << !c << endl; //perintah output

    cout << ” Nilai !d = “ << !d << endl << endl; //perintah output

    cout << ” Operator Bitwise\n”; //perintah output

    cout << “=====================================\n”; //perintah output

    e = a*b; //inisialisasi nilai e = nilai a dikali dengan nilai b

    f = e >> 1; //inisialisasi nilai f = e shift right 1 (dibagi 2)

    i = e << 1; //inisialisasi nilai i = e shift left 1 (dikali 2)

    cout << ” Nilai e (axb) = “ << e << endl; //perintah output nilai e

    cout << ” Nilai “ << e << ” >> 1 = “ << f << endl; //perintah output nilai f

    cout << ” Nilai “ << e << ” << 1 = “ << i << endl << endl; //perintah output nilai i

    cout << ” Operator Ternary\n”; //perintah output

    cout << “=====================================\n”; //perintah output

    g = (a < b) ? a : b; //inisialisasi g dengan operator ternary untuk membandingkan angka

    cout << ” Angka yang terkecil adalah “ << g << endl << endl; //perintah output g

    return 0; //akhir dari fungsi main()

}

Hasil program:

 

Video tutorialnya:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s