-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathQLTV.cpp
More file actions
182 lines (166 loc) · 3.83 KB
/
Copy pathQLTV.cpp
File metadata and controls
182 lines (166 loc) · 3.83 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include <bits/stdc++.h>
#define MAXN 300
#define MAXName 34
#define F(i,a,b) for(int i =a;i<=b;i++)
//----------------------------------------//
using namespace std;
int num=0;
struct members{
int ID;
char name[MAXName];
int age;
int groupID;
};
members member[MAXN];
//
//void addFile(){
// fprintf(f,"thanh vien thu %d :\n",num);
// fprintf(f,"%d\n",member[num].groupID);
// fprintf(f,"%d\n",member[num].ID);
// fprintf(f,"%d\n",member[num].age);
// fprintf(f,"%s\n",member[num].name);
//}
int findMember(int id){
for(int i =1;i<=num;i++){
if(member[i].ID == id)
return i;
}
}
bool checkID(int id){
for(int i = 1; i<=num;i++)
if(member[i].ID == id)
return false;
return true;
}
void addMenber(){
cout<<"NOTE: nhan -1 de ngung nhap!!"<<endl;
while(1){
int id;
num++;
while(1){
cout<<"Nhap ID:";
cin >>id;
if(id == -1){
num--;
return;
}
if(!checkID(id)){
cout<<"ID ban vua nhap vua bi trung!Hay nhap lai:"<<endl;
} else{
member[num].ID = id;
break;
}
}
cout<<"Nhap tuoi:";
cin >>member[num].age;
cout<<"Nhap nhom:";
cin >>member[num].groupID;
cout<<"Nhap ten:";
fflush(stdin);
gets(member[num].name);
}
}
void deleteMember(){
int id;
cout<<"Nhap ID:";
cin>> id;
int i = findMember(id);
if( i==0){
cout<<"thanh vien khong ton tai!"<<endl;
return;
}
for(int j = i+1 ;j<=num;j++){
member[j-1] = member[j];
}
num--;
}
void editMember(){
int id;
cout<<"Nhap ID:";
cin>> id;
int i = findMember(id);
if( i==0){
cout<<"thanh vien khong ton tai!"<<endl;
return;
}
cout<<"Cap nhat thong tin"<<endl;
cout<<"ID:" ;cin>>member[i].ID;
cout<<"Ten:" ;cin>>member[i].name;
cout<<"Tuoi:" ;cin>>member[i].age;
cout<<"Nhom:" ;cin>>member[i].groupID;
}
void printMember(){
int id;
cout<<"Nhap ID:";
cin>> id;
int i = findMember(id);
cout<<"============================="<<endl;
cout<<"ID :" <<member[i].ID << endl;
cout<<"Ten :" <<member[i].name << endl;
cout<<"Tuoi:" <<member[i].age << endl;
cout<<"Nhom:" <<member[i].groupID <<endl;
}
void printAllMember(){
cout<<"so thanh vien trong Doi la:"<<num<<endl;
printf("ID NAME AGE GROUP");
printf("\n");
for(int i =1;i<=num;i++){
printf("%6d%25s%6d%6d\n",member[i].ID,member[i].name,member[i].age,member[i].groupID);
}
}
void Quick_sort(int L,int R){
int i,j,pivot;
i = L;
j = R;
pivot = member[L+rand()%(R-L+1)].ID;
do{
while(member[i].ID<pivot) i++;
while(member[j].ID>pivot) j--;
if(i<=j){
swap(member[i],member[j]);
i++;j--;
}
}while( i<=j);
if(i<R) Quick_sort(i,R);
if(j>L) Quick_sort(L,j);
}
void SapXepID(){
cout<<"danh sach Thanh vien Theo ID tang dan!"<<endl;
Quick_sort(1,num);
printAllMember();
}
void Menu(){
cout<<"||---------------------------------------------||"<<endl;
cout<<"||>>>>>>>>>HE THONG QUAN LI THANH VIEN<<<<<<<<<||"<<endl;
cout<<"|| Them thanh vien moi : 1 || "<<endl;
cout<<"|| Xoa thanh vien cu : 2 ||"<<endl;
cout<<"|| Sua thong tin thanh vien : 3 ||"<<endl;
cout<<"|| In thanh vien Doi theo ID : 4 ||"<<endl;
cout<<"|| In tat ca thanh vien Doi : 5 ||"<<endl;
cout<<"|| Sap xep thanh vien theo ID : 6 ||"<<endl;
cout<<"||---------------------------------------------||"<<endl;
cout<<" ==> Nhan de chon chuc nang : ";
int option;
cin>>option;
switch(option){
case 1 : addMenber(); break;
case 2 : deleteMember(); break;
case 3 : editMember(); break;
case 4 : printMember();break;
case 5 : printAllMember();break;
case 6 : SapXepID();break;
default: cout<<"Vui long nhap lai!"<<endl;
}
}
int main(){
char ch;
do{
Menu();
cout<<"Ban muon tiep tuc hay thoat(Y/N):";
cin>>ch;
system("cls");
}while( ch =='Y'||ch =='y');
cout<<"Cam on ban da su dung ung dung"<<endl;
cout<<"----Copyright :Linhdzai--------";
return 0;
}