0% found this document useful (0 votes)
3 views7 pages

Include

Uploaded by

lacminhtruong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

Include

Uploaded by

lacminhtruong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

#include <stdio.

h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>

struct NgayThangNam {
int ngay;
int thang;
int nam;
};

struct LopHoc {
int maLop;
char tenLop[100];
char lichHoc[10];
double hocPhi;
struct LopHoc* Next;
};

struct HocVien {
int maHocVien;
char hoLot[50];
char ten[50];
struct NgayThangNam ngaySinh;
int maLop;
double diem;
struct HocVien* Next;
};

struct lophoc {
LopHoc* Head;
LopHoc* Tail;
};

struct hocvien {
HocVien* Head;
HocVien* Tail;
};
LopHoc *createlophoc(int ma, char ten[], char lich[], double hocphi){
LopHoc *p = (struct LopHoc*)malloc(sizeof(struct LopHoc));
if (p == NULL){
printf("khong the cap phat node moi");
getch();
return NULL;
}
p->maLop = ma;
strcpy(p->tenLop, ten);
strcpy(p->lichHoc, lich);
p->hocPhi = hocphi;
p->Next = NULL;
return p;
}
HocVien *createhocvien(int ma, char hoLot[], char ten[], struct NgayThangNam
ngaySinh, int maLop, double diem){
HocVien *p = (struct HocVien*)malloc(sizeof(struct HocVien));
if (p == NULL){
printf("khong the cap phat node moi");
getch();
return NULL;
}
p->maHocVien = ma;
strcpy(p->hoLot, hoLot);
strcpy(p->ten, ten);
p->ngaySinh = ngaySinh;
p->maLop = maLop;
p->diem = diem;
p->Next = NULL;
return p;
}
void initlophoc(lophoc &lp){
lp.Head = NULL;
lp.Tail = NULL;
}
void inithocvien(hocvien &hv){
// khởi tạo danh sách rỗ ng
hv.Head = NULL;
hv.Tail = NULL;
}
int isEmptylophoc(lophoc lh){
if (lh.Head == NULL){
return 1;
}
else{
return 0;
}
}
int isEmptyhocvien(hocvien hv){
// kiểm tra danh sách rỗ ng
if (hv.Head == NULL){
return 1;
}
else{
return 0;
}
}
int themvaoLopHoc(lophoc &lh, LopHoc *p){
if (p == NULL){
return 0;
}
if (isEmptylophoc(lh) == 1){
lh.Head = p;
lh.Tail = p;
}
else{
p->Next = lh.Head;
lh.Head = p;
}
return 1;
}
int themvaoHocVien(hocvien &hv, HocVien *p){
if (p == NULL){
return 0;
}
if (isEmptyhocvien(hv) == 1){
hv.Head = p;
hv.Tail = p;
}
else{
p->Next = hv.Head;
hv.Head = p;
}
return 1;
}
void themLopHoc(lophoc &lh) {
int ma;
char ten[100];
char lich[10];
double hocphi;
printf("Nhap ma lop: ");
scanf("%d", &ma);
printf("Nhap ten lop: ");
scanf("%s", ten);
printf("Nhap lich hoc: ");
scanf("%s", lich);
printf("Nhap hoc phi: ");
scanf("%lf", &hocphi);

LopHoc *P = createlophoc(ma, ten, lich, hocphi);


if (themvaoLopHoc(lh, P) == 1)
printf("them vao thanh cong");
else printf("them vao khong thanh cong do khong du bo nho de cap phat");
}

