-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathBai49.cpp
141 lines (117 loc) · 2.59 KB
/
Bai49.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
Tính đóng gói dữ liệu: các thành phần public
*/
#include <iostream>
#include <cstring>
using namespace std;
class Student {
private:
char ID[20];
char name[100];
int age;
float mark;
char address[100];
public:
Student();
Student(char*);
Student(char*, int);
Student(char*, int, char*, char*, float);
void showInfo();
void setID(char*);
void setName(char*);
void setAddress(char*);
void setAge(int);
void setMark(float);
int getAge();
float getMark();
char* getName();
char* getAddress();
char* getID();
};
Student::Student() {
cout << "Call non para constructor" << endl;
this->name[0] = '\0';
this->address[0] = '\0';
this->ID[0] = '\0';
this->age = 0;
this->mark = 0;
}
Student::Student(char* name) {
cout << "Call 1 para constructor" << endl;
strcpy_s(this->name, 99, name);
this->address[0] = '\0';
this->ID[0] = '\0';
this->age = 0;
this->mark = 0;
}
Student::Student(char* name, int age) {
cout << "Call 2 params constructor" << endl;
strcpy_s(this->name, 99, name);
this->address[0] = '\0';
this->ID[0] = '\0';
this->age = age;
this->mark = 0;
}
Student::Student(char* name, int age, char* id, char* address, float mark) {
cout << "Call 5 params constructor" << endl;
strcpy_s(this->name, 99, name);
strcpy_s(this->ID, 19, id);
strcpy_s(this->address, 99, address);
this->age = age;
this->mark = mark;
}
void Student::setID(char* id) {
strcpy_s(this->ID, 19, id);
}
void Student::setName(char* name) {
strcpy_s(this->name, 99, name);
}
void Student::setAddress(char* addr) {
strcpy_s(this->address, 99, addr);
}
void Student::setAge(int age) {
this->age = age;
}
void Student::setMark(float mark) {
this->mark = mark;
}
int Student::getAge() {
return this->age;
}
float Student::getMark() {
return this->mark;
}
char* Student::getName() {
return this->name;
}
char* Student::getAddress() {
return this->address;
}
char* Student::getID() {
return this->ID;
}
void Student::showInfo() {
cout << "============== Student Info ===========" << endl;
cout << "Name: " << name << endl;
cout << "Address: " << address << endl;
cout << "Id: " << ID << endl;
cout << "Age: " << age << endl;
cout << "Mark: " << mark << endl;
cout << "=======================================" << endl;
}
int main() {
char* name = new char[100];
strcpy_s(name, 99, "Tran Van Hung");
char* id = new char[20];
strcpy_s(id, 19, "B21DCCN123");
char* addr = new char[100];
strcpy_s(addr, 99, "Hanoi");
Student s, s1, s2, s3, s4; // goi ham tao 0 tham so
s.setAge(20);
s1.setName(name);
s2.setAddress(addr);
s3.setMark(7.5);
s.setID(id);
s.showInfo();
return 0;
}