-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmember_fungsi_kelas.cpp
More file actions
104 lines (84 loc) · 1.74 KB
/
member_fungsi_kelas.cpp
File metadata and controls
104 lines (84 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// 1. deklarasi
// - member function dideklarasikan di dalam definisi kelas
// - bisa dideklarasikan di bagian modifikasi akses -> public, private,
// protected
// 2. definisi -> inline function :: <- scope resolution
// 3. aksebilitas
//
// 1. inline
// 2. outline
// 3. static member function
// 4. const member function
// 5. friend function
#include <iostream>
#include <string>
/**
class Mobil {
public:
std::string nama;
void tampilkanInformasiMobil() {
std::cout << "nama mobil: " << nama << std::endl;
}
};
**/
/**
class Orang {
public:
std::string nama;
void tampilkanNama();
};
void Orang::tampilkanNama() {
std::cout << "nama: " << nama << std::endl;
}
**/
/**
class Hitung {
private:
static int hitung_angka;
public:
static void tambahkan() {
hitung_angka++;
}
static void tampilkanHitung() {
std::cout << "hitung: " << hitung_angka << std::endl;
}
};
int Hitung::hitung_angka = 0;
**/
/**
class Mobil {
private:
std::string nama;
int tahun_keluaran;
public:
Mobil(std::string n, int t) : nama(n), tahun_keluaran(t) {}
void tampilkanInfo() const {
std::cout << "nama mobil: " << nama << std::endl;
std::cout << "tahun keluaran: " << tahun_keluaran << std::endl;
}
};
**/
/**
class Kotak {
private:
double lebar;
public:
Kotak(double l) : lebar(l) {}
friend void tampilkanInfoKotak(const Kotak &k);
};
void tampilkanInfoKotak(const Kotak &k) {
std::cout << "lebar kotak adalah " << k.lebar << std::endl;
}
**/
class Mobil {
private:
std::string nama;
public:
Mobil(std::string n) : nama(n) {}
void tampilkanInfo() { std::cout << "nama mobil: " << this->nama << std::endl; }
};
int main() {
Mobil mobil_pertama("Ferrari");
mobil_pertama.tampilkanInfo();
return 0;
}