forked from thantrieu/C-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBai51.cpp
157 lines (130 loc) · 5.93 KB
/
Bai51.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
Các thành phần static
*/
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
class Student {
private:
char ID[20];
char name[100];
int age;
float mark;
char address[100];
static int count;
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();
static int getCount();
static void setCount(int c);
};
int Student::count = 0;
int Student::getCount() {
return count;
}
void Student::setCount(int c) {
//age = c;
}
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;
count++;
}
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;
count++;
}
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;
count++;
}
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;
count++;
}
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
Student s5(name), s6(name, 20);
Student s7(name);
cout << s7.getCount() << endl;
cout << Student::getCount() << endl;
return 0;
}