-
Notifications
You must be signed in to change notification settings - Fork 0
/
Class Student.cpp
104 lines (84 loc) · 1.75 KB
/
Class Student.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <iostream>
using namespace std;
class Student
{
private:
int id;
string name;
public:
int getId();
void setId(int);
string getName();
void setName(string);
void displayStudent() const;
void hitungTotal();
//constructor
Student(); //default constructor
Student(string);
Student(int, string); // constructor with parameter.
};
void Student::setId(int xid)
{
this->id = xid;
}
int Student::getId()
{
return this->id;
}
void Student::setName(string nm)
{
this->name = nm;
}
string Student::getName()
{
return this->name;
}
void Student::displayStudent() const
{
cout << this->id << "\t" << name << endl;
}
Student::Student() //default constructor
{
this->id = 0;
this->name = "";
}
Student::Student(int xid, string xname) //default constructor
{
this->id = xid;
this->name = xname;
}
int main()
{
cout << "Application started." << endl;
Student s1;
s1.setId(100);
s1.setName("Affan");
s1.displayStudent();
Student s2;
s2.setId(101);
s2.setName("Bunny");
s2.displayStudent();
Student s3;
s3 = s2;
s3.displayStudent();
//Contoh pass by reference
Student s4;
int xid = 200;
string nm = "Elisa";
s4.setId(xid);
s4.setName(nm);
s4.displayStudent();
s4.setName("Elisa Thomson");
cout << s4.getName() << endl;
Student s5(105, "Farrah");
s5.displayStudent();
//contoh membuat srray dari objek student
Student list_of_students[100];
cout << "\n" << endl;
}
// 1.
// An empty space; a vacuum.
// 2.
// astronomy An extended region of space containing no galaxies
// 3.
// materials science A collection of adjacent vacancies inside a crystal lattice.