-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkelas_objek.cpp
More file actions
54 lines (46 loc) · 1.14 KB
/
kelas_objek.cpp
File metadata and controls
54 lines (46 loc) · 1.14 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
// class NamaDariKelas {
// .. akses modifikasi, public, private, proctected
// .. data member (attribut)
// .. member function (metode)
// };
#include <iostream>
#include <string>
/**
class Mobil {
public:
std::string merek_mobil;
int tahun_keluaran;
void displayInfoMobil() {
std::cout << "Merek mobil: " << merek_mobil << std::endl;
std::cout << "Tahun keluaran mobil: " << tahun_keluaran << std::endl;
}
};
**/
class Orang {
public:
std::string nama;
int tahun_lahir;
int tahun_sekarang;
void tampilkanUmurSekarang() {
std::cout << "umur kamu sekarang adalah " << tahun_sekarang - tahun_lahir << std::endl;
}
};
int main() {
/**
Mobil mobil_pertama;
Mobil mobil_kedua;
mobil_pertama.merek_mobil = "Mclaren";
mobil_pertama.tahun_keluaran = 2024;
mobil_pertama.displayInfoMobil();
std::cout << std::endl;
mobil_kedua.merek_mobil = "ferrari";
mobil_kedua.tahun_keluaran = 2023;
mobil_kedua.displayInfoMobil();
**/
Orang orang_pertama;
orang_pertama.tahun_lahir = 1998;
orang_pertama.tahun_sekarang = 2024;
orang_pertama.nama = "rizki";
orang_pertama.tampilkanUmurSekarang();
return 0;
}