Skip to content

Commit d72a29f

Browse files
committed
Add C++ programming language
1 parent 378865e commit d72a29f

16 files changed

+571
-0
lines changed
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
C/C++ Code Template
3+
Archive of Reversing.ID
4+
Programming Language (C++)
5+
*/
6+
7+
/*
8+
Deklarasikan header file (module) yang ingin disertakan.
9+
Header file umumnya berisi deklarasi konstanta, struct / class, serta prototipe fungsi.
10+
*/
11+
#include <iostream>
12+
13+
/*
14+
Definisikan fungsi main().
15+
Fungsi main() adalah entry point atau fungsi pertama (user-code) yang akan dijalankan
16+
ketika aplikasi dijalankan.
17+
*/
18+
int main(int argc, char* argv[])
19+
{
20+
// letakkan kode di sini
21+
22+
23+
// return value, status yang dikembalikan oleh program ke OS ketika eksekusi berakhir.
24+
return 0;
25+
}
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Declaration
3+
Archive of Reversing.ID
4+
Programming Language (C++)
5+
6+
Deklarasi berbagai tipe data dasar
7+
*/
8+
9+
int main(int argc, char* argv[])
10+
{
11+
// deklarasi variabel dan konstanta
12+
// tipe data: integral = char, int, long
13+
// float = float, double
14+
15+
// -- definisi bilangan bulat
16+
short s;
17+
int i;
18+
long l;
19+
20+
// -- definisi bilangan pecahan (floating-point)
21+
float f;
22+
double d;
23+
24+
// variabel vs konstanta
25+
int i_var;
26+
int i_var2, i_var3;
27+
const int X = 10;
28+
const int Y = 15, Z = 20;
29+
30+
// memungkinkan untuk assign ulang ke variable tapi tidak ke konstanta
31+
i_var = 1;
32+
i_var3 = i_var2 = i_var;
33+
34+
35+
return 0;
36+
}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Switch
3+
Archive of Reversing.ID
4+
Programming Language (C++)
5+
6+
Statement Switch untuk pencocokan majemuk.
7+
*/
8+
9+
#include <iostream>
10+
11+
int main(int argc, char* argv[])
12+
{
13+
// definisi variabel lokal
14+
int grade = 'B';
15+
16+
switch (grade)
17+
{
18+
case 'A':
19+
std::cout << "Excellent" << std:: endl;
20+
break;
21+
case 'B':
22+
case 'C':
23+
std::cout << "Well done" << std:: endl;
24+
break;
25+
case 'D':
26+
std::cout << "You passed" << std:: endl;
27+
break;
28+
case 'F':
29+
std::cout << "Better try again" << std:: endl;
30+
break;
31+
default:
32+
std::cout << "Invalid grade" << std:: endl;
33+
}
34+
35+
std::cout << "Your grade is : " << grade << std::endl;
36+
37+
return 0;
38+
}

Codes/Language/c++/basic/11.for.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Foor
3+
Archive of Reversing.ID
4+
Programming Language (C++)
5+
6+
Statement For untuk perulangan.
7+
*/
8+
9+
#include <iostream>
10+
11+
int main(int argc, char* argv[])
12+
{
13+
int a;
14+
15+
// perulangan dengan pencacahan
16+
for (a = 10; a < 20; a = a + 1)
17+
{
18+
std::cout << "Value of a: " << a << std::endl;
19+
}
20+
21+
return 0;
22+
}

