-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolimorfisme.cpp
More file actions
41 lines (34 loc) · 861 Bytes
/
polimorfisme.cpp
File metadata and controls
41 lines (34 loc) · 861 Bytes
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
// 1. statis
// 2. dinamis
//
// class Dasar {
// public:
// virtual void fungsi() {
// ...
// }
// }
//
// class turunan : public dasar {
// public:
// void display() override {
// ...
// }
// }
#include <iostream>
class OperasiMatematika {
public:
int add(int a, int b) { return a + b; }
double add(double a, double b) { return a + b; }
};
int main() {
OperasiMatematika op_matmatika;
int a = 20, b = 30;
double a_desimal = 20.3, b_desimal = 15.5;
std::cout << "penjumlahan bilangan bulat dari " << a << " dan " << b
<< std::endl;
std::cout << "hasilnya adalah: " << op_matmatika.add(a, b);
std::cout << "penjumlahan bilangan desimal dari " << a_desimal << " dan "
<< b_desimal << std::endl;
std::cout << "hasilnya adalah: " << op_matmatika.add(a_desimal, b_desimal);
return 0;
}