11:51 PM
0


Pada postingan kali ini mencakup materi dari Modul IV mengenai Operator Bagian 2 yang diterapkan pada Bahasa pemrograman C++ dengan IDE Microsoft Visual Studio 2010.
Modul IV 4.1 (Operator Aritmatika)



Source Code
Coding
Source Code Pemrograman C++:
1.  //Modul 4-1
2.  //Operator Aritmatika
3.  //Nama     : Made Wahyu Sandika Purnama
4.  //NRP      : 49013019
5.   
6.  #include<iostream> //pemanggilan header iostream
7.   
8.  using namespace std; //deklarasi standard input output
9.   
10. int main() //fungsi utama bertipe integer
11. { //pembuka fungsi utama
12.     cout<<"Penggunaan Operator Aritmatika\n\n"; //output header program
13.     cout<<"2 + 3 = "<<2+3<<endl<<endl; //menampilkan hasil operasi pertambahan
14.     cout<<"10 - 5 = "<<10-5<<endl<<endl; //menampilkan hasil operasi pengutangan
15.     cout<<"4 x 3 = "<<4*3<<endl<<endl; //menampilkan hasil operasi perkalian
16.     cout<<"4 / 2 = "<<4/2<<endl<<endl; //menampilkan hasil operasi pembagian
17.     cout<<"10 % 3 = "<<10%3<<endl<<endl; //menampilkan hasil operasi modulus
18.     system("pause"); //menahan eksekusi program
19.     return 0; //akhir fungsi utama bertipe integer
20. } //penutup fungsi utama

Modul IV 4.2 (Operator Logika)



Source Code
Coding
Source Code Pemrograman C++:
1.  // Modul 4-2.cpp : Defines the entry point for the console application.
2.  // Operator Logika
3.  //Nama     : Made Wahyu Sandika Purnama
4.  //NRP      : 49013019
5.   
6.  #include "stdafx.h" //pemanggilan header stdafx yang digunakan khusus microsoft
7.  #include <iostream> //pemanggilan header iostream
8.   
9.  using namespace std; //deklarasi standard input output
10.  
11. int _tmain(int argc, _TCHAR* argv[]) //fungsi utama
12. { //pembuka fungsi utama
13.     cout<<"OPERASI OPERATOR LOGIKA\n\n"; //output header
14.     cout<<"Tabel Kebenaran Operator AND\n"; //output header
15.     cout<<"1 && 1 = "<<(1&&1)<<endl; //menampilkan hasil 1 and 1
16.     cout<<"1 && 0 = "<<(1&&0)<<endl; //menampilkan hasil 1 and 0
17.     cout<<"0 && 1 = "<<(0&&1)<<endl; //menampilkan hasil 0 and 1
18.     cout<<"0 && 0 = "<<(0&&0)<<endl<<endl; //menampilkan hasil 0 and 0
19.  
20.     cout<<"Tabel Kebenaran Operator OR\n"; //output header
21.     cout<<"1 || 1 = "<<(1||1)<<endl; //menampilkan hasil 1 or 1
22.     cout<<"1 || 0 = "<<(1||0)<<endl; //menampilkan hasil 1 or 0
23.     cout<<"0 || 1 = "<<(0||1)<<endl; //menampilkan hasil 0 or 1
24.     cout<<"0 || 0 = "<<(0||0)<<endl<<endl; //menampilkan hasil 0 or 0
25.  
26.     cout<<"Tabel Kebenaran Operator NOT\n"; //output header
27.     cout<<"!1 = "<<!1<<endl; //menampilkan hasil not 1
28.     cout<<"!0 = "<<!0<<endl<<endl; //menampilkan hasil not 0
29.     system("pause"); //menahan eksekusi program
30.     return 0; //akhir fungsi utama bertipe integer
31. } //penutup fungsi utama

Modul IV 4.3 (Operator Bitwise)