Codes/Language/c++/basic/12.while.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
While
3+
Archive of Reversing.ID
4+
Programming Language (C++)
5+
6+
Statement While untuk perulangan.
7+
*/
8+
#include <stdio.h>
9+
10+
int main(int argc, char* argv[])
11+
{
12+
int a = 10;
13+
14+
while (a < 20)
15+
{
16+
std::cout << "Value of a: " << a std::endl;
17+
18+
// increment a, perubahan nilai sehingga mendekati kondisi henti
19+
a++;
20+
}
21+
22+
return 0;
23+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Do-While
3+
Archive of Reversing.ID
4+
Programming Language (C++)
5+
6+
Statement Do-While untuk perulangan.
7+
*/
8+
#include <iostream>
9+
10+
int main(int argc, char* argv[])
11+
{
12+
int a = 10;
13+
14+
do
15+
{
16+
std::cout << "Value of a: " << a << std::endl;
17+
18+
// increment a, perubahan nilai sehingga mendekati kondisi henti
19+
a++;
20+
} while (a < 20);
21+
22+
return 0;
23+
}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Function
3+
Archive of Reversing.ID
4+
Programming Language (C++)
5+
6+
Fungsi sebagai potongan kode.
7+
*/
8+
#include <stdio.h>
9+
10+
int max(int num1, int num2)
11+
{
12+
// deklarasi variabel lokal yang dibutuhkan
13+
int result;
14+
15+
// operasi sebuah fungsi
16+
if (num1 > num2)
17+
result = num1;
18+
else
19+
result = num2;
20+
21+
// kembalikan nilai yang sesuai
22+
return result;
23+
}
24+
25+
int main(int argc, char* argv[])
26+
{
27+
// deklarasi variabel dan isi dengan nilai dari kembalian fungsi
28+
int a = max(3, 5);
29+
int b = max(7, 10);
30+
31+
std::cout << "max(3, 5) = " << a << std::endl;
32+
std::cout << "max(7,10) = " << b << std::endl;
33+
34+
return 0;
35+
}
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
String
3+
Archive of Reversing.ID
4+
Programming Language (C++)
5+
6+
Representasi String
7+
*/
8+
9+
#include <cstring>
10+
11+
/*
12+
Terdapat dua tipe string di C++:
13+
- C-Style
14+
- C++ String class
15+
16+
Pada C-Style, string diimplementasikan sebagai array of character dengan
17+
0 atau \0 sebagai batas akhir string.
18+
19+
Pada C++ String class, terdapat sebuah class yang merepresentasikan string
20+
dengan operasinya (akan dibahas pada class).
21+
*/
22+
23+
int main(int argc, char* argv[])
24+
{
25+
// C-Style string, deklarasi array dengan karakter tiap elemennya
26+
char str1[] = {'R', 'e', 'v', 'e', 'r', 's', 'i', 'n', 'g', '.', 'I', 'D', 0};
27+
char str2[] = "Programming";
28+
char str3[32];
29+
30+
// C++ String class
31+
std::string str4 = "Reversing.ID";
32+
std::string str5 = "Programming";
33+
std::string str6;
34+
35+
// -- Operasi C-Style string
36+
// copy
37+
strcpy(str3, str1);
38+
39+
// concatenation
40+
strcat(str3, str1);
41+
42+
43+
// -- Operasi C++ String class
44+
// copy
45+
str6 = str4;
46+
47+
// concatenation
48+
str6 += str5;
49+
50+
return 0;
51+
}

Codes/Language/c++/basic/2.array.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Array
3+
Archive of Reversing.ID
4+
Programming Language (C++)
5+
6+
Sifat dan penggunaan array.
7+
*/
8+
9+
#include <iostream>
10+
11+
int main(int argc, char* argv[])
12+
{
13+
int plain [10];
14+
double assigned [10] = { 100.0, 2.0, 3.4, 7.0, 50.0 } ;
15+
16+
// assign value ke index 6 dari array "plain"
17+
plain [6] = 10;
18+
19+
std::cout << "plain[0] = " << plain[0] << std::endl;
20+
std::cout << "plain[6] = " << plain[6] << std::endl;
21+
std::cout << "assigned[0] = " << assigned[0] << std::endl;
22+
std::cout << "assigned[6] = " << assigned[6] << std::endl;
23+
24+
// assign value ke index 6 dari arrai "assigned"
25+
assigned[6] = 3.14;
26+
27+
std::cout << "assigned[6] = " << assigned[6] << std::endl;
28+
29+
return 0;
30+
}

Codes/Language/c++/basic/3.struct.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Struct
3+
Archive of Reversing.ID
4+
Programming Language (C++)
5+
6+
Struct dan penggunaannya.
7+
*/
8+
9+
#include <iostream>
10+
#include <cstring>
11+
12+
13+
struct book_t
14+
{
15+
char title[50];
16+
char author[50];
17+
char subject[100];
18+
int book_id;
19+
};
20+
21+
22+
int main( )
23+
{
24+
book_t Book1; // Deklarasi Book1 dengan tipe Book
25+
book_t Book2; // Deklarasi Book2 dengan tipe Book
26+
27+
// spesifikasi book 1
28+
strcpy( Book1.title, "C/C++ Programming");
29+
strcpy( Book1.author, "Rakai Ady Wikradinata");
30+
strcpy( Book1.subject, "C Programming Tutorial");
31+
Book1.book_id = 6495407;
32+
33+
// spesifikasi book 2
34+
strcpy( Book2.title, "Little Playground of Reverse Engineering");
35+
strcpy( Book2.author, "Satria Ady Pradana");
36+
strcpy( Book2.subject, "Reverse Engineering Tutorial");
37+
Book2.book_id = 6495700;
38+
39+
// cetak informasi book 1
40+
std::cout << "Book 1 title : " << Book1.title << std::endl;
41+
std::cout << "Book 1 author : " << Book1.author << std::endl;
42+
std::cout << "Book 1 subject : " << Book1.subject << std::endl;
43+
std::cout << "Book 1 book_id : " << Book1.book_id << std::endl;
44+
45+
// cetak informasi book 2
46+
std::cout << "Book 2 title : " << Book2.title << std::endl;
47+
std::cout << "Book 2 author : " << Book2.author << std::endl;
48+
std::cout << "Book 2 subject : " << Book2.subject << std::endl;
49+
std::cout << "Book 2 book_id : " << Book2.book_id << std::endl;
50+
51+
return 0;
52+
}

Codes/Language/c++/basic/4.enum.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Enumeration
3+
Archive of Reversing.ID
4+
Programming Language (C++)
5+
6+
Enumerasi dan penggunaannya.
7+
*/
8+
9+
#include <iostream>
10+
11+
12+
enum month_t
13+
{
14+
Jan, Feb, Mar, Apr, May, Jun,
15+
Jul, Aug, Sep, Oct, Nov, Dec
16+
};
17+
18+
19+
int main(int argc, char* argv[])
20+
{
21+
month_t month;
22+
23+
month = Aug; // seharusnya bernilai 7
24+
25+
std::cout << "Month: " << month << std::endl;
26+
27+
// cetak semua bulan
28+
std::cout << "Month 'Jan' = " << Jan << std::endl;
29+
std::cout << "Month 'Feb' = " << Feb << std::endl;
30+
std::cout << "Month 'Mar' = " << Mar << std::endl;
31+
std::cout << "Month 'Apr' = " << Apr << std::endl;
32+
std::cout << "Month 'May' = " << May << std::endl;
33+
std::cout << "Month 'Jun' = " << Jun << std::endl;
34+
std::cout << "Month 'Jul' = " << Jul << std::endl;
35+
std::cout << "Month 'Aug' = " << Aug << std::endl;
36+
std::cout << "Month 'Sep' = " << Sep << std::endl;
37+
std::cout << "Month 'Oct' = " << Oct << std::endl;
38+
std::cout << "Month 'Nov' = " << Nov << std::endl;
39+
std::cout << "Month 'Dec' = " << Dec << std::endl;
40+
41+
42+
return 0;
43+
}

0 commit comments

Comments
 (0)