-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstructor.cpp
More file actions
78 lines (67 loc) · 1.71 KB
/
constructor.cpp
File metadata and controls
78 lines (67 loc) · 1.71 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
// 1. nama constructor adalah sama denga nama kelas
// 2. tidak memiliki return,termasuk void
// 3. dapat menerima parameter
// 4. dipanggil secara otomatis saat si object dibuat
// jenis constructor
// - default constructor
// - parameterized constructor
// - copy constructor
#include <iostream>
#include <string>
/**
class Mobil {
public:
std::string nama;
int tahun_keluaran;
Mobil() {
nama = "Ferrari";
tahun_keluaran = 2024;
std::cout << "default constructor dibuat" << std::endl;
}
void tampilkanInformasiMobil() {
std::cout << "nama mobil: " << nama << std::endl;
std::cout << "tahun keluaran: " << tahun_keluaran << std::endl;
}
};
**/
/**
class Siswa {
public:
std::string nama;
int kelas;
Siswa(std::string n, int k) {
nama = n;
kelas = k;
std::cout << "parameter constructor dibuat" << std::endl;
}
void tampilkanInfoSiswa() {
std::cout << "nama: " << nama << std::endl;
std::cout << "kelas: " << kelas << std::endl;
}
};
**/
class youtubeProgramming {
public:
std::string nama_channel;
int kode_channel;
youtubeProgramming(std::string n, int k) {
nama_channel = n;
kode_channel = k;
}
youtubeProgramming(const youtubeProgramming &objek) {
nama_channel = objek.nama_channel;
kode_channel = objek.kode_channel;
std::cout << "copy constructor dipanggil" << std::endl;
}
void tampilkanInfo() {
std::cout << "nama channel: " << nama_channel << std::endl;
std::cout << "kode channel: " << kode_channel << std::endl;
}
};
int main() {
youtubeProgramming youtube_pertama("wpu", 711);
youtubeProgramming youtube_kedua = youtube_pertama;
youtube_pertama.tampilkanInfo();
youtube_kedua.tampilkanInfo();
return 0;
}