Source Code
Coding
Source Code Pemrograman C++:
1.  //Modul 4-3
2.  //Operator Bitwise
3.  //Nama     : Made Wahyu Sandika Purnama
4.  //NRP      : 49013019
5.   
6.  #include <iostream> //pemanggilan header iostream
7.   
8.  using namespace std; //deklarasi standard input output
9.   
10. int main() //fungsi utama bertipe integer
11. { //pembuka fungsi utama
12.     int u,v,w; //deklarasi variabel u,v,w bertipe integer
13.     u=1<<1; //inisialisasi variabel u
14.     v=1<<2; //inisialisasi variabel v
15.     w=1<<3; //inisialisasi variabel w
16.     cout<<"1 << 1 = "<<u<<endl; //menampilkan isi variabel u
17.     cout<<"1 << 2 = "<<v<<endl; //menampilkan isi variabel v
18.     cout<<"1 << 3 = "<<w<<endl<<endl; //menampilkan isi variabel w
19.  
20.     int x,y,z; //deklarasi variabel x,y,z bertipe integer
21.     x=16>>1; //inisialisasi variabel x
22.     y=16>>2; //inisialisasi variabel y
23.     z=16>>3; //inisialisasi variabel z
24.     cout<<"16 >> 1 = "<<x<<endl; //menampilkan isi variabel u
25.     cout<<"16 >> 2 = "<<y<<endl; //menampilkan isi variabel u
26.     cout<<"16 >> 3 = "<<z<<endl<<endl; //menampilkan isi variabel u
27.  
28.     int a=1; //deklarasi variabel a bertipe integer dan diisi nilai 1
29.     int b=0; //deklarasi variabel b bertipe integer dan diisi nilai 0
30.     cout<<"a = "<<a<<endl; //menampilkan isi variabel a
31.     cout<<"b = "<<b<<endl; //menampilkan isi variabel b
32.     cout<<"a & b = "<<(a&b)<<endl; //menampilkan hasil a and b
33.     cout<<"a | b = "<<(a|b)<<endl; //menampilkan hasil a or b
34.     cout<<"!a = "<<!a<<endl; //menampilkan hasil not a
35.     cout<<"!b = "<<!b<<endl; //menampilkan hasil not b
36.     cout<<"a ^ b = "<<(a^b)<<endl<<endl; //menampilkan hasil a xor b
37.     system ("pause"); //menahan eksekusi program
38.     return 0; //akhir fungsi utama bertipe integer
39. } //penutup fungsi utama

Modul IV 4.4 (Operator Ternary)



Source Code
Coding
Source Code Pemrograman C++:
1.  // Modul 4-4.cpp : Defines the entry point for the console application.
2.  //Operator Ternary
3.  //Nama     : Made Wahyu Sandika Purnama
4.  //NRP      : 49013019
5.   
6.  #include "stdafx.h" //pemanggilan header stdafx yang digunakan oleh microsoft
7.  #include <iostream> //pemanggilan header iostream
8.   
9.  using namespace std; //deklarasi standard input output
10.  
11. int _tmain(int argc, _TCHAR* argv[]) //fungsi utama bertipe integer
12. { //pembuka fungsi utama
13.     int x; //deklarasi variabel x bertipe integer
14.     cout<<"Masukkan Nilai x = "; //meminta inputan dari user
15.     cin>>x; //menyimpan nilai inputan dari user ke variabel
16.     cout<<"\n"; //membuat baris baru
17.  
18.     x = (x<0) ? -x : x; //kondisi menanyakan apakah inputan lebih besar dari 0, jika ya x dinegatifkan, jika tidak tetap diisi dengan nilai inputan
19.     cout<<"| x | = "<<x<<endl<<endl; //menampilkan hasil dari x
20.    
21.     system("pause"); //menahan eksekusi program
22.     return 0; //akhir fungsi utama bertipe integer
23. } //penutup fungsi utama

0 comments:

Post a Comment