-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkelas_objek.cpp
More file actions
51 lines (38 loc) · 1.01 KB
/
kelas_objek.cpp
File metadata and controls
51 lines (38 loc) · 1.01 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
#include <iostream>
#include <string>
// attribut
// metode
// object
class Mobil {
private:
std::string merk;
int tahun_produksi;
std::string warna;
public:
Mobil(std::string merk_mobil, int tahun_mobil, std::string warna_mobil) {
merk = merk_mobil;
tahun_produksi = tahun_mobil;
warna = warna_mobil;
}
void nyalakan_mesin() {
std::cout << "mesin mobil " << merk << " hidup / menyala" << std::endl;
}
void klakson() {
std::cout << "bim bim dari mobil " << merk << std::endl;
}
void ingpo_mobil() {
std::cout << "merk mobil: " << merk << std::endl;
std::cout << "tahun produksi mobil: " << tahun_produksi << std::endl;
std::cout << "warna mobil: " << warna << std::endl;
}
};
int main() {
Mobil mobil_jaguar("jaguar sport x20", 2025, "hijau");
Mobil mobil_buggati("buggati xp450", 2025, "merah");
mobil_jaguar.ingpo_mobil();
mobil_jaguar.klakson();
mobil_jaguar.nyalakan_mesin();
std::cout << std::endl;
mobil_buggati.ingpo_mobil();
return 0;
}