forked from thantrieu/LearnC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bai6.4E.c
129 lines (112 loc) · 2.54 KB
/
Bai6.4E.c
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
#include <stdio.h>
#include <string.h>
struct HoTen {
char ho[20];
char dem[20];
char ten[20];
};
struct DiemMH {
float toan;
float van;
float anh;
float tbc;
};
struct SinhVien {
int ma;
struct HoTen hoVaTen;
int tuoi;
char gioiTinh[10];
struct DiemMH diem;
};
void nhapDiem(struct DiemMH* diem) {
printf("Toan: ");
scanf("%f", &diem->toan);
printf("Van: ");
scanf("%f", &diem->van);
printf("Anh: ");
scanf("%f", &diem->anh);
diem->tbc = (diem->toan + diem->van + diem->anh) / 3;
}
void nhapHoTen(struct HoTen* ten) {
printf("Ho: ");
scanf("%s", ten->ho);
printf("Dem: ");
getchar();
gets(ten->dem);
printf("Ten: ");
scanf("%s", ten->ten);
}
struct SinhVien nhapSV() {
struct SinhVien sv;
printf("Nhap ma: ");
scanf("%d", &sv.ma);
nhapHoTen(&sv.hoVaTen);
printf("Tuoi: ");
scanf("%d", &sv.tuoi);
printf("Gioi tinh: ");
scanf("%s", sv.gioiTinh);
nhapDiem(&sv.diem);
return sv;
}
void hienThiTTSV(struct SinhVien sv) {
printf("%-10d %-10s %-20s %-10s %-10d %-10s %-10.2f %-10.2f %-10.2f %-10.2f\n",
sv.ma, sv.hoVaTen.ho, sv.hoVaTen.dem, sv.hoVaTen.ten, sv.tuoi, sv.gioiTinh,
sv.diem.toan, sv.diem.van, sv.diem.anh, sv.diem.tbc);
}
void sapXepTheoTen(struct SinhVien* ds, int slsv) {
int i, j;
for(i = 0; i < slsv - 1; i++) {
for(j = slsv - 1; j > i; j --) {
if(strcmp(ds[j].hoVaTen.ten, ds[j-1].hoVaTen.ten) < 0) {
struct SinhVien sv = ds[j];
ds[j] = ds[j - 1];
ds[j - 1] = sv;
}
}
}
}
void sapXepTheoDiem(struct SinhVien* ds, int slsv) {
int i, j;
for(i = 0; i < slsv - 1; i++) {
for(j = slsv - 1; j > i; j --) {
if(ds[j].diem.tbc > ds[j - 1].diem.tbc) {
struct SinhVien sv = ds[j];
ds[j] = ds[j - 1];
ds[j - 1] = sv;
}
}
}
}
void timTheoTen(struct SinhVien* ds, int slsv) {
char ten[20];
printf("Nhap ten: ");
scanf("%s", ten);
printf("%-10s %-10s %-20s %-10s %-10s %-10s %-10s %-10s %-10s %-10s\n",
"Ma SV", "Ho", "Dem", "Ten", "Tuoi", "Gioi Tinh",
"Diem Toan", "Diem Van", "Diem Anh", "Diem TBC");
int i, timSV = 0;
for(i = 0; i < slsv; i++) {
if(strcmp(ten, ds[i].hoVaTen.ten) == 0) {
hienThiTTSV(ds[i]);
timSV = 1;
}
}
if(timSV == 0) {
printf("Khong co sinh vien %s trong danh sach!\n", ten);
}
}
int main(){
struct SinhVien dssv[100];
int slsv = 0;
struct SinhVien sv;
sv = nhapSV();
dssv[slsv++] = sv;
printf("%-10s %-10s %-20s %-10s %-10s %-10s %-10s %-10s %-10s %-10s\n",
"Ma SV", "Ho", "Dem", "Ten", "Tuoi", "Gioi Tinh",
"Diem Toan", "Diem Van", "Diem Anh", "Diem TBC");
int i;
for(i = 0; i < slsv; i++) {
hienThiTTSV(dssv[i]);
}
return 0;
}