void themHocVien(hocvien &hv) {


int ma;
char holot[50];
char ten[50];
int ngay, thang, nam;
int malop;
double diem;
printf("Nhap ma hoc vien: ");
scanf("%d", &ma);
printf("Nhap ho lot: ");
scanf("%s", holot);
printf("Nhap ten: ");
scanf("%s", ten);
printf("Nhap ngay sinh (ngay thang nam): ");
scanf("%d %d %d", &ngay, &thang, &nam);
NgayThangNam ngaysinh = { ngay, thang, nam };
printf("Nhap ma lop hoc vien: ");
scanf("%d", &malop);
printf("Nhap diem: ");
scanf("%lf", &diem);

HocVien *P = createhocvien(ma, holot, ten, ngaysinh, malop, diem);


if(themvaoHocVien(hv,P)==1)
printf("them vao thanh cong");
else printf("them vao khong thanh cong do khong du bo nho de cap phat");
}
void showlophoc(LopHoc *p){
printf("Ma lop: %d\n", p->maLop);
printf("Ten lop: %s\n", p->tenLop);
printf("Lich hoc: %s\n", p->lichHoc);
printf("Hoc phi: %.2f\n", p->hocPhi);
}
void showdanhsachlophoc(lophoc lh){
if (isEmptylophoc(lh) == 1){
printf("danh sach rong");
return;
}
LopHoc *P = lh.Head;
int i = 1;
while (P != NULL){
printf("Thong tin lop hoc thu %d:\n", i);
showlophoc(P);
P = P->Next; // đi đế n Node kếtiế p
i++;
}
}
void showhocvien(HocVien *p){
printf("Ma hoc vien: %d\n", p->maHocVien);
printf("Ho va ten: %s %s\n", p->hoLot, p->ten);
printf("Ngay sinh: %d/%d/%d\n", p->ngaySinh.ngay,
p->ngaySinh.thang,
p->ngaySinh.nam);
printf("Ma lop: %d\n", p->maLop);
printf("Diem: %.2f\n", p->diem);
}
void showdanhsachhocvien(hocvien hv){
if (isEmptyhocvien(hv) == 1){
printf("danh sach rong");
return;
}
HocVien *p = hv.Head;
int i = 1;
while (p != NULL){
printf("\nThong tin hoc vien thu %d:\n",i);
showhocvien(p);
p = p->Next; // đi đế n Node kếtiế p
i++;
}
}
// lựa chọn thứ tư
//void searchByClassName(hocvien &hv, char name) {
// HocVien *p = hv.Head;
//
// int found = 0;
//
// while (p != NULL) {
//
// if (p->tenlop == name) {
//
//
// found = 1;
//
// }
//
// p = p->Next;
//
// }
//
// if (!found) {
//
// printf("khong tim thay hoc sinh voi ten lop %d\n", name);
//
// }
//
//}

void timkiemtheomahs(hocvien &hv, int id){


HocVien *temp = hv.Head;
int found = 0;
while (temp != NULL) {
if (temp->maHocVien == id) {
showhocvien(temp);
found = 1;
}
temp = temp->Next;
}
if (!found) {
printf("khong tim thay hoc sinh voi ma hoc vien %d\n", id);
}
}
void timkiemtheonamsinh(hocvien hv, int year) {
HocVien *p = hv.Head;
int found = 0;
while (p != NULL) {
if (p->ngaySinh.nam == year) {
showhocvien(p);
found = 1;
}
p = p->Next;
}
if (!found) {
printf("khong tim thay hoc sinh voi ngaythangnamsinh %d\n", year);
}
}
void showMenu(){
printf("\
n**************************************************************************\n");
printf("\n Menu
\n");
printf("\
n**************************************************************************\n");
printf("\n 0. Thoat chuong trinh
\n");
printf("\n 1. Tao mot node moi
\n");
printf("\n 2. Tao mot danh sach nhap tu ban phim
\n");
printf("\n 3. Them mot hoc vien
\n");
printf("\n 4. Tim cac hoc vien theo tieu chi: ten lop hoac ma hoc vien hoac
nam sinh\n");
printf("\n 5. Tim kiem so X co trong danh sach
\n");
printf("\n 6. Xoa phan tu dau cua danh danh
\n");
printf("\n 7. Xoa phan tu ke dau cua danh danh
\n");
printf("\
n**************************************************************************\n");
}
//.................................................
void process(){
struct lophoc dsLopHoc;
struct hocvien dsHocVien;
initlophoc(dsLopHoc);
inithocvien(dsHocVien);
int chon;
do {
showMenu();
printf("\nBan hay lua chon mot chuc nang:");
scanf("%d", &chon);

switch (chon){
case 1:

break;
case 2:

break;
case 3:
themHocVien(dsHocVien);
showdanhsachhocvien(dsHocVien);
break;
case 4:
int luachon4;
printf("\
n**************************************************************************\n");
printf("\n Lua chon 4
\n");
printf("\
n**************************************************************************\n");
printf("\n 1. Tim kiem theo ten lop
\n");
printf("\n 2. Tim kiem theo ma hoc vien
\n");
printf("\n 3. Tim kiem theo nam sinh
\n");
printf("\
n**************************************************************************\n");
printf("\nBan hay lua chon chuc nang: ");
scanf("%d", &luachon4);
switch (luachon4){
case 1:

case 2:
int ID;
printf("\nnhap ma hoc sinh ma ban can tim: ");
scanf("%d", &ID);
timkiemtheomahs(dsHocVien, ID);
break;
case 3:
int NAM;
printf("\nnhap nam sinh cua hoc sinh ma ban can tim: ");
scanf("%d", &NAM);
timkiemtheonamsinh(dsHocVien, NAM);
}
break;
case 5:

break;
case 6:

break;
case 7:

break;
}
} while (chon != 0);
getch();
}
int main() {
process();
getch();
}

You might also like