-
Notifications
You must be signed in to change notification settings - Fork 1
/
2217051004_D_11.cpp
77 lines (62 loc) · 1.6 KB
/
2217051004_D_11.cpp
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
#include <iostream>
#include <string>
using namespace std;
class Toko {
private:
string nama_produk = "";
long long harga = 0;
string id_produk = "";
long long produk_terjual = 0;
long long stok = 0;
public:
Toko(string name, long long price, long long quantity) {
this->nama_produk = name;
this->harga = price;
this->stok = quantity;
this->id_produk = name.substr(0, 3);
}
void setNamaProduk(string newName) {
this->nama_produk = newName;
}
void setHarga(long long newHarga) {
this->harga = newHarga;
}
void setStok(long long newStok) {
this->stok = newStok;
}
string getNamaProduk() {
return this->nama_produk;
}
long long getHarga() {
return this->harga;
}
long long getStok() {
return this->stok;
}
void jual(long long sold) {
this->produk_terjual += sold;
this->stok -= sold;
}
void restok(long long newStock) {
this->stok += newStock;
}
void createId(string name) {
this->id_produk = name.substr(0, 3);
}
void printData() {
cout << "Nama Produk\t: " << this->nama_produk << endl;
cout << "Harga\t\t: Rp " << this->harga << endl;
cout << "ID Produk\t: " << this->id_produk << endl;
cout << "Produk Terjual\t: " << this->produk_terjual << endl;
cout << "Stok\t\t: " << this->stok << endl;
}
};
int main()
{
char nama_produk[] = "Sabun";
Toko p1(nama_produk, 10000, 10);
p1.restok(10);
p1.createId(nama_produk);
p1.jual(5);
p1.printData();
}