-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuts petruk.cpp
86 lines (69 loc) · 1.63 KB
/
uts petruk.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
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <string>
// Class Person
class Person {
private:
std::string name;
std::string address;
int age;
public:
std::string getName() {
return this->name;
}
std::string getAddress() {
return this->address;
}
int getAge () {
return this->age;
}
void setName (std::string newName) {
this->name = newName;
}
void setAddress (std::string newAddress) {
this->address = newAddress;
}
void setAge (int newAge) {
this->age = newAge;
}
};
/* swapInt
* desc : function that swap int value
* usage :
* int a = 50;
* int b = 10;
* swapInt(&a, &b);
* a == 10
* b == 50
*/
void swapInt(int *lhs, int *rhs) {
int tmp = *lhs;
*lhs = *rhs;
*rhs = tmp;
}
/* fungsi menghitung luas segitiga
*
*/
double luasSegitiga (double alas, double tinggi) {
return alas / 2 * tinggi;
}
using namespace std;
int main()
{
const char * str = "hello world"; // c string
int a = 100;
int b = 200;
cout << str << endl;
cout << "a = " << a << endl; // 100
cout << "b = " << b << endl; // 200
swapInt(&a, &b); // swap a and b
cout << "a = " << a << endl; // 200
cout << "b = " << b << endl; // 100
Person orangBaik;
orangBaik.setName("Siapa ya");
orangBaik.setAddress("dimana ya");
orangBaik.setAge(100);
cout << "Nama saya = " << orangBaik.getName() << endl;
cout << "Tinggal di = " << orangBaik.getAddress() << endl;
cout << "Umur saya = " << orangBaik.getAge() << endl;
return 0;
}