avatar
15thang5

gywreb 67 16th May, 2019

                                           
                         #include <iostream>
#include <conio.h>
#include <string>
#include <string.h>
#include <graphics.h>
#include <time.h>
#include <fstream>
using namespace std;

#define max 100
//
typedef struct {
	char mamh[16]; // chua cho cho ki tu cuoi \0
	char tenmh[53]; // tuong tu nhu tren
} monhoc;

typedef struct { // mang con tro ==> khai bao cau truc theo keu con tro
	int slmh;
	monhoc *DSMH[max];
} nodeMH;
//RONG

typedef struct {
	char masv[16];
	char ho[53];
	char ten[53];
	char phai[2]; // nam == 0; nu == 1
	char password[53];
} sinhvien; // cau truc thanh phan info

struct nodeSV{
	sinhvien sv; // thanh phan info cua nut trong danh sach
	struct nodeSV *next; // truong next cau danh sach
}; // danh sach lien ket don

typedef nodeSV *PTRSV;

typedef struct {
	char malop[16];
	char tenlop[53];
	int slsv;
	PTRSV DSSV = NULL; // con tro den danh sach sinh vien thuoc ve lop do
} lop; // danh sach tuyen tinh


typedef struct {
	int sll ;
	lop DSL[max];
}nodeL;

typedef struct {
	char mamh[16];
	double diem;
	int slch;
} diem;

struct nodeD {
	diem d; // truong info cua danh sach diem
	struct nodeD *next; // truong next cua danh sach diem
}; // danh sach lien ket don

typedef nodeD *PTRD;

//cay nhi phan danh sach cau hoi thi
typedef struct {
	int id;// key = id ( random )
	char mamh[16];
	char info[53];
	char ans[2]; // chi co 1 ki tu A v B v C v D
	char A[53];
	char B[53];
	char C[53];
	char D[53];

}cauhoi;

int ID;

struct nodeCH{
	cauhoi ch;
	int bf;
	struct nodeCH *right;
	struct nodeCH *left;
};

typedef nodeCH *PTRCH;
PTRCH DSCH = NULL;
//

////////////////////////////////////////////////////////////////////////////////////////////////////

//HIEN THI CHU TREN MAN HINH DO HOA
class DisText { // class for displaying text
	private:
		int MAXL; //max lenght size
		int lenght ;
		char *text; // pointer for text
	public:
		DisText(int n); // n for the SIZE of text type (contructor)
		void addtext(char ch); //add ch to text
		void deltext(); //del text
		void emptytext();
		char *distext() { //display with the \0 at the end
			char *t  = new char[lenght]; //for the last \0
			for (int i = 0; i < lenght; i++) {
				t[i] = text[i];
			}
			t[lenght] = '\0'; //very important when compare for the right text
			return t;
		}
		int FullText();
		int NullText();
		void GetText(char *ch);

};

DisText::DisText(int n) {
	MAXL = n; //n position \0
	text = new char[MAXL]; // n size , create memory for *text
	for (int i = 0; i <= MAXL; i++) {
		text[i] = ' ' ;// NULL char for store new character when addchar
	}
	text[MAXL] = '\0'; //last store char
	lenght = 0; //start to add more or decrease lenght when using other function(like addtext ,..)

}
void DisText::addtext(char ch) {
	if(lenght <= MAXL -1) {
	lenght++; //add lenght to add 1 ch
	text[lenght - 1] = ch; // store the newly added ch to text
	}
}
void DisText::deltext() {
	if(lenght >= 1) {
		text[lenght - 1] = ' '; // at the position u previously add
		lenght--; //decrease the text size
	}
}

int DisText::NullText() {
	if(lenght == 0) return 1;
	else return 0;
}

int DisText::FullText() {
	if(lenght == MAXL - 1) return 1;
	else return 0;
}

void DisText::emptytext() {
	for (int i = 0; i <= MAXL; i++) {
		text[i] = ' ' ;
	}
	text[MAXL] = '\0';
	lenght = 0;
}

void DisText::GetText (char *ch) {
	int k = 0;
	while (ch[k] != '\0') {
		lenght++;
		k++;
	}
	for(int i = 0; i < lenght; i++) {
		text[i] = ch[i];
	}
	text[lenght] = '\0';
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//PROTOTYPE
void GV_CHOICE(int choice);
void WriteL(nodeL &SubL);
void ReadL(nodeL &SubL);
void InsertLastSV(PTRSV &First, sinhvien SV);
void THI_UI();
void HS_INPUT();
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//MAN HINH DANG NHAP
void Login_scr() {
	setbkcolor(14);
	setfillstyle(1,14);
	bar(160,120,480,150);
	setfillstyle(1,3); //set the login boord color
	settextstyle(8,0,1);
	setcolor(9);
	rectangle(160,120,480,360);
	bar(160,150,480,360); // the centre of screen with resolution divide by 4
	line(160,150,480,150);
	setcolor(0);//set the title color
	settextjustify(CENTER_TEXT,TOP_TEXT);
	outtextxy(320,125,"DANG NHAP"); //dis
	setcolor(1);
	setbkcolor(15);
	outtextxy(140,410,"[F1]:hien mat khau(3s)");
	outtextxy(140 + textwidth("//") + textwidth("[F1]:hien mat khau(3s)"),410,"[F5]:lam moi trang");
	setcolor(12);
	outtextxy(80,440,"[ESC]:thoat");
	outtextxy(80 + textwidth("////") + textwidth("[ESC]:thoat"),440,"[TAB]:len dong");
	outtextxy(80 + textwidth("////////") + textwidth("[ESC]:thoat") + textwidth("[TAB]:len dong "),440,"[ENTER]:xac nhan");
	setbkcolor(3);
	setcolor(0);
	settextjustify(LEFT_TEXT,TOP_TEXT);
	outtextxy(190,190,"TAI KHOAN");
	outtextxy(190,245,"MAT KHAU"); //display pass title
	setfillstyle(1,11); //set login space color
	rectangle(190,210,460,240);//LOgin space
	rectangle(190,265,460,295); //PASS Lo/ higher than the text 15
	bar(190,210,460,240); // display text below 5
	bar(190,265,460,295); //ID login space
	setbkcolor(11);
	setcolor(0); //set text color
}

void Login()
{
	// now, you can run project
	Login_scr();
	nodeL SubL;
	DisText p(53), phd(53), a(16);
	char pass, acc ;
	int enter = 0; // Input from ID to PASS
	do {
		if(enter == 0) {
			setcolor(12); //
			rectangle(190,210,460,240); // cho biet dc la dang o vi tri ID
			acc = getch();
			setcolor(0);
			setbkcolor(11);
			if(acc == 13) { //enter hoac mui ten xuong
				enter++;
				setcolor(0);
				rectangle(190,210,460,240);
			}
			else if(acc == 27) {
				a.emptytext();
				p.emptytext();
				phd.emptytext();
				enter = 2;
			}
			else if(acc == 63) {
				a.emptytext();
				p.emptytext();
				phd.emptytext();
				Login();
			}
			else if (acc == 59) {
				outtextxy(200,270,p.distext());
				rectangle(190,265,460,295);
				delay(3000);
				outtextxy(200,270,phd.distext());
				rectangle(190,265,460,295);
			}
			else if (acc == 8||acc == 127){
				a.deltext();
				//cleardevice();
				Login_scr();
				outtextxy(200,215,a.distext());
				outtextxy(200,270,phd.distext());
			}
			else if ((acc >= 48 && acc <= 57)|| (acc >= 65&& acc <= 90)||(acc >= 97&& acc <= 122)) {
				if(!a.FullText() && textwidth(a.distext()) <= 242 ) {
					a.addtext(acc);
					outtextxy(200,215,a.distext());
				}
				else {
				setbkcolor(3);
				setcolor(12);
				outtextxy(200,340,"BAN NHAP QUA DO DAI KI TU");
				delay(1000);
				outtextxy(200,340,"                         ");
				}
			}
		}
		else if(enter == 1) {
			setcolor(12);
			rectangle(190,265,460,295); // cho biet dc o vi tri PASS
			pass = getch();
			setcolor(0);
			// Done input your pass
			if(pass == 13) {
				ReadL(SubL);
				for(int i = 0; i <= SubL.sll; i++) {
					for(PTRSV q = SubL.DSL[i].DSSV; q != NULL; q = q->next) {
						if(strcmp(a.distext(),q->sv.masv) == 0 && strcmp(p.distext(),q->sv.password) == 0) {
							setbkcolor(2);
							setcolor(0);
							char *ch = new char[100];
							ch[0] = '\0';
							strcat(ch,q->sv.ho);
							strcat(ch," ");
							strcat(ch,q->sv.ten);
							outtextxy(200,320,ch);
							setbkcolor(3);
							setcolor(12);
							outtextxy(200,340,"DANG NHAP THANH CONG");
							delay(1000);
							outtextxy(200,340,"                    ");
							setbkcolor(15);
							cleardevice();
							//THI_UI();
							HS_INPUT();
						}
					}
				}
				if(strcmp(a.distext(),"GV") == 0 && strcmp(p.distext(),"GV") == 0) {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,340,"DANG NHAP THANH CONG");
					delay(1000);
					outtextxy(200,340,"                         ");
					setbkcolor(15);
					cleardevice();
					GV_CHOICE(0);
				}
				else if (strcmp(a.distext(),"GV") != 0) {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,340,"BAN NHAP SAI TAI KHOAN");
					delay(1000);
					outtextxy(200,340,"                         ");
					enter--;
					setcolor(0);
					rectangle(190,265,460,295);
				}
				else if (strcmp(p.distext(),"GV") != 0)	{
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,340,"BAN NHAP SAI MAT KHAU ");
					delay(1000);
					outtextxy(200,340,"                         ");
				}

			}
			else if(pass == 27) {
				a.emptytext();
				p.emptytext();
				phd.emptytext();
				enter = 2;
			}
			else if(pass == 63) {
				a.emptytext();
				p.emptytext();
				phd.emptytext();
				enter--;
				Login();
			}
			else if (pass == 59) {
				outtextxy(200,270,p.distext());
				delay(3000);
				outtextxy(200,270,phd.distext());
			}

			else if(pass == 9) {
				enter--;
				setcolor(0);
				rectangle(190,265,460,295);
			}
			//delete ur pass
			else if (pass == 8||pass == 127){
				if(p.NullText()) {
					enter--;
					setcolor(0);
					rectangle(190,265,460,295);
				}
				p.deltext();
				phd.deltext();
				//cleardevice();
				Login_scr();
				outtextxy(200,215,a.distext());
				outtextxy(200,270,phd.distext());
			}
			//normal character without any speacial cases
			else if ((pass >= 48 && pass <= 57)|| (pass >= 65&& pass <= 90)||(pass >= 97&& pass <= 122) || pass == 32) {
				if(!p.FullText() && textwidth(p.distext()) <= 242 ) {
					p.addtext(pass);
					phd.addtext('*');
					outtextxy(200,270,phd.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,340,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(200,340,"                         ");
					setbkcolor(11);
				}
			}
			//special case

		}
		else if(enter == 2) {
			//cleardevice();
			closegraph();
		}

	} while (1);
	//cleardevice();
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//
//NHAP MON HOC
int EmptyMH(nodeMH SubMH) {
	return SubMH.slmh == 0;
}
int FullMH(nodeMH SubMH) {
	return SubMH.slmh == max;
}
void ReadMH(nodeMH &SubMH) {

	ifstream fr("D:\\New folder\\DSMH.txt");

	if(fr.fail()){
		cout<<"can't read file'";
	}

	SubMH.slmh = -1;

	while(!fr.eof()){
		SubMH.slmh++;
		SubMH.DSMH[SubMH.slmh] = new monhoc;
		fr.getline(SubMH.DSMH[SubMH.slmh]->mamh,16);
		fr.getline(SubMH.DSMH[SubMH.slmh]->tenmh,53);
	};
	fr.close();
}

void WriteMH(nodeMH &SubMH) {

	ofstream fw("D:\\New folder\\DSMH.txt");

	for(int i = 0; i <= SubMH.slmh; i++) {
		fw<<SubMH.DSMH[i]->mamh<<endl;
		fw<<SubMH.DSMH[i]->tenmh<<endl;
	}
	fw.close();
}
int CheckMH(char *ch ,nodeMH &SubMH) {
	for (int i = 0; i <= SubMH.slmh; i++) {
		if(strcmp(ch,SubMH.DSMH[i]->mamh) == 0 || strcmp(ch,SubMH.DSMH[i]->tenmh) == 0)
			return i;
	}
	return -1;
}

void MH_UI() {
	setbkcolor(14);
	setfillstyle(1,14);
	bar(160,120,480,150);
	setfillstyle(1,3); //set the login boord color
	settextstyle(8,0,1);
	setcolor(9);
	rectangle(160,120,480,360);
	bar(160,150,480,360); // the centre of screen with resolution divide by 4
	line(160,150,480,150);
	setcolor(0);//set the title color
	settextjustify(CENTER_TEXT,TOP_TEXT);
	outtextxy(320,125,"NHAP MON HOC"); //dis
	setcolor(1);
	setbkcolor(15);
	outtextxy(120,410,"[F5]:lam moi trang");
	setcolor(12);
	outtextxy(80,440,"[ESC]:thoat");
	outtextxy(80 + textwidth("////") + textwidth("[ESC]:thoat"),440,"[TAB]:len dong");
	outtextxy(80 + textwidth("////////") + textwidth("[ESC]:thoat") + textwidth("[TAB]:len dong "),440,"[ENTER]:xac nhan");
	setbkcolor(3);
	setcolor(0);
	settextjustify(LEFT_TEXT,TOP_TEXT);
	outtextxy(190,190,"MA MON HOC");
	outtextxy(190,245,"TEN MON HOC"); //display pass title
	setfillstyle(1,11); //set login space color
	rectangle(190,210,460,240);//LOgin space
	rectangle(190,265,460,295); //PASS Lo/ higher than the text 15
	bar(190,210,460,240); // display text below 5
	bar(190,265,460,295); //ID login space
	setbkcolor(11);
	setcolor(0); //set text color
}
void MH_UD() {
	setbkcolor(14);
	setfillstyle(1,14);
	bar(160,120,480,150);
	setfillstyle(1,3); //set the login boord color
	settextstyle(8,0,1);
	setcolor(9);
	rectangle(160,120,480,360);
	bar(160,150,480,360); // the centre of screen with resolution divide by 4
	line(160,150,480,150);
	setcolor(0);//set the title color
	settextjustify(CENTER_TEXT,TOP_TEXT);
	outtextxy(320,125,"XOA MON HOC"); //dis
	setcolor(1);
	setbkcolor(15);
	outtextxy(120,410,"[F5]:lam moi trang");
	setcolor(12);
	outtextxy(80,440,"[ESC]:thoat");
	outtextxy(80 + textwidth("////") + textwidth("[ESC]:thoat"),440,"[ENTER]:xac nhan");
	setbkcolor(3);
	setcolor(0);
	settextjustify(LEFT_TEXT,TOP_TEXT);
	outtextxy(190,190,"MA MON HOC MUON XOA");
	setfillstyle(1,11); //set login space color
	rectangle(190,210,460,240);//LOgin space
	bar(190,210,460,240); // display text below 5
	setbkcolor(11);
	setcolor(0); //set text color
}
void MH_UF() {
	setbkcolor(14);
	setfillstyle(1,14);
	bar(160,120,480,150);
	setfillstyle(1,3); //set the login boord color
	settextstyle(8,0,1);
	setcolor(9);
	rectangle(160,120,480,360);
	bar(160,150,480,360); // the centre of screen with resolution divide by 4
	line(160,150,480,150);
	setcolor(0);//set the title color
	settextjustify(CENTER_TEXT,TOP_TEXT);
	outtextxy(320,125,"HIEU CHINH MON HOC"); //dis
	setcolor(1);
	setbkcolor(15);
	outtextxy(120,410,"[F5]:lam moi trang");
	setcolor(12);
	outtextxy(80,440,"[ESC]:thoat");
	outtextxy(80 + textwidth("////") + textwidth("[ESC]:thoat"),440,"[ENTER]:xac nhan");
	setbkcolor(3);
	setcolor(0);
	settextjustify(LEFT_TEXT,TOP_TEXT);
	outtextxy(190,190,"MA MON HOC MUON HIEU CHINH");
	setfillstyle(1,11); //set login space color
	rectangle(190,210,460,240);//LOgin space
	bar(190,210,460,240); // display text below 5
	setbkcolor(11);
	setcolor(0); //set text color
}
void InputMH(nodeMH &SubMH) {

	cleardevice();
	MH_UI();
	DisText mamh(16), tenmh(53);
	char ma,ten,thoat,comfirm;
	int enter = 0;// bien xuong dong
	do{
		ReadMH(SubMH);
		if(enter == 0) {
			setcolor(12); //
			rectangle(190,210,460,240);// cho biet dc la dang o vi tri
			ma = getch();
			setbkcolor(11);
			setcolor(0);
			if(ma == 13) { //enter hoac mui ten xuong
				enter++;
				setcolor(0);
				rectangle(190,210,460,240);
			}
			else if(ma == 27) {
				mamh.emptytext();
				tenmh.emptytext();
				enter = 2;
			}

			else if(ma == 63) {
				mamh.emptytext();
				tenmh.emptytext();
				MH_UI();
			}
			else if (ma == 8||ma == 127){
				mamh.deltext();
				//cleardevice();
				MH_UI();
				outtextxy(200,215,mamh.distext());
				outtextxy(200,270,tenmh.distext());
			}
			else if ((ma >= 48 && ma <= 57)|| (ma >= 65&& ma <= 90)||(ma >= 97&& ma <= 122)) {
				if(!mamh.FullText() && textwidth(mamh.distext()) <= 242 ) {
					mamh.addtext(ma);
					outtextxy(200,215,mamh.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,340,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(200,340,"                         ");
					setbkcolor(11);
				}
			}
		}
		else if(enter == 1) {
			setcolor(12);
			rectangle(190,265,460,295); // cho biet dc o vi tri
			ten = getch();
			setcolor(0);
			if(ten == 13) {
				setbkcolor(3);
				setcolor(12);
				if(!FullMH(SubMH)) {
					if(mamh.NullText()) {
						setbkcolor(3);
						setcolor(12);
						outtextxy(200,340,"CHUA NHAP MA MON HOC");
						delay(1000);
						outtextxy(200,340,"                    ");
						setcolor(0);
						rectangle(190,265,460,295);
						setbkcolor(11);
						enter = 0;
					}
					else if(tenmh.NullText()) {
						setbkcolor(3);
						setcolor(12);
						outtextxy(200,340,"CHUA NHAP TEN MON HOC");
						delay(1000);
						outtextxy(200,340,"                     ");
						setbkcolor(11);
					}
					else if(CheckMH(mamh.distext(),SubMH) == -1 && CheckMH(tenmh.distext(),SubMH) == -1) {
						outtextxy(200,340,"LUU MON HOC? (Y/N)");
						comfirm = getch();
						if(comfirm == 'y' || comfirm == 'Y') {
						SubMH.DSMH[SubMH.slmh] = new monhoc;
						strcpy(SubMH.DSMH[SubMH.slmh]->mamh,mamh.distext());
						strcpy(SubMH.DSMH[SubMH.slmh]->tenmh,tenmh.distext());
						WriteMH(SubMH);
						MH_UI();
						setbkcolor(3);
						setcolor(12);
						outtextxy(200,340,"DA LUU ! ");
						delay(1000);
						outtextxy(200,340,"         ");
						mamh.emptytext();
						tenmh.emptytext();
						outtextxy(200,340,"TIEP TUC NHAP? (Y/N)");
						thoat = getch();
						if(thoat == 'y' || thoat == 'Y') {
							SubMH.slmh++;
							enter--;
							MH_UI();
						}
						else {
							enter++;
							//break;
						}
						}
						else {
							enter--;
							MH_UI();
							outtextxy(200,215,mamh.distext());
							outtextxy(200,270,tenmh.distext());
						}
					}
					else {
						enter--;
						MH_UI();
						outtextxy(200,215,mamh.distext());
						outtextxy(200,270,tenmh.distext());
						setbkcolor(3);
						setcolor(12);
						outtextxy(200,340,"MON HOC NAY DA TON TAI");
						delay(1000);
						outtextxy(200,340,"                      ");
					}
				}
				else if(FullMH(SubMH)) {
					MH_UI();
					setbkcolor(3);
					setcolor(12);
					mamh.emptytext();
					tenmh.emptytext();
					do{
						outtextxy(200,340,"DANH SACH DA DAY !");
						delay(1000);
						outtextxy(200,340,"                  ");
						delay(1000);
						outtextxy(200,340,"VUI LONG XOA MON !");
						delay(1000);
						outtextxy(200,340,"                  ");
						thoat = getch();
					} while (thoat != 27);
					enter++;
				}

			}
			else if(ten == 27) {
				mamh.emptytext();
				tenmh.emptytext();
				enter = 2;
			}

			else if(ten == 63) {
				mamh.emptytext();
				tenmh.emptytext();
				enter--;
				MH_UI();
			}

			else if(ten == 9) {
				enter--;
				setcolor(0);
				rectangle(190,265,460,295);
			}

			else if (ten == 8||ten == 127){
				if(tenmh.NullText()) {
					enter--;
					setcolor(0);
					rectangle(190,265,460,295);
				}
				tenmh.deltext();
				//cleardevice();
				MH_UI();
				outtextxy(200,215,mamh.distext());
				outtextxy(200,270,tenmh.distext());
			}
			//normal character without any speacial cases
			else if ((ten >= 48 && ten <= 57)|| (ten >= 65&& ten <= 90)||(ten >= 97&& ten <= 122) || ten == 32) {
				if(!tenmh.FullText() && textwidth(tenmh.distext()) <= 242) {
					tenmh.addtext(ten);
					outtextxy(200,270,tenmh.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,340,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(200,340,"                         ");
					setbkcolor(11);
				}
			}
			//special case

		}
		else if(enter == 2) {
			setbkcolor(15);
			cleardevice();
			GV_CHOICE(2);
		}
	} while(1);
}

void DeleteMH(nodeMH &SubMH) {

	ReadMH(SubMH);
	cleardevice();
	MH_UD();
	DisText mamh_c(16);
	char ma,thoat,comfirm;
	int enter = 0;
	do{
		if(enter == 0) {
			setcolor(12); //
			rectangle(190,210,460,240); // cho biet dc la dang o vi tri
			ma = getch();
			setbkcolor(11);
			setcolor(0);
			if(ma == 13) {
				if(EmptyMH(SubMH)) {
					MH_UD();
					mamh_c.emptytext();
					setbkcolor(3);
					setcolor(12);
					do {
						outtextxy(200,340,"DANH SACH MON HOC TRONG !");
						delay(1000);
						outtextxy(200,340,"                         ");
						outtextxy(200,340,"VUI LONG NHAP THEM MON !");
						delay(1000);
						outtextxy(200,340,"                        ");
						thoat = getch();
					} while(thoat != 27);
					enter++;
				}
				else {
					setbkcolor(3);
					setcolor(12);
					if(mamh_c.NullText()) {
						outtextxy(200,340,"CHUA NHAP MA MON HOC");
						delay(1000);
						outtextxy(200,340,"                    ");
						setbkcolor(11);
					}
					else if(CheckMH(mamh_c.distext(),SubMH) != -1) {
						int temp = CheckMH(mamh_c.distext(),SubMH);
						outtextxy(200,280,"BAN CO MUON XOA MON HOC:");
						outtextxy(200,340,"(Y/N)?");
						setcolor(0);
						setbkcolor(11);
						outtextxy(200,310,SubMH.DSMH[temp]->tenmh);
						comfirm = getch();
						if(comfirm == 'y' || comfirm == 'Y') {
							for(int i = temp; i < SubMH.slmh; i++) {
									SubMH.DSMH[i] = SubMH.DSMH[i+1];
									//delete SubMH.DSMH[SubMH.slmh - 1];
							}
							SubMH.slmh-=2;
							WriteMH(SubMH);
							MH_UD();
							setbkcolor(3);
							setcolor(12);
							outtextxy(200,340,"DA XOA ! ");
							delay(1000);
							outtextxy(200,340,"         ");
							mamh_c.emptytext();
							outtextxy(200,340,"TIEP TUC XOA? (Y/N)");
							thoat = getch();
							if(thoat == 'y' || thoat == 'Y') {
								MH_UD();
							}
							else {
								enter++;
								//break;
							}
						}
						else {
						MH_UD();
						outtextxy(200,215,mamh_c.distext());
						}
					}
					else {
						MH_UD();
						outtextxy(200,215,mamh_c.distext());
						setbkcolor(3);
						setcolor(12);
						outtextxy(200,340,"MA MON HOC KHONG TON TAI");
						delay(1000);
						outtextxy(200,340,"                         ");
					}
				}
			}
			else if(ma == 27) {
				mamh_c.emptytext();
				enter++;
			}

			else if(ma == 63) {
				mamh_c.emptytext();
				MH_UD();
			}

			else if (ma == 8||ma == 127){
				mamh_c.deltext();
				//cleardevice();
				MH_UD();
				outtextxy(200,215,mamh_c.distext());
			}
			else if ((ma >= 48 && ma <= 57)|| (ma >= 65&& ma <= 90)||(ma >= 97&& ma <= 122)) {
				if(!mamh_c.FullText() && textwidth(mamh_c.distext()) <= 242) {
					mamh_c.addtext(ma);
					outtextxy(200,215,mamh_c.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,340,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(200,340,"                         ");
					setbkcolor(11);
		 		}
			}
		}
		else if(enter == 1) {
			setbkcolor(15);
			cleardevice();
			GV_CHOICE(3);
		}
	} while(1);
}
void FixMH(nodeMH &SubMH) {

	ReadMH(SubMH);
	cleardevice();
	MH_UF();
	DisText mamh_c(16), tenmh_c(53);
	char ma,thoat,comfirm;
	int enter = 0, temp = 0;
	do{
		if(enter == 0) {
			setcolor(12); //
			rectangle(190,210,460,240); // cho biet dc la dang o vi tri
			ma = getch();
			setbkcolor(11);
			setcolor(0);
			if(ma == 13) {
				if(EmptyMH(SubMH)) {
					MH_UF();
					mamh_c.emptytext();
					setbkcolor(3);
					setcolor(12);
					do {
						outtextxy(200,340,"DANH SACH MON HOC TRONG !");
						delay(1000);
						outtextxy(200,340,"                         ");
						outtextxy(200,340,"VUI LONG NHAP THEM MON !");
						delay(1000);
						outtextxy(200,340,"                        ");
						thoat = getch();
					} while(thoat != 27);
					enter++;
				}
				else {
					setbkcolor(3);
					setcolor(12);
					if(mamh_c.NullText()) {
						outtextxy(200,340,"CHUA NHAP MA MON HOC");
						delay(1000);
						outtextxy(200,340,"                    ");
						setbkcolor(11);
					}
					else if(CheckMH(mamh_c.distext(),SubMH) != -1) {
						temp = CheckMH(mamh_c.distext(),SubMH);
						char *ch = new char[53];
						ch[0] = '\0';
						strcat(ch,SubMH.DSMH[temp]->tenmh);
						tenmh_c.GetText(ch);
						outtextxy(200,280,"HIEU CHINH MON HOC:");
						outtextxy(200,340,"(Y/N)?");
						setcolor(0);
						setbkcolor(11);
						outtextxy(200,310,tenmh_c.distext());
						comfirm = getch();
						if(comfirm == 'y' || comfirm == 'Y') {
							MH_UF();
							outtextxy(200,215,tenmh_c.distext());
							mamh_c.emptytext();
							enter++;
						}
						else if(comfirm == 'n' || comfirm == 'N'){
						MH_UF();
						outtextxy(200,215,mamh_c.distext());
						}
					}
					else {
						MH_UF();
						outtextxy(200,215,mamh_c.distext());
						setbkcolor(3);
						setcolor(12);
						outtextxy(200,340,"MA MON HOC KHONG TON TAI");
						delay(1000);
						outtextxy(200,340,"                         ");
					}
				}
			}
			else if(ma == 27) {
				mamh_c.emptytext();
				enter = 2;
			}

			else if(ma == 63) {
				mamh_c.emptytext();
				MH_UF();
			}

			else if (ma == 8||ma == 127){
				mamh_c.deltext();
				//cleardevice();
				MH_UF();
				outtextxy(200,215,mamh_c.distext());
			}
			else if ((ma >= 48 && ma <= 57)|| (ma >= 65&& ma <= 90)||(ma >= 97&& ma <= 122)) {
				if(!mamh_c.FullText() && textwidth(mamh_c.distext()) <= 242) {
					mamh_c.addtext(ma);
					outtextxy(200,215,mamh_c.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,340,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(200,340,"                         ");
					setbkcolor(11);
		 		}
			}
		}
		if(enter == 1) {
			setbkcolor(3);
			setcolor(0);
			outtextxy(190,190,"                          ");
			outtextxy(190,190,"TEN MON HOC HIEU CHINH");
			setcolor(12); //
			rectangle(190,210,460,240); // cho biet dc la dang o vi tri
			ma = getch();
			setbkcolor(11);
			setcolor(0);
			if(ma == 13) {
				setbkcolor(3);
				setcolor(12);
				if(tenmh_c.NullText()) {
					outtextxy(200,340,"KHONG THE DE TRONG");
					delay(1000);
					outtextxy(200,340,"                  ");
					setbkcolor(11);
				}
				else if(CheckMH(tenmh_c.distext(),SubMH) == -1) {
					outtextxy(200,340,"HIEU CHINH MON HOC?(Y/N)");
					comfirm = getch();
					if(comfirm == 'y' || comfirm == 'Y') {
						strcpy(SubMH.DSMH[temp]->tenmh,tenmh_c.distext());
						SubMH.slmh--;
						WriteMH(SubMH);
						MH_UF();
						setbkcolor(3);
						setcolor(12);
						outtextxy(200,340,"DA HIEU CHINH ! ");
						delay(1000);
						outtextxy(200,340,"         ");
						tenmh_c.emptytext();
						outtextxy(200,340,"TIEP TUC HIEU CHINH?(Y/N)");
						thoat = getch();
						if(thoat == 'y' || thoat == 'Y') {
							enter--;
							MH_UF();
						}
						else {
							enter++;
						}
					}
					else if(comfirm == 'n' || comfirm == 'N'){
						MH_UF();
						outtextxy(200,215,tenmh_c.distext());
					}
				}
				else {
					MH_UF();
					outtextxy(200,215,tenmh_c.distext());
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,340,"TEN MON HOC NAY DA TON TAI");
					delay(1000);
					outtextxy(200,340,"                          ");
				}
			}
			else if(ma == 27) {
				tenmh_c.emptytext();
				enter++;
			}

			else if(ma == 63) {
				tenmh_c.emptytext();
				MH_UF();
			}

			else if (ma == 8||ma == 127){
				tenmh_c.deltext();
				//cleardevice();
				MH_UF();
				outtextxy(200,215,tenmh_c.distext());
			}
			else if ((ma >= 48 && ma <= 57)|| (ma >= 65&& ma <= 90)||(ma >= 97&& ma <= 122) || ma == 32) {
				if(!tenmh_c.FullText() && textwidth(tenmh_c.distext()) <= 242) {
					tenmh_c.addtext(ma);
					outtextxy(200,215,tenmh_c.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,340,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(200,340,"                         ");
					setbkcolor(11);
		 		}
			}
		}
		else if(enter == 2) {
			setbkcolor(15);
			cleardevice();
			GV_CHOICE(4);
		}
	} while(1);
}

void OutputMH(nodeMH &SubMH) {

	ReadMH(SubMH);
	cleardevice();
	int page = 0, total_page = 1, display_page = 1; //to change page when conditions met
	char control; //the control on keyboard
	do{
		setbkcolor(3);
		settextstyle(8,0,1);
		setfillstyle(1,14);
		setcolor(2);
		rectangle(60,30,580,420);
		bar(60,30,580,60);
		line(60,60,580,60);
		setfillstyle(1,11);
		bar(60,60,580,420);
		setfillstyle(1,3);
		bar(60,60,580,90);
		setcolor(0);
		line(120,60,120,420); //same x axis to draw a straight line
		line(240,60,240,420); //divide the list into 8 parts
		int space = 30; // space to draw the line divide the list to display classes
		for (int  i = 0; i <= 10; i++) { //i is the number of displayed items - 2
			space += 30;
			line(60,30+space,580,30+space);
		}
		settextjustify(CENTER_TEXT,TOP_TEXT); //divide the screen to 2 and place the text at center
		setbkcolor(14);
		setcolor(0);
		outtextxy(320,35,"DANH SACH CAC MON HOC"); //displayed text below 5
		setbkcolor(3);
		setcolor(8);
		outtextxy(90,65,"STT");
		outtextxy(180,65,"MA MON HOC");
		outtextxy(410,65,"TEN MON HOC");
		setcolor(12);
		setbkcolor(15);
		outtextxy(120,440," [ESC]:thoat ");
		setcolor(2);
		outtextxy(120 + textwidth("    ") + textwidth("[ESC]:thoat"),440,"[<-]:trang truoc ");
		outtextxy(120 + textwidth("   ") + textwidth("[ESC]:thoat") +textwidth("[<-]:trang truoc"),440,"[->]:trang ke");
		setcolor(0);
		setbkcolor(11);
		for (int i = page + 1; i <= min(page + 11,SubMH.slmh); i++) { // i phu thuoc vao page -> hien thi cac lop theo so thu tu hien thi tren 1 trang
			char *t = new char[10]; // tao so thu tu
			itoa(i,t,10); // convert number to string to display on graphic
			outtextxy(90,65 + (i - page)*30,t); // display STT
			outtextxy(180,65 + (i - page)*30,SubMH.DSMH[i - 1]->mamh);
			outtextxy(410,65 + (i - page)*30,SubMH.DSMH[i - 1]->tenmh);
			/* (i - page)*30 : i luon luon > page ; i la thu tu hien thi lop
				page la dieu kien chuyen trang , 11 la so luong toi da hien thi
				tren 1 trang, page tang len +11 khi bam [->], 30 la khoang cach hien thi
				giua cac dong chu voi nhau.
				==> (i - page) = {1, 2 ,3 ,.. den khi reset lai = 1 khi chuyen trang}
			*/

			/* min(page + 11, SubL.sll): giua so luong lop va so luong hien thi toi da
				tinh toi trang hien tai (vd : trang 2 -> hien thi dc 22 / 42 so lop hoc)
				chon so nho hon de hien thi ( cho truong hop toi trang cuoi, so luong lop
				ko hien thi het trang -> lay SubL.sll)
				==> tranh hien tuong hien thi tran ra ngoai bang hien thi.
			*/
		}
		total_page = SubMH.slmh/11 + (SubMH.slmh % 11 == 0 ? 0 : 1); // neu ko chia het cho 11 thi cong them 1 de hien thi phan mon con lai o trg khac
		char *total = new char[10]; //tao con tro chuoi de hien thi
		itoa(total_page,total,10); // chuyen so thanh chuoi de hien thi
		char *display = new char[10];
		itoa(display_page,display,10);
		setbkcolor(15);
		outtextxy(500,5,"TRANG: ");
		outtextxy(500 + textwidth("    "),5,display);
		outtextxy(500 + textwidth("    ") + textwidth(display),5,"/");
		outtextxy(500 + textwidth("    ") + textwidth(display) + textwidth("/"),5,total);
		do{
			control = getch();
		} while(control != 27 &&(!(control == 77&& page + 11 < SubMH.slmh)) && (!(control == 75 && page > 0)));
		/* khong nhan control:
			+ neu nhu nhan escape
			+ neu nhu nhan [->] nhung so luong hien thi toi da da vuot qua so luong lop
			+ neu nhu nhan [<-] nhung so luong hien thi toi da se thanh so am (vo ly)
		*/
		if(control == 27) {
			setbkcolor(15);
			cleardevice();
			GV_CHOICE(5);
		}
		if(control == 77) {
			page += 11; // tang so luon hien thi lop toi da cua 1 trang len 11 (tt hien thi cac lop sau)
			display_page++;
		}
		else if(control == 75) {
			page -= 11; // giam so luong hien thi lop toi da xuong 11 (thu tu cac lop da hien thi - 11 cac lop hien thi trc do)
			display_page--;
		}
	}while(1);
}

//////////////////////////////////////////////////////////////////////////////////////////////////

//NHAP LOP
int CheckL(char *ch, nodeL &SubL) {
	for (int i = 0; i <= SubL.sll; i++) {
		if(strcmp(ch,SubL.DSL[i].malop) == 0 || strcmp(ch,SubL.DSL[i].tenlop) == 0)
			return i;
	}
	return -1;
}
int EmptyL(nodeL &SubL) {
	return SubL.sll == 0;
}
int FullL(nodeL &SubL) {
	return SubL.sll == max;
}
void ReadL(nodeL &SubL) {

	ifstream fr_sv("D:\\New folder\\DSL.txt");

	SubL.sll = -1;

	sinhvien SV;

	while(!fr_sv.eof()) {
			char *t = new char[100];
			SubL.sll++;
			fr_sv.getline(SubL.DSL[SubL.sll].malop,16);
			fr_sv.getline(SubL.DSL[SubL.sll].tenlop,53);
			fr_sv.getline(t,100);
			SubL.DSL[SubL.sll].slsv = atoi(t);
			for (int k = 0; k <= atoi(t) - 1; k++) {
				fr_sv.getline(SV.masv,16);
				fr_sv.getline(SV.password,53);
				fr_sv.getline(SV.ho,53);
				fr_sv.getline(SV.ten,53);
				fr_sv.getline(SV.phai,2);
				InsertLastSV(SubL.DSL[SubL.sll].DSSV,SV);
			}
	};
	fr_sv.close();
}

void WriteL(nodeL &SubL) {

	ofstream fw_sv("D:\\New folder\\DSL.txt");

	for(int i = 0; i <= SubL.sll - 1; i++) {
		fw_sv<<SubL.DSL[i].malop<<endl;
		fw_sv<<SubL.DSL[i].tenlop<<endl;
		if(SubL.DSL[i].DSSV == NULL)  //Kiem tra danh sach co rong hay khong
			fw_sv<<"0"<<endl;
		else {
			fw_sv<<SubL.DSL[i].slsv<<endl;
			for(PTRSV p = SubL.DSL[i].DSSV /*First*/; p != NULL; p = p->next) {
				fw_sv<<p->sv.masv<<endl;
				fw_sv<<p->sv.password<<endl;
				fw_sv<<p->sv.ho<<endl;
				fw_sv<<p->sv.ten<<endl;
				fw_sv<<p->sv.phai<<endl;
			}
		}
	}
	fw_sv.close();

}

void L_UI() { //GIAO DIEN NHAP LOP
	setbkcolor(14);
	setfillstyle(1,14);
	bar(160,120,480,150);
	setfillstyle(1,3); //set the login boord color
	settextstyle(8,0,1);
	setcolor(9);
	rectangle(160,120,480,360);
	bar(160,150,480,360); // the centre of screen with resolution divide by 4
	line(160,150,480,150);
	setcolor(0);//set the title color
	settextjustify(CENTER_TEXT,TOP_TEXT);
	outtextxy(320,125,"NHAP LOP"); //dis
	setcolor(1);
	setbkcolor(15);
	outtextxy(120,410,"[F5]:lam moi trang");
	setcolor(12);
	outtextxy(80,440,"[ESC]:thoat");
	outtextxy(80 + textwidth("////") + textwidth("[ESC]:thoat"),440,"[TAB]:len dong");
	outtextxy(80 + textwidth("////////") + textwidth("[ESC]:thoat") + textwidth("[TAB]:len dong "),440,"[ENTER]:xac nhan");
	setbkcolor(3);
	setcolor(0);
	settextjustify(LEFT_TEXT,TOP_TEXT);
	outtextxy(190,190,"MA LOP");
	outtextxy(190,245,"TEN LOP"); //display pass title
	setfillstyle(1,11); //set login space color
	rectangle(190,210,460,240);//LOgin space
	rectangle(190,265,460,295); //PASS Lo/ higher than the text 15
	bar(190,210,460,240); // display text below 5
	bar(190,265,460,295); //ID login space
	setbkcolor(11);
	setcolor(0); //set text color'

}

void InputL(nodeL &SubL) {

	ReadL(SubL);
	cleardevice();
	L_UI();
	DisText mal(16), tenl(53);
	char ma,ten,thoat,comfirm;
	int enter = 0; // bien xuong dong
	do{
		if(enter == 0) {
			setcolor(12); //
			rectangle(190,210,460,240); // cho biet dc la dang o vi tri
			ma = getch();
			setcolor(0);
			setbkcolor(11);
			if(ma == 13) { //enter hoac mui ten xuong
				enter++;
				setcolor(0);
				rectangle(190,210,460,240);
			}
			else if(ma == 27) {
				mal.emptytext();
				tenl.emptytext();
				enter = 2;
			}

			else if(ma == 63) {
				mal.emptytext();
				tenl.emptytext();
				L_UI();
			}

			else if (ma == 8||ma == 127){
				mal.deltext();
				//cleardevice();
				L_UI();
				outtextxy(200,215,mal.distext());
				outtextxy(200,270,tenl.distext());
			}
			else if ((ma >= 48 && ma <= 57)|| (ma >= 65&& ma <= 90)||(ma >= 97&& ma <= 122)) {
				if(!mal.FullText() && textwidth(mal.distext()) <= 242) {
					mal.addtext(ma);
					outtextxy(200,215,mal.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,340,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(200,340,"                         ");
					setbkcolor(11);
				}
			}
		}
		else if(enter == 1) {
			setcolor(12);
			rectangle(190,265,460,295); // cho biet dc o vi tri
			ten = getch();
			setcolor(0);
			if(ten == 13) {
				if(FullL(SubL)) {
					L_UI();
					mal.emptytext();
					tenl.emptytext();
					setbkcolor(3);
					setcolor(12);
					do {
						outtextxy(200,340,"DANH SACH LOP DAY !");
						delay(1000);
						outtextxy(200,340,"                   ");
						outtextxy(200,340,"VUI LONG XOA LOP !");
						delay(1000);
						outtextxy(200,340,"                               ");
						thoat = getch();
					} while(thoat != 27);
					enter++;
				}
				else if(mal.NullText()) {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,340,"BAN CHUA NHAP MA LOP");
					delay(1000);
					outtextxy(200,340,"                    ");
					setcolor(0);
					rectangle(190,265,460,295);
					setbkcolor(11);
					enter = 0;
				}
				else if(tenl.NullText()) {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,340,"BAN CHUA NHAP TEN LOP");
					delay(1000);
					outtextxy(200,340,"                     ");
					setbkcolor(11);
				}
				else {
					setbkcolor(3);
					setcolor(12);
					if(CheckL(mal.distext(),SubL) == -1 && CheckL(tenl.distext(),SubL) == -1) {
						outtextxy(200,340,"LUU LOP? (Y/N)");
						comfirm = getch();
						if(comfirm == 'y' || comfirm == 'Y') {
						strcpy(SubL.DSL[SubL.sll].malop,mal.distext());
						strcpy(SubL.DSL[SubL.sll].tenlop,tenl.distext());
						SubL.DSL[SubL.sll].slsv = 0; //khoi tao lop do voi so luong sinh vien = 0
						SubL.DSL[SubL.sll].DSSV = NULL; //danh sach sinh vien cua lop moi = NULL
						SubL.sll++;
						WriteL(SubL);
						L_UI();
						setbkcolor(3);
						setcolor(12);
						outtextxy(200,340,"DA LUU ! ");
						delay(1000);
						outtextxy(200,340,"         ");
						mal.emptytext();
						tenl.emptytext();
						outtextxy(200,340,"TIEP TUC NHAP? (Y/N)");
						thoat = getch();
							if(thoat == 'y' || thoat == 'Y') {
								enter--;
								L_UI();
							}
							else {
								enter++;
								//break;
							}
						}
						else {
							enter--;
							L_UI();
							outtextxy(200,215,mal.distext());
							outtextxy(200,270,tenl.distext());
						}
					}
					else {
						enter--;
						L_UI();
						outtextxy(200,215,mal.distext());
						outtextxy(200,270,tenl.distext());
						setbkcolor(3);
						setcolor(12);
						outtextxy(200,340,"LOP NAY DA TON TAI");
						delay(1000);
						outtextxy(200,340,"                  ");
					}
				}
			}
			else if(ten == 27) {
				mal.emptytext();
				tenl.emptytext();
				enter = 2;
			}

			else if(ten == 63) {
				mal.emptytext();
				tenl.emptytext();
				enter--;
				L_UI();
			}

			else if(ten == 9) {
				enter--;
				setcolor(0);
				rectangle(190,265,460,295);
			}

			else if (ten == 8||ten == 127){
				if(tenl.NullText()) {
					enter--;
					setcolor(0);
					rectangle(190,265,460,295);
				}
				tenl.deltext();
				//cleardevice();
				L_UI();
				outtextxy(200,215,mal.distext());
				outtextxy(200,270,tenl.distext());
			}
			//normal character without any speacial cases
			else if ((ten >= 48 && ten <= 57)|| (ten >= 65&& ten <= 90)||(ten >= 97&& ten <= 122) || ten == 32) {
				if(!tenl.FullText() && textwidth(tenl.distext()) <= 242) {
					tenl.addtext(ten);
					outtextxy(200,270,tenl.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,340,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(200,340,"                         ");
					setbkcolor(11);
				}
			}
			//special case

		}
		else if(enter == 2) {
			setbkcolor(15);
			cleardevice();
			GV_CHOICE(0);
		}
	} while(1);
}

void OutputL(nodeL &SubL) {

	ReadL(SubL);
	cleardevice();
	int page = 0, total_page = 1, display_page = 1; //to change page when conditions met
	char control; //the control on keyboard
	do{
		setbkcolor(3);
		settextstyle(8,0,1);
		setfillstyle(1,14);
		setcolor(2);
		rectangle(60,30,580,420);
		bar(60,30,580,60);
		line(60,60,580,60);
		setfillstyle(1,11);
		bar(60,60,580,420);
		setfillstyle(1,3);
		bar(60,60,580,90);
		setcolor(0);
		line(120,60,120,420); //same x axis to draw a straight line
		line(240,60,240,420); //divide the list into 8 parts
		int space = 30; // space to draw the line divide the list to display classes
		for (int  i = 0; i <= 10; i++) { //i is the number of displayed items - 2
			space += 30;
			line(60,30+space,580,30+space);
		}
		settextjustify(CENTER_TEXT,TOP_TEXT); //divide the screen to 2 and place the text at center
		setbkcolor(14);
		setcolor(0);
		outtextxy(320,35,"DANH SACH CAC LOP"); //displayed text below 5
		setbkcolor(3);
		setcolor(8);
		outtextxy(90,65,"STT");
		outtextxy(180,65,"MA LOP");
		outtextxy(410,65,"TEN LOP");
		setcolor(12);
		setbkcolor(15);
		outtextxy(120,440," [ESC]:thoat ");
		setcolor(2);
		outtextxy(120 + textwidth("    ") + textwidth("[ESC]:thoat"),440,"[<-]:trang truoc ");
		outtextxy(120 + textwidth("   ") + textwidth("[ESC]:thoat") +textwidth("[<-]:trang truoc"),440,"[->]:trang ke");
		setcolor(0);
		setbkcolor(11);
		for (int i = page + 1; i <= min(page + 11,SubL.sll); i++) { // i phu thuoc vao page -> hien thi cac lop theo so thu tu hien thi tren 1 trang
			char *t = new char[10]; // tao so thu tu
			itoa(i,t,10); // convert number to string to display on graphic
			outtextxy(90,65 + (i - page)*30,t); // display STT
			outtextxy(180,65 + (i - page)*30,SubL.DSL[i - 1].malop);
			outtextxy(410,65 + (i - page)*30,SubL.DSL[i - 1].tenlop);
			/* (i - page)*30 : i luon luon > page ; i la thu tu hien thi lop
				page la dieu kien chuyen trang , 11 la so luong toi da hien thi
				tren 1 trang, page tang len +11 khi bam [->], 30 la khoang cach hien thi
				giua cac dong chu voi nhau.
				==> (i - page) = {1, 2 ,3 ,.. den khi reset lai = 1 khi chuyen trang}
			*/

			/* min(page + 11, SubL.sll): giua so luong lop va so luong hien thi toi da
				tinh toi trang hien tai (vd : trang 2 -> hien thi dc 22 / 42 so lop hoc)
				chon so nho hon de hien thi ( cho truong hop toi trang cuoi, so luong lop
				ko hien thi het trang -> lay SubL.sll)
				==> tranh hien tuong hien thi tran ra ngoai bang hien thi.
			*/
		}
		total_page = SubL.sll/11 + (SubL.sll % 11 == 0 ? 0 : 1); // neu ko chia het cho 11 thi cong them 1 de hien thi phan mon con lai o trg khac
		char *total = new char[10]; //tao con tro chuoi de hien thi
		itoa(total_page,total,10); // chuyen so thanh chuoi de hien thi
		char *display = new char[10];
		itoa(display_page,display,10);
		setbkcolor(15);
		outtextxy(500,5,"TRANG: ");
		outtextxy(500 + textwidth("    "),5,display);
		outtextxy(500 + textwidth("    ") + textwidth(display),5,"/");
		outtextxy(500 + textwidth("    ") + textwidth(display) + textwidth("/"),5,total);
		do{
			control = getch();
		} while(control != 27 &&(!(control == 77&& page + 11 < SubL.sll)) && (!(control == 75 && page > 0)));
		/* khong nhan control:
			+ neu nhu nhan escape
			+ neu nhu nhan [->] nhung so luong hien thi toi da da vuot qua so luong lop
			+ neu nhu nhan [<-] nhung so luong hien thi toi da se thanh so am (vo ly)
		*/
		if(control == 27) {
			setbkcolor(15);
			cleardevice();
			GV_CHOICE(1);
		}
		if(control == 77) {
			page += 11; // tang so luon hien thi lop toi da cua 1 trang len 11 (tt hien thi cac lop sau)
			display_page++;
		}
		else if(control == 75) {
			page -= 11; // giam so luong hien thi lop toi da xuong 11 (thu tu cac lop da hien thi - 11 cac lop hien thi trc do)
			display_page--;
		}
	}while(1);
}

/////////////////////////////////////////////////////////////////////////////////////////////////

//NHAP SINH VIEN

PTRSV CheckSV(char *ch, nodeL &SubL, int i) {
	for (PTRSV p = SubL.DSL[i].DSSV; p != NULL; p = p->next) {
		if(strcmp(ch,p->sv.masv) == 0)
			return p;
	}
	return NULL;
}

void InsertLastSV(PTRSV &First, sinhvien SV) {
	PTRSV p = new nodeSV;
	p->sv = SV; p->next = NULL;
	if(First == NULL) First = p;
	else {
		PTRSV Last;
		for (Last = First; Last->next != NULL; Last = Last->next); //cho last chay den cuoi danh sach
		Last -> next = p; //cuoi danh sach gan p
	}

}
void SV_UI() {
	setbkcolor(14);
	setfillstyle(1,14);
	bar(160,30,480,60);
	setfillstyle(1,3); //set the login boord color
	settextstyle(8,0,1);
	setcolor(9);
	rectangle(160,30,480,420);
	bar(160,60,480,420); // the centre of screen with resolution divide by 4
	line(160,60,480,60);
	setcolor(0);//set the title color
	settextjustify(CENTER_TEXT,TOP_TEXT);
	outtextxy(320,35,"NHAP SINH VIEN"); //dis
	setcolor(1);
	setbkcolor(15);
	outtextxy(120,435,"[F1]:hien mat khau(3s)");
	outtextxy(120 + textwidth("//") + textwidth("[F1]:hien mat khau(3s)"),435,"[F5]:lam moi trang");
	setcolor(12);
	outtextxy(80,5,"[ESC]:thoat");
	outtextxy(80 + textwidth("////") + textwidth("[ESC]:thoat"),5,"[TAB]:len dong");
	outtextxy(80 + textwidth("////////") + textwidth("[ESC]:thoat") + textwidth("[TAB]:len dong "),5,"[ENTER]:xac nhan");
	setbkcolor(3);
	setcolor(0);
	settextjustify(LEFT_TEXT,TOP_TEXT);
	outtextxy(190,80,"MA LOP");
	outtextxy(190,135,"MA SINH VIEN"); //display pass title
	outtextxy(190,190,"MAT KHAU");
	outtextxy(190,245,"HO");
	outtextxy(190,300,"TEN");
	outtextxy(190,360,"PHAI (NAM:0 - NU:1)");
	setfillstyle(1,11); //set login space color
	rectangle(190,100,460,130);//LOgin space
	rectangle(190,155,460,185); //PASS Lo/ higher than the text 15
	rectangle(190,210,460,240);
	rectangle(190,265,460,295);
	rectangle(190,320,460,350);
	rectangle(190 + textwidth("PHAI (NAM:0 - NU:1) "),355,460,385);
	bar(190,100,460,130);//LOgin space
	bar(190,155,460,185); //PASS Lo/ higher than the text 15
	bar(190,210,460,240); // display text below 5
	bar(190,265,460,295); //ID login space
	bar(190,320,460,350);
	bar(190 + textwidth("PHAI (NAM:0 - NU:1) "),355,460,385);
	setbkcolor(11);
	setcolor(0); //set text color

	//delay(1000000);
}

void InputSV(nodeL &SubL) {

	ReadL(SubL);
	cleardevice();
	SV_UI();
	int w = textwidth("PHAI (NAM:0 - NU:1) ");
	DisText mal_sv(16), masv(53), pass(53), passhd(53), ho(53), ten(53), phai(2);
	char mal, ma, h, t, p, ph, thoat, comfirm;
	int enter = 0; // bien xuong dong
	do{
		if(enter == 0) {
			setcolor(12); //
			rectangle(190,100,460,130); // cho biet dc la dang o vi tri
			mal = getch();
			setcolor(0);
			setbkcolor(11);
			if(mal == 13) { //enter hoac mui ten xuong
				enter++;
				setcolor(0);
				rectangle(190,100,460,130);
			}
			else if(mal == 27) {
				mal_sv.emptytext();
				masv.emptytext();
				pass.emptytext();
				passhd.emptytext();
				ho.emptytext();
				ten.emptytext();
				phai.emptytext();
				enter = 6;
			}

			else if(mal == 63) {
				mal_sv.emptytext();
				masv.emptytext();
				pass.emptytext();
				passhd.emptytext();
				ho.emptytext();
				ten.emptytext();
				phai.emptytext();
				SV_UI();
			}
			else if (mal == 59) {
				outtextxy(200,215,pass.distext());
				delay(3000);
				outtextxy(200,215,passhd.distext());
			}
			else if (mal == 8||mal == 127){
				mal_sv.deltext();
				//cleardevice();
				SV_UI();
				outtextxy(200,105,mal_sv.distext());
				outtextxy(200,160,masv.distext());
				outtextxy(200,215,passhd.distext());
				outtextxy(200,270,ho.distext());
				outtextxy(200,325,ten.distext());
				outtextxy(210+w,360,phai.distext());
			}
			else if ((mal >= 48 && mal <= 57)|| (mal >= 65&& mal <= 90)||(mal >= 97&& mal <= 122)) {
				if(!mal_sv.FullText() && textwidth(mal_sv.distext()) <= 242) {
					mal_sv.addtext(mal);
					outtextxy(200,105,mal_sv.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,400,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(200,400,"                         ");
					setbkcolor(11);
				}
			}
		}
		else if(enter == 1) {
			setcolor(12);
			rectangle(190,155,460,185); // cho biet dc o vi tri
			ma = getch();
			setcolor(0);
			if(ma == 13) {
				enter++;
				setcolor(0);
				rectangle(190,155,460,185);
			}
			else if(ma == 9) {
				enter--;
				setcolor(0);
				rectangle(190,155,460,185);
			}
			else if(ma == 27) {
				mal_sv.emptytext();
				masv.emptytext();
				pass.emptytext();
				passhd.emptytext();
				ho.emptytext();
				ten.emptytext();
				phai.emptytext();
				enter = 6;
			}

			else if(ma == 63) {
				mal_sv.emptytext();
				masv.emptytext();
				pass.emptytext();
				passhd.emptytext();
				ho.emptytext();
				ten.emptytext();
				phai.emptytext();
				enter = 0;
				SV_UI();
			}
			else if (ma == 59) {
				outtextxy(200,215,pass.distext());
				delay(3000);
				outtextxy(200,215,passhd.distext());
			}
			else if (ma == 8||ma == 127){
				if(masv.NullText()) {
					enter--;
					setcolor(0);
					rectangle(190,155,460,185);
				}
				masv.deltext();
				//cleardevice();
				SV_UI();
				outtextxy(200,105,mal_sv.distext());
				outtextxy(200,160,masv.distext());
				outtextxy(200,215,passhd.distext());
				outtextxy(200,270,ho.distext());
				outtextxy(200,325,ten.distext());
				outtextxy(210+w,360,phai.distext());
			}
			//normal character without any speacial cases
			else if ((ma >= 48 && ma <= 57)|| (ma >= 65&& ma <= 90)||(ma >= 97&& ma <= 122)) {
				if(!masv.FullText() && textwidth(masv.distext()) <= 242) {
					masv.addtext(ma);
					outtextxy(200,160,masv.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,400,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(200,400,"                         ");
					setbkcolor(11);
				}
			}
		}
			//special case
		else if(enter == 2) {
			setcolor(12);
			rectangle(190,210,460,240); // cho biet dc o vi tri
			p = getch();
			setcolor(0);
			if(p == 13) {
				enter++;
				setcolor(0);
				rectangle(190,210,460,240);
			}
			else if(p == 9) {
				enter--;
				setcolor(0);
				rectangle(190,210,460,240);
			}
			else if(p == 27) {
				mal_sv.emptytext();
				masv.emptytext();
				pass.emptytext();
				passhd.emptytext();
				ho.emptytext();
				ten.emptytext();
				phai.emptytext();
				enter = 6;
			}

			else if(p == 63) {
				mal_sv.emptytext();
				masv.emptytext();
				pass.emptytext();
				passhd.emptytext();
				ho.emptytext();
				ten.emptytext();
				phai.emptytext();
				enter = 0;
				SV_UI();
			}
			else if (p == 59) {
				outtextxy(200,215,pass.distext());
				delay(3000);
				outtextxy(200,215,passhd.distext());
			}
			else if (p == 8||p == 127){
				if(pass.NullText()) {
					enter--;
					setcolor(0);
					rectangle(190,210,460,240);
				}
				pass.deltext();
				passhd.deltext();
				//cleardevice();
				SV_UI();
				outtextxy(200,105,mal_sv.distext());
				outtextxy(200,160,masv.distext());
				outtextxy(200,215,passhd.distext());
				outtextxy(200,270,ho.distext());
				outtextxy(200,325,ten.distext());
				outtextxy(210+w,360,phai.distext());
			}
			//normal character without any speacial cases
			else if ((p>= 48 && p <= 57)|| (p >= 65&& p <= 90)||(p >= 97&& p <= 122) || p == 32) {
				if(!pass.FullText() && textwidth(pass.distext()) <= 242) {
					pass.addtext(p);
					passhd.addtext('*');
					outtextxy(200,215,passhd.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,400,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(200,400,"                         ");
					setbkcolor(11);
				}
			}
		}
		else if(enter == 3) {
			setcolor(12);
			rectangle(190,265,460,295); // cho biet dc o vi tri
			h = getch();
			setcolor(0);
			if(h == 13) {
				enter++;
				setcolor(0);
				rectangle(190,265,460,295);
			}
			else if(h == 9) {
				enter--;
				setcolor(0);
				rectangle(190,265,460,295);
			}
			else if(h == 27) {
				mal_sv.emptytext();
				masv.emptytext();
				pass.emptytext();
				passhd.emptytext();
				ho.emptytext();
				ten.emptytext();
				phai.emptytext();
				enter = 6;
			}

			else if(h == 63) {
				mal_sv.emptytext();
				masv.emptytext();
				pass.emptytext();
				passhd.emptytext();
				ho.emptytext();
				ten.emptytext();
				phai.emptytext();
				enter = 0;
				SV_UI();
			}
			else if (h == 59) {
				outtextxy(200,215,pass.distext());
				delay(3000);
				outtextxy(200,215,passhd.distext());
			}
			else if (h == 8||h == 127){
				if(ho.NullText()) {
					enter--;
					setcolor(0);
					rectangle(190,265,460,295);
				}
				ho.deltext();
				//cleardevice();
				SV_UI();
				outtextxy(200,105,mal_sv.distext());
				outtextxy(200,160,masv.distext());
				outtextxy(200,215,passhd.distext());
				outtextxy(200,270,ho.distext());
				outtextxy(200,325,ten.distext());
				outtextxy(210+w,360,phai.distext());
			}
			//normal character without any speacial cases
			else if ((h>= 48 && h <= 57)|| (h >= 65&& h <= 90)||(h >= 97&& h <= 122) || h == 32) {
				if(!ho.FullText() && textwidth(ho.distext()) <= 242) {
					ho.addtext(h);
					outtextxy(200,270,ho.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,400,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(200,400,"                         ");
					setbkcolor(11);
				}
			}
		}
		else if(enter == 4) {
			setcolor(12);
			rectangle(190,320,460,350); // cho biet dc o vi tri
			t = getch();
			setcolor(0);
			if(t == 13) {
				enter++;
				setcolor(0);
				rectangle(190,320,460,350);
			}
			else if(t == 9) {
				enter--;
				setcolor(0);
				rectangle(190,320,460,350);
			}
			else if(t == 27) {
				mal_sv.emptytext();
				masv.emptytext();
				pass.emptytext();
				passhd.emptytext();
				ho.emptytext();
				ten.emptytext();
				phai.emptytext();
				enter = 6;
			}

			else if(t == 63) {
				mal_sv.emptytext();
				masv.emptytext();
				pass.emptytext();
				passhd.emptytext();
				ho.emptytext();
				ten.emptytext();
				phai.emptytext();
				enter = 0;
				SV_UI();
			}
			else if (t == 59) {
				outtextxy(200,215,pass.distext());
				delay(3000);
				outtextxy(200,215,passhd.distext());
			}
			else if (t == 8||t == 127){
				if(ten.NullText()) {
					enter--;
					setcolor(0);
					rectangle(190,320,460,350);
				}
				ten.deltext();
				//cleardevice();
				SV_UI();
				outtextxy(200,105,mal_sv.distext());
				outtextxy(200,160,masv.distext());
				outtextxy(200,215,passhd.distext());
				outtextxy(200,270,ho.distext());
				outtextxy(200,325,ten.distext());
				outtextxy(210+w,360,phai.distext());
			}
			//normal character without any speacial cases
			else if ((t>= 48 && t <= 57)|| (t >= 65&& t <= 90)||(t >= 97&& t <= 122) || t == 32) {
				if(!ten.FullText() && textwidth(ten.distext()) <= 242) {
					ten.addtext(t);
					outtextxy(200,325,ten.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,400,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(200,400,"                         ");
					setbkcolor(11);
				}
			}
		}
		else if(enter == 5) {
			setcolor(12);
			rectangle(190 + w,355,460,385); // cho biet dc o vi tri
			ph = getch();
			setcolor(0);
			if(ph == 13) {
				setcolor(0);
				rectangle(190 + w,355,460,385);
				int i = CheckL(mal_sv.distext(),SubL);
				if(mal_sv.NullText()) {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,400,"BAN CHUA NHAP MA LOP");
					delay(1000);
					outtextxy(200,400,"                    ");
					setbkcolor(11);
					enter = 0;
				}
				else if(CheckL(mal_sv.distext(),SubL) == -1) {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,400,"MA LOP KHONG TON TAI");
					delay(1000);
					outtextxy(200,400,"                    ");
					setbkcolor(11);
					enter = 0;
				}
				else if(masv.NullText()) {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,400,"CHUA NHAP MA SINH VIEN");
					delay(1000);
					outtextxy(200,400,"                      ");
					setbkcolor(11);
					enter = 1;
				}
				else if(pass.NullText()) {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,400,"BAN CHUA NHAP MAT KHAU");
					delay(1000);
					outtextxy(200,400,"                      ");
					setbkcolor(11);
					enter = 2;
				}
				else if(ho.NullText()) {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,400,"BAN CHUA NHAP HO");
					delay(1000);
					outtextxy(200,400,"                ");
					setbkcolor(11);
					enter = 3;
				}
				else if(ten.NullText()) {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,400,"BAN CHUA NHAP TEN");
					delay(1000);
					outtextxy(200,400,"                 ");
					setbkcolor(11);
					enter = 4;
				}
				else if(phai.NullText()) {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,400,"BAN CHUA NHAP PHAI");
					delay(1000);
					outtextxy(200,400,"                  ");
					setbkcolor(11);
				}
				else {
					if(SubL.DSL[i].slsv == max) {
						setbkcolor(3);
						setcolor(12);
						outtextxy(200,400,"DANH SACH DA DAY");
						delay(1000);
						outtextxy(200,400,"                ");
						setbkcolor(11);
						mal_sv.emptytext();
						masv.emptytext();
						pass.emptytext();
						passhd.emptytext();
						ho.emptytext();
						ten.emptytext();
						phai.emptytext();
					}
					else if(CheckSV(masv.distext(),SubL,i) != NULL) {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,400,"SINH VIEN DA TON TAI");
					delay(1000);
					outtextxy(200,400,"                    ");
					setbkcolor(11);
					enter = 1;
					}
					else {
						setbkcolor(3);
						setcolor(12);
						outtextxy(200,400,"LUU SINH VIEN (Y/N)?");
						comfirm = getch();
						if(comfirm == 'y' || comfirm == 'Y') {
							sinhvien SV;
							strcpy(SubL.DSL[i].malop,mal_sv.distext());
							strcpy(SV.masv,masv.distext());
							strcpy(SV.password,pass.distext());
							strcpy(SV.ho,ho.distext());
							strcpy(SV.ten,ten.distext());
							strcpy(SV.phai,phai.distext());
							InsertLastSV(SubL.DSL[i].DSSV,SV);
							SubL.DSL[i].slsv++;
							WriteL(SubL);
							setbkcolor(3);
							setcolor(12);
							outtextxy(200,400,"DA LUU !            ");
							delay(1000);
							outtextxy(200,400,"                    ");
							masv.emptytext();
							pass.emptytext();
							passhd.emptytext();
							ho.emptytext();
							ten.emptytext();
							phai.emptytext();
							outtextxy(200,400,"TIEP TUC NHAP? (Y/N)");
							thoat = getch();
							if(thoat == 'y' || thoat == 'Y') {
								enter = 1;
								SV_UI();
								outtextxy(200,105,mal_sv.distext());
							}
							else if(thoat == 'n' || thoat == 'N') {
								enter++;
							}
						}
						else if(comfirm == 'n' || comfirm == 'N') {
							enter = 0;
							SV_UI();
							outtextxy(200,105,mal_sv.distext());
							outtextxy(200,160,masv.distext());
							outtextxy(200,215,passhd.distext());
							outtextxy(200,270,ho.distext());
							outtextxy(200,325,ten.distext());
							outtextxy(210+w,360,phai.distext());
						}
					}
				}
			}
			else if(ph == 9) {
				enter--;
				setcolor(0);
				rectangle(190 + w,355,460,385);
			}
			else if(ph == 27) {
				mal_sv.emptytext();
				masv.emptytext();
				pass.emptytext();
				passhd.emptytext();
				ho.emptytext();
				ten.emptytext();
				phai.emptytext();
				enter = 6;
			}

			else if(ph == 63) {
				mal_sv.emptytext();
				masv.emptytext();
				pass.emptytext();
				passhd.emptytext();
				ho.emptytext();
				ten.emptytext();
				phai.emptytext();
				enter = 0;
				SV_UI();
			}
			else if (ph == 59) {
				outtextxy(200,215,pass.distext());
				delay(3000);
				outtextxy(200,215,passhd.distext());
			}
			else if (ph == 8||ph == 127){
				if(phai.NullText()) {
					enter--;
					setcolor(0);
					rectangle(190 + w,355,460,385);
				}
				phai.deltext();
				//cleardevice();
				SV_UI();
				outtextxy(200,105,mal_sv.distext());
				outtextxy(200,160,masv.distext());
				outtextxy(200,215,passhd.distext());
				outtextxy(200,270,ho.distext());
				outtextxy(200,325,ten.distext());
				outtextxy(210+w,360,phai.distext());
			}
			//normal character without any speacial cases
			else if (ph == 48 || ph == 49) {
				if(!phai.FullText()) {
					phai.addtext(ph);
					outtextxy(210 + w,360,phai.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(200,400,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(200,400,"                         ");
					setbkcolor(11);
				}
			}
		}
		else if(enter == 6) {
			setbkcolor(15);
			cleardevice();
			GV_CHOICE(6);
		}
	} while(1);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CAU HOI THI
//////////////
int getBF(PTRCH p);
	void ReupBal(PTRCH &root);
	// right rotate function
	// this funtion for tree moving more to the left
	PTRCH RotateR(PTRCH T){
		PTRCH p= T->left;
		T->left  = p->right;
		p->right = T;
		return p;
	}
	// left rotate function
	PTRCH RotateL(PTRCH T){
		PTRCH p= T->right;
		T->right  = p->left;
		p->left = T;
		return p;
	}
	// double right left rotate function
	//cay con trai lech phai	
	PTRCH RotateLR(PTRCH T){
		PTRCH u = T->left;
		PTRCH p = u->right;
		u->right = p->left;
		p->left  = u;
		T->left  = p->right;
		p->right = T;
		return p;
	}
	// double left right rotate function
	// cay con phai lech trai
	PTRCH RotateRL(PTRCH T){
		PTRCH u = T->right;
		PTRCH p = u->left;
		u->left = p->right;
		p->right  = u;
		T->right = p->left;
		p->left = T;
		return p;
	}
	// add new node function
	
	int maxHeight(PTRCH node)  
	{  
    	if (node == NULL)  
        	return 0;  
    	else
    	{  
        /* compute the height of each subtree */
        	int lHeight = maxHeight(node->left);  
        	int rHeight = maxHeight(node->right);  
      
        	/* use the larger one */
        	if (lHeight > rHeight)  
            	return(lHeight + 1);  
        	else return(rHeight + 1);  
    	}  
	}	  

	void Add(PTRCH &p, int x,cauhoi c){
		p 			= 	new nodeCH;
		p->ch.id	=	x;
		strcpy(p->ch.mamh,c.mamh);
		strcpy(p->ch.info,c.info);
		strcpy(p->ch.A ,c.A);
		strcpy(p->ch.B ,c.B);
		strcpy(p->ch.C ,c.C);
		strcpy(p->ch.D ,c.D);
		strcpy(p->ch.ans,c.ans);
		//p->ch.ans = c.ans;
		p->left		=	NULL;
		p->right	=	NULL;
		p->bf		=	0;
	}
	// Insert function
	void Insert_node(PTRCH &p, int x,cauhoi c){
		if(p==NULL)
			Add(p,x,c);
		else 
		{
			if(x<p->ch.id)
			{
				Insert_node(p->left,x,c);
				if(maxHeight(p->left)-maxHeight(p->right)==2)
					if(x<p->left->ch.id)
						p=RotateR(p);
					else p=RotateLR(p);
			}
			else if(x>p->ch.id)
			{
				Insert_node(p->right,x,c);
				if(maxHeight(p->left)-maxHeight(p->right)==-2)
					if(x>p->right->ch.id)
						p=RotateL(p);
					else p=RotateRL(p);
			}	
		}
		ReupBal(p);
	}
// delete

// cap nhat lai gia tri BF cho tung nodes
	int getBF(PTRCH p){
			int hL,hR;
			hL = maxHeight(p->left);
			hR = maxHeight(p->right);
			return p->bf=hL-hR;
		}
// Function reup the bf of nodes in tree
// in this function i use preorder function to traverse all the tree and re-update the bf of every nodes 
	void ReupBal(PTRCH &root){
	
		int const size=100;
		PTRCH Stack[size];
		int sp = -1;	// hang doi rong
		PTRCH p  = root; // cho p = root de duyet tu dau
		while(p!=NULL){
			
			p->bf = getBF(p);
			
			if(p->right!=NULL)
				Stack[++sp]=p->right;
			if(p->left!=NULL)
				p=p->left;
			else if(sp==-1)
				break;
			else p=Stack[sp--];
		}
	}
	void Preorder(PTRCH p){
			if( p != NULL)
		{
		cout<<p->ch.id<<":";
			//cout<<p->bf<<"/";
			cout<<p->ch.mamh<<"/";
			cout<<p->ch.info<<"/";
			cout<<p->ch.A<<"/";
			cout<<p->ch.B<<"/";
			cout<<p->ch.C<<"/";
			cout<<p->ch.D<<"/";
			cout<<p->ch.ans<<endl;
			Preorder(p->left);
			Preorder(p->right);
		}
	}
///////////////
	int Random(){
		 // hàm cho phép t?o ra giá tr? ng?u nhiên theo th?i gian th?c
		int x = rand()%50000;
		return x;
	}
	int randomab(int a,int b){
		int x = rand()%(b-a+1)+a;
		return x;
	}
//// ghi cau hoi vao file
		void writeCH(PTRCH p){
		ofstream fw("D:\\New folder\\DSCH.txt",ios_base::out|ios_base::app);
		if(!fw.fail())
		{
			if(p!=NULL)
			{	
				fw<<p->ch.id<<endl;
				fw<<p->ch.mamh<<endl;
				fw<<p->ch.info<<endl;
				fw<<p->ch.A<<endl;
				fw<<p->ch.B<<endl;
				fw<<p->ch.C<<endl;
				fw<<p->ch.D<<endl;
				fw<<p->ch.ans<<endl;
				writeCH(p->left);
				writeCH(p->right);
			}
			fw.close();
		}
	}
/////// read questions from file
	void readCH(PTRCH &p){
		int x;
		cauhoi c;
		ifstream fr("D:\\New folder\\DSCH.txt",ios_base::in|ios_base::app);
		if(fr.fail())
			return;
		while(!fr.eof()){
				char *t= new char[10];
			fr.getline(t,10);
			x= atoi(t);	
			fr.getline(c.mamh,100);
			fr.getline(c.info,100);
			fr.getline(c.A,100);
			fr.getline(c.B,100);
			fr.getline(c.C,100);
			fr.getline(c.D,100);
			fr.getline(c.ans,3);
			//fr>>c.ans;
			Insert_node(p, x,c);
		}
	}
/////////////
void CH_UI() {

	setbkcolor(15);					// set background
   	cleardevice();
	setcolor(2);       // set text color
	setfillstyle(1,14);
	bar(20,30,620,60);
	rectangle(20,30,620,60); // rectangle->setfillstyle->setbar
	line( 60,60 ,580 ,60);
	bar(20,30,620,420);
	rectangle(20,30,620,420);
	setfillstyle(1,3);
	bar(20,60,620,420);
	setbkcolor(14);
	setcolor(0);
	settextjustify(CENTER_TEXT,TOP_TEXT);
	settextstyle(8,0,1);  // kieu chu: 1-8, huong chu, do lon chu
	outtextxy(320,35,"NHAP VAO CAU HOI");
	setcolor(1);
	setbkcolor(15);
	outtextxy(120,440,"[F5]:lam moi trang");
	setcolor(12);
	outtextxy(80,5,"[ESC]:thoat");
	outtextxy(80 + textwidth("////") + textwidth("[ESC]:thoat"),5,"[TAB]:len dong");
	outtextxy(80 + textwidth("////////") + textwidth("[ESC]:thoat") + textwidth("[TAB]:len dong "),5,"[ENTER]:xac nhan");
	setbkcolor(3);
	setcolor(0);
	settextjustify(LEFT_TEXT,TOP_TEXT);
	setbkcolor(3);
	outtextxy(50,90 ,"MA MON HOC");
	outtextxy(50,135,"CAU HOI");
	outtextxy(50,180,"CAU A  ");
	outtextxy(50,225,"CAU B  ");
	outtextxy(50,270,"CAU C  ");
	outtextxy(50,315,"CAU D  ");
	outtextxy(50,360,"DAP AN ");
	int t = textwidth("MA MON HOC ");
	setfillstyle(1,11);
	setcolor(0);
	rectangle( 50+t,85 ,600,115);
	rectangle( 20+t,130 ,600,160);
	rectangle( 20+t,175 ,600,205);
	rectangle( 20+t,220 ,600,250);
	rectangle( 20+t,265 ,600,295);
	rectangle( 20+t,310 ,600,340);
	rectangle( 20+t,355 ,20+t+30,385);
	bar( 50+t,85 ,600,115);
	bar( 20+t,130 ,600,160);
	bar( 20+t,175 ,600,205);
	bar( 20+t,220 ,600,250);
	bar( 20+t,265 ,600,295);
	bar( 20+t,310 ,600,340);
	bar( 20+t,355 ,20+t+30,385);
	setbkcolor(11);
	setcolor(0);

}
int CheckMH_CH(char *ch ,nodeMH &SubMH) {
	for (int i = 0; i <= SubMH.slmh; i++) {
		if(strcmp(ch,SubMH.DSMH[i]->mamh) == 0)
			return 1;
	}
	return 0;
}
void InputCH(PTRCH &p) {
	nodeMH list;// danh sach mon hoc
	ReadMH(list);
	//readCH(p);	
	cleardevice();
	CH_UI();
	int t = textwidth("MA MON HOC ");
	setbkcolor(3);
	ID = rand()%1000000 + 1;
	char *id_ch = new char[10];
	itoa(ID,id_ch,10);
	outtextxy(65 + t,360,"ID:");
	outtextxy(100 + t,360,id_ch);
	setbkcolor(11);
	setcolor(0);
	DisText mamh_ch(16), info(53), A(53), B(53), C(53), D(53), ans(2);
	char ma, inf, a, b, c, d, dapan,thoat, comfirm;
	int enter = 0; // bien xuong dong
	do{
		if(enter == 0) {
			setcolor(12); //
			rectangle(50+t,85 ,600,115); // cho biet dc la dang o vi tri
			ma = getch();
			setcolor(0);
			setbkcolor(11);
			if(ma == 13) { //enter hoac mui ten xuong
				if(CheckMH_CH(mamh_ch.distext(),list)==0)
				{
					setbkcolor(3);
					setcolor(12);
					outtextxy(70+t,400,"MA MON HOC KHONG TON TAI");
					delay(1000);
					outtextxy(70+t,400,"                         ");
					setbkcolor(11);
					setcolor(12); //
					rectangle(50+t,85 ,600,115);
					enter=0;
				}
				else{
					enter++;
					setcolor(0);
					rectangle(50+t,85 ,600,115);
				}
			}
			else if(ma == 27) {
				mamh_ch.emptytext();
				info.emptytext();
				A.emptytext();
				B.emptytext();
				C.emptytext();
				D.emptytext();
				ans.emptytext();
				enter = 7;
			}

			else if(ma == 63) {
				mamh_ch.emptytext();
				info.emptytext();
				A.emptytext();
				B.emptytext();
				C.emptytext();
				D.emptytext();
				ans.emptytext();
				CH_UI();
				setbkcolor(3);
				ID = rand()%1000000 + 1;
				char *id_ch = new char[10];
				itoa(ID,id_ch,10);
				outtextxy(65 + t,360,"ID:");
				outtextxy(100 + t,360,id_ch);
			}
			else if (ma == 8||ma == 127){
				mamh_ch.deltext();
				//cleardevice();
				CH_UI();
				outtextxy(60+t,90,mamh_ch.distext());
				outtextxy(60+t,135,info.distext());
				outtextxy(60+t,180,A.distext());
				outtextxy(60+t,225,B.distext());
				outtextxy(60+t,270,C.distext());
				outtextxy(60+t,315,D.distext());
				outtextxy(60+t,360,ans.distext());
				setbkcolor(3);
				outtextxy(65 + t,360,"ID:");
				outtextxy(100 + t,360,id_ch);
				setbkcolor(11);
			}
			else if ((ma >= 48 && ma <= 57)|| (ma >= 65&& ma <= 90)||(ma >= 97&& ma <= 122)) {
				if(!mamh_ch.FullText() && textwidth(mamh_ch.distext()) <= 418) {
					mamh_ch.addtext(ma);
					outtextxy(60+t,90,mamh_ch.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(70+t,400,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(70+t,400,"                         ");
					setbkcolor(11);
				}
			}
		}
		else if(enter == 1) {
			setcolor(12); //
			rectangle( 20+t,130 ,600,160); // cho biet dc la dang o vi tri
			inf = getch();
			setcolor(0);
			setbkcolor(11);
			if(inf == 13) { //enter hoac mui ten xuong
				enter++;
				setcolor(0);
				rectangle( 20+t,130 ,600,160);
			}
			else if(inf == 27) {
				mamh_ch.emptytext();
				info.emptytext();
				A.emptytext();
				B.emptytext();
				C.emptytext();
				D.emptytext();
				ans.emptytext();
				enter = 7;
			}
			else if(inf == 9){
				setcolor(12); 
				rectangle(50+t,85 ,600,115);
				setcolor(0);
				rectangle( 20+t,130 ,600,160);
				enter--; 
			}
			else if(inf == 0) {
				inf = getch();
				if(inf==63)
				{
				mamh_ch.emptytext();
				info.emptytext();
				A.emptytext();
				B.emptytext();
				C.emptytext();
				D.emptytext();
				ans.emptytext();
				CH_UI();
				setbkcolor(3);
				ID = rand()%1000000 + 1;
				char *id_ch = new char[10];
				itoa(ID,id_ch,10);
				outtextxy(65 + t,360,"ID:");
				outtextxy(100 + t,360,id_ch);
				enter = 0;
				}
			}
			else if (inf == 8||inf == 127){
				if(info.NullText()) {
					enter--;
					setcolor(0);
					rectangle( 20+t,130 ,600,160);
				}
				info.deltext();
				//cleardevice();
				CH_UI();
				outtextxy(60+t,90,mamh_ch.distext());
				outtextxy(30+t,135,info.distext());
				outtextxy(30+t,180,A.distext());
				outtextxy(30+t,225,B.distext());
				outtextxy(30+t,270,C.distext());
				outtextxy(30+t,315,D.distext());
				outtextxy(30+t,360,ans.distext());
				setbkcolor(3);
				outtextxy(65 + t,360,"ID:");
				outtextxy(100 + t,360,id_ch);
				setbkcolor(11);
			}
			else if ((inf >= 48 && inf <= 57)|| (inf >= 65&& inf <= 90)||(inf >= 97&& inf <= 122)||(inf=='?')||(inf=='+')||(inf=='-')||(inf=='*')||(inf=='/')||(inf=='=')||(inf==32)) {
				if(!info.FullText() && textwidth(info.distext()) <= 430) {
					info.addtext(inf);
					outtextxy(30+t,135,info.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(70+t,400,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(70+t,400,"                         ");
					setbkcolor(11);
				}
			}
		}
		else if(enter == 2) {
			setcolor(12); //
			rectangle( 20+t,175 ,600,205); // cho biet dc la dang o vi tri
			a = getch();
			setcolor(0);
			setbkcolor(11);
			if(a == 13) { //enter hoac mui ten xuong
				enter++;
				setcolor(0);
				rectangle( 20+t,175 ,600,205);
			}
			else if(a == 9){
				setcolor(12); 
				rectangle(20+t,130 ,600,160);
				setcolor(0);
				rectangle( 20+t,175 ,600,205);
				enter--; 
			}
			else if(a == 27) {
				mamh_ch.emptytext();
				info.emptytext();
				A.emptytext();
				B.emptytext();
				C.emptytext();
				D.emptytext();
				ans.emptytext();
				enter = 7;
			}

			else if(a == 0) {
				a = getch();
				if(a==63)
				{
				mamh_ch.emptytext();
				info.emptytext();
				A.emptytext();
				B.emptytext();
				C.emptytext();
				D.emptytext();
				ans.emptytext();
				CH_UI();
				setbkcolor(3);
				ID = rand()%1000000 + 1;
				char *id_ch = new char[10];
				itoa(ID,id_ch,10);
				outtextxy(65 + t,360,"ID:");
				outtextxy(100 + t,360,id_ch);
				enter = 0;
				}
			}
			else if (a == 8||a == 127){
				if(A.NullText()) {
					enter--;
					setcolor(0);
					rectangle( 20+t,175 ,600,205);
				}
				A.deltext();
				//cleardevice();
				CH_UI();
				outtextxy(60+t,90,mamh_ch.distext());
				outtextxy(30+t,135,info.distext());
				outtextxy(30+t,180,A.distext());
				outtextxy(30+t,225,B.distext());
				outtextxy(30+t,270,C.distext());
				outtextxy(30+t,315,D.distext());
				outtextxy(30+t,360,ans.distext());
				setbkcolor(3);
				outtextxy(65 + t,360,"ID:");
				outtextxy(100 + t,360,id_ch);
				setbkcolor(11);
			}
			else if ((a >= 48 && a <= 57)|| (a >= 65&& a <= 90)||(a >= 97&& a <= 122) || a == 32||(a=='?')||(a=='+')||(a=='-')||(a=='*')||(a=='/')||(a=='=')) {
				if(!A.FullText() && textwidth(A.distext()) <= 430) {
					A.addtext(a);
					outtextxy(30+t,180,A.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(70+t,400,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(70+t,400,"                         ");
					setbkcolor(11);
				}
			}
		}
		else if(enter == 3) {
			setcolor(12); //
			rectangle( 20+t,220 ,600,250); // cho biet dc la dang o vi tri
			b = getch();
			setcolor(0);
			setbkcolor(11);
			if(b == 13) { //enter hoac mui ten xuong
				enter++;
				setcolor(0);
				rectangle( 20+t,220 ,600,250);
			}
			else if(b == 9){
				setcolor(12); 
				rectangle(20+t,175 ,600,205);
				setcolor(0);
				rectangle( 20+t,220 ,600,250);
				enter--; 
			}
			else if(b == 27) {
				mamh_ch.emptytext();
				info.emptytext();
				A.emptytext();
				B.emptytext();
				C.emptytext();
				D.emptytext();
				ans.emptytext();
				enter = 7;
			}

			else if(b == 0) {
				b = getch();
				if(b==63)
				{
				mamh_ch.emptytext();
				info.emptytext();
				A.emptytext();
				B.emptytext();
				C.emptytext();
				D.emptytext();
				ans.emptytext();
				CH_UI();
				setbkcolor(3);
				ID = rand()%1000000 + 1;
				char *id_ch = new char[10];
				itoa(ID,id_ch,10);
				outtextxy(65 + t,360,"ID:");
				outtextxy(100 + t,360,id_ch);
				enter = 0;
				}
			}
			else if (b == 8||b == 127){
				if(B.NullText()) {
					enter--;
					setcolor(0);
					rectangle( 20+t,220 ,600,250);
				}
				B.deltext();
				//cleardevice();
				CH_UI();
				outtextxy(60+t,90,mamh_ch.distext());
				outtextxy(30+t,135,info.distext());
				outtextxy(30+t,180,A.distext());
				outtextxy(30+t,225,B.distext());
				outtextxy(30+t,270,C.distext());
				outtextxy(30+t,315,D.distext());
				outtextxy(30+t,360,ans.distext());
				setbkcolor(3);
				outtextxy(65 + t,360,"ID:");
				outtextxy(100 + t,360,id_ch);
				setbkcolor(11);
			}
			else if ((b >= 48 && b <= 57)|| (b >= 65&& b <= 90)||(b >= 97&& b <= 122) || b == 32||(b=='?')||(b=='+')||(b=='-')||(b=='*')||(b=='/')||(b=='=')) {
				if(!B.FullText() && textwidth(B.distext()) <= 430) {
					B.addtext(b);
					outtextxy(30+t,225,B.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(70+t,400,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(70+t,400,"                         ");
					setbkcolor(11);
				}
			}
		}
		else if(enter == 4) {
			setcolor(12); //
			rectangle( 20+t,265 ,600,295); // cho biet dc la dang o vi tri
			c = getch();
			setcolor(0);
			setbkcolor(11);
			if(c == 13) { //enter hoac mui ten xuong
				enter++;
				setcolor(0);
				rectangle( 20+t,265 ,600,295);
			}
			else if(c == 9){
				setcolor(12); 
				rectangle(20+t,220 ,600,250);
				setcolor(0);
				rectangle( 20+t,265 ,600,295);
				enter--; 
			}
			else if(c == 27) {
				mamh_ch.emptytext();
				info.emptytext();
				A.emptytext();
				B.emptytext();
				C.emptytext();
				D.emptytext();
				ans.emptytext();
				enter = 7;
			}

			else if(c == 0) {
				c = getch();
				if(c==63)
				{
				mamh_ch.emptytext();
				info.emptytext();
				A.emptytext();
				B.emptytext();
				C.emptytext();
				D.emptytext();
				ans.emptytext();
				CH_UI();
				setbkcolor(3);
				ID = rand()%1000000 + 1;
				char *id_ch = new char[10];
				itoa(ID,id_ch,10);
				outtextxy(65 + t,360,"ID:");
				outtextxy(100 + t,360,id_ch);
				enter = 0;
				}
			}
			else if (c == 8||c == 127){
				if(C.NullText()) {
					enter--;
					setcolor(0);
					rectangle( 20+t,265 ,600,295);
				}
				C.deltext();
				//cleardevice();
				CH_UI();
				outtextxy(60+t,90,mamh_ch.distext());
				outtextxy(30+t,135,info.distext());
				outtextxy(30+t,180,A.distext());
				outtextxy(30+t,225,B.distext());
				outtextxy(30+t,270,C.distext());
				outtextxy(30+t,315,D.distext());
				outtextxy(30+t,360,ans.distext());
				setbkcolor(3);
				outtextxy(65 + t,360,"ID:");
				outtextxy(100 + t,360,id_ch);
				setbkcolor(11);
			}
			else if ((c >= 48 && c <= 57)|| (c >= 65&& c <= 90)||(c >= 97&& c <= 122) || c == 32||(c=='?')||(c=='+')||(c=='-')||(c=='*')||(c=='/')||(c=='=')) {
				if(!C.FullText() && textwidth(C.distext()) <= 430) {
					C.addtext(c);
					outtextxy(30+t,270,C.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(70+t,400,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(70+t,400,"                         ");
					setbkcolor(11);
				}
			}
		}
		else if(enter == 5) {
			setcolor(12); //
			rectangle( 20+t,310 ,600,340); // cho biet dc la dang o vi tri
			d = getch();
			setcolor(0);
			setbkcolor(11);
			if(d == 13) { //enter hoac mui ten xuong
				enter++;
				setcolor(0);
				rectangle( 20+t,310 ,600,340);
			}
			else if(d == 9){
			
				setcolor(0);
				rectangle(20+t,310 ,600,340);
				enter--; 
			}
			else if(d == 27) {
				mamh_ch.emptytext();
				info.emptytext();
				A.emptytext();
				B.emptytext();
				C.emptytext();
				D.emptytext();
				ans.emptytext();
				enter = 7;
			}

			else if(d == 0) {
				d = getch();
				if(d==63)
				{
				mamh_ch.emptytext();
				info.emptytext();
				A.emptytext();
				B.emptytext();
				C.emptytext();
				D.emptytext();
				ans.emptytext();
				CH_UI();
				setbkcolor(3);
				ID = rand()%1000000 + 1;
				char *id_ch = new char[10];
				itoa(ID,id_ch,10);
				outtextxy(65 + t,360,"ID:");
				outtextxy(100 + t,360,id_ch);
				enter = 0;
				}
			}
			else if (d == 8||d == 127){
				if(D.NullText()) {
					enter--;
					setcolor(0);
					rectangle( 20+t,310 ,600,340);
				}
				D.deltext();
				//cleardevice();
				CH_UI();
				outtextxy(60+t,90,mamh_ch.distext());
				outtextxy(30+t,135,info.distext());
				outtextxy(30+t,180,A.distext());
				outtextxy(30+t,225,B.distext());
				outtextxy(30+t,270,C.distext());
				outtextxy(30+t,315,D.distext());
				outtextxy(30+t,360,ans.distext());
				setbkcolor(3);
				outtextxy(65 + t,360,"ID:");
				outtextxy(100 + t,360,id_ch);
				setbkcolor(11);
			}
			else if ((d >= 48 && d <= 57)|| (d >= 65&& d <= 90)||(d >= 97&& d <= 122) || d == 32||(d=='?')||(d=='+')||(d=='-')||(d=='*')||(d=='/')||(d=='=')) {
				if(!D.FullText() && textwidth(D.distext()) <= 430) {
					D.addtext(d);
					outtextxy(30+t,315,D.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(70+t,400,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(70+t,400,"                         ");
					setbkcolor(11);
				}
			}
		}
		else if(enter == 6) {
			setcolor(12); //
			rectangle( 20+t,355 ,20+t+30,385); // cho biet dc la dang o vi tri
			dapan = getch();
			setcolor(0);
			setbkcolor(11);
			if(dapan == 13) { //enter hoac mui ten xuong
				if(info.NullText()&&A.NullText()&&B.NullText()&&C.NullText()&&D.NullText()&&ans.NullText()){
					setbkcolor(3);
					setcolor(12);
					outtextxy(70+t,400,"BAN CHUA NHAP THONG TIN");
					delay(1000);
					outtextxy(70+t,400,"                         ");
					setbkcolor(11);
					setcolor(0); //
					rectangle( 20+t,355 ,20+t+30,385);
					setcolor(12); //
					rectangle(50+t,85 ,600,115);
					enter=0;
					
				}
				else if(info.NullText()){
					setbkcolor(3);
					setcolor(12);
					outtextxy(70+t,400,"BAN CHUA NHAP CAU HOI");
					delay(1000);
					outtextxy(70+t,400,"                         ");
					setbkcolor(11);
					setcolor(0); //
					rectangle( 20+t,355 ,20+t+30,385);
					enter=1;
					
				}
				else if(A.NullText()){
					setbkcolor(3);
					setcolor(12);
					outtextxy(70+t,400,"BAN CHUA NHAP CAU A");
					delay(1000);
					outtextxy(70+t,400,"                         ");
					setbkcolor(11);
					setcolor(0); //
					rectangle( 20+t,355 ,20+t+30,385);
					enter = 2;
				}
				else if(B.NullText()){
					setbkcolor(3);
					setcolor(12);
					outtextxy(70+t,400,"BAN CHUA NHAP CAU B");
					delay(1000);
					outtextxy(70+t,400,"                         ");
					setbkcolor(11);
					setcolor(0); //
					rectangle( 20+t,355 ,20+t+30,385);
					enter = 3;
				}
				else if(C.NullText()){
					setbkcolor(3);
					setcolor(12);
					outtextxy(70+t,400,"BAN CHUA NHAP CAU C");
					delay(1000);
					outtextxy(70+t,400,"                         ");
					setbkcolor(11);
					setcolor(0); //
					rectangle( 20+t,355 ,20+t+30,385);
					enter = 4;
				}
				else if(D.NullText()){
					setbkcolor(3);
					setcolor(12);
					outtextxy(70+t,400,"BAN CHUA NHAP CAU D");
					delay(1000);
					outtextxy(70+t,400,"                         ");
					setbkcolor(11);
					setcolor(0); //
					rectangle( 20+t,355 ,20+t+30,385);
					enter = 5;
				}
				else if(ans.NullText()){
					setbkcolor(3);
					setcolor(12);
					outtextxy(70+t,400,"BAN CHUA NHAP DAP AN");
					delay(1000);
					outtextxy(70+t,400,"                         ");
					setbkcolor(11);
					setcolor(0); //
					rectangle( 20+t,355 ,20+t+30,385);
					enter = 6;
				}
				else if(!info.NullText()&&!A.NullText()&&!B.NullText()&&!C.NullText()&&!D.NullText()&&!ans.NullText()){
					//readCH(p);
					setbkcolor(3);
					setcolor(12);
					outtextxy(70+t,400,"LUU CAU HOI:Y/N");
					char select = getch();
					if(select=='Y'||select=='y'||select==13){
						cauhoi temp;
						
						strcpy(temp.mamh,mamh_ch.distext());
						strcpy(temp.info,info.distext());
						strcpy(temp.A,A.distext());
						strcpy(temp.B,B.distext());
						strcpy(temp.C,C.distext());
						strcpy(temp.D,D.distext());
						strcpy(temp.ans,ans.distext());
						Insert_node(p,ID,temp);
						writeCH(p);
						outtextxy(70+t,400,"               ");
						
						//setbkcolor(3);
						setcolor(12);
						outtextxy(70+t,400,"SUCCESSFUL");
						delay(1000);
						outtextxy(70+t,400,"                         ");
						mamh_ch.emptytext();
						info.emptytext();
						A.emptytext();
						B.emptytext();
						C.emptytext();
						D.emptytext();
						ans.emptytext();
						CH_UI();
						setbkcolor(3);
						setcolor(0); //
						rectangle(50+t,85 ,600,115);
						ID = rand()%1000000 + 1;
						char *id_ch = new char[10];
						itoa(ID,id_ch,10);
						outtextxy(65 + t,360,"ID:");
						outtextxy(100 + t,360,id_ch);
						enter=0;
					}
				}
			}
			else if(dapan == 9){
			
				setcolor(0);
				rectangle(20+t,355 ,20+t+30,385);
				enter--; 
			}
			else if(dapan == 27) {
				mamh_ch.emptytext();
				info.emptytext();
				A.emptytext();
				B.emptytext();
				C.emptytext();
				D.emptytext();
				ans.emptytext();
				enter = 7;
			}

			else if(dapan == 0) {
				dapan = getch();
				if(dapan==63)
				{
				mamh_ch.emptytext();
				info.emptytext();
				A.emptytext();
				B.emptytext();
				C.emptytext();
				D.emptytext();
				ans.emptytext();
				CH_UI();
				setbkcolor(3);
				ID = rand()%1000000 + 1;
				char *id_ch = new char[10];
				itoa(ID,id_ch,10);
				outtextxy(65 + t,360,"ID:");
				outtextxy(100 + t,360,id_ch);
				enter = 0;
				}
			}
			else if (dapan == 8||dapan == 127){
				if(ans.NullText()) {
					enter--;
					setcolor(0);
					rectangle( 20+t,355 ,20+t+30,385);
				}
				ans.deltext();
				//cleardevice();
				CH_UI();
				outtextxy(60+t,90,mamh_ch.distext());
				outtextxy(30+t,135,info.distext());
				outtextxy(30+t,180,A.distext());
				outtextxy(30+t,225,B.distext());
				outtextxy(30+t,270,C.distext());
				outtextxy(30+t,315,D.distext());
				outtextxy(30+t,360,ans.distext());
				setbkcolor(3);
				outtextxy(65 + t,360,"ID:");
				outtextxy(100 + t,360,id_ch);
				setbkcolor(11);
			}
			else if (dapan >= 65 && dapan <= 68 || dapan >= 97 && dapan <= 100) {
				if(!ans.FullText() && textwidth(ans.distext()) <= 430) {
					ans.addtext(dapan);
					outtextxy(30+t,360,ans.distext());
				}
				else {
					setbkcolor(3);
					setcolor(12);
					outtextxy(70+t,400,"BAN NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(70+t,400,"                         ");
					setbkcolor(11);
				}
			}
		}
		else if(enter == 7) {
			setbkcolor(15);
			cleardevice();
			GV_CHOICE(7);
		}
	} while(1);
}
/////////////////////////////////////////////////////////////////////////////////////////////////

// GIAO DIEN CUA GIAO VIEN VA CHUYEN CANH
GV_UI() {
	setbkcolor(14);
	setfillstyle(1,14);
	bar(160,60,480,90);
	settextstyle(8,0,1);
	setcolor(9);
	setfillstyle(1,11);
	rectangle(160,60,480,420);
	bar(160,90,480,420);
	line(160,90,480,90);
	settextjustify(CENTER_TEXT,TOP_TEXT);
	setcolor(0);
	outtextxy(320,65,"DANH SACH TUY CHON"); //dis
	setcolor(1);
	setbkcolor(15);
	outtextxy(120,440,"[F5]:len dau trang");
	setcolor(12);
	outtextxy(80,5,"[ESC]:thoat");
	setcolor(2);
	outtextxy(80 + textwidth("////") + textwidth("[ESC]:thoat"),5,"[ ^ ]:len ");
	outtextxy(80 + textwidth("////////") + textwidth("[ESC]:thoat") + textwidth("[ ^ ]:len "),5,"[ v ]:xuong ");
	settextjustify(LEFT_TEXT,TOP_TEXT);
	setbkcolor(11);
	setcolor(0);
	int space = 30;
	for(int i = 0; i <= 9; i++) {
		line(160,90 + space,480,90 + space);
		space += 30;
	}
	outtextxy(180,65 + 30, "NHAP LOP");
	outtextxy(180,65 + 30*2, "DANH SACH LOP");
	outtextxy(180,65 + 30*3, "NHAP MON HOC");
	outtextxy(180,65 + 30*4, "XOA MON HOC");
	outtextxy(180,65 + 30*5, "HIEU CHINH MON HOC");
	outtextxy(180,65 + 30*6, "DANH SACH MON HOC");
	outtextxy(180,65 + 30*7, "NHAP SINH VIEN THEO LOP");
	outtextxy(180,65 + 30*8, "NHAP CAU HOI THEO MON HOC");
}

void GV_CHOICE(int choice) {

	GV_UI();
	nodeL SubL;
	nodeMH SubMH;
	PTRCH p;
	p=NULL;
	char ctrl, comfirm;
	do{
		GV_UI();
		setbkcolor(3);
		setfillstyle(1,3);
		if(choice == 0) {
			rectangle(160,90,480,120);
			bar(160,90,480,120);
			setcolor(0);
			outtextxy(180,65 + 30, "NHAP LOP");
			ctrl = getch();
			if (ctrl == 13) {
				setbkcolor(15);
				InputL(SubL);
			}
		}

		else if (choice == 1) {
			rectangle(160,120,480,150);
			bar(160,120,480,150);
			setcolor(0);
			outtextxy(180,65 + 30*2, "DANH SACH LOP");
			ctrl = getch();
			if (ctrl == 13) {
				setbkcolor(15);
				OutputL(SubL);
			}
		}

		else if(choice == 2) {
			rectangle(160,150,480,180);
			bar(160,150,480,180);
			setcolor(0);
			outtextxy(180,65 + 30*3, "NHAP MON HOC");
			ctrl = getch();
			if (ctrl == 13) {
				setbkcolor(15);
				InputMH(SubMH);
			}
		}
		else if(choice == 3) {
			rectangle(160,180,480,210);
			bar(160,180,480,210);
			setcolor(0);
			outtextxy(180,65 + 30*4, "XOA MON HOC");
			ctrl = getch();
			if (ctrl == 13) {
				setbkcolor(15);
				DeleteMH(SubMH);
			}
		}
		else if(choice == 4) {
			rectangle(160,210,480,240);
			bar(160,210,480,240);
			setcolor(0);
			outtextxy(180,65 + 30*5, "HIEU CHINH MON HOC");
			ctrl = getch();
			if(ctrl == 13) {
				setbkcolor(15);
				FixMH(SubMH);
			}
		}
		else if(choice == 5) {
			rectangle(160,240,480,270);
			bar(160,240,480,270);
			setcolor(0);
			outtextxy(180,65 + 30*6, "DANH SACH MON HOC");
			ctrl = getch();
			if(ctrl == 13) {
				setbkcolor(15);
				OutputMH(SubMH);
			}
		}
		else if(choice == 6) {
			rectangle(160,270,480,300);
			bar(160,270,480,300);
			setcolor(0);
			outtextxy(180,65 + 30*7, "NHAP SINH VIEN THEO LOP");
			ctrl = getch();
			if (ctrl == 13) {
				setbkcolor(15);
				InputSV(SubL);
			}
		}
		else if(choice == 7) {
			
			rectangle(160,300,480,330);
			bar(160,300,480,330);
			setcolor(0);
			outtextxy(180,65 + 30*8, "NHAP CAU HOI THEO MON HOC");
			ctrl = getch();
			if (ctrl == 13) {
				setbkcolor(15);
				InputCH(p);
				//HS_INPUT();
			}
		}
		if(ctrl == 63) {
			choice = 0;
		}
		if(ctrl == 27) {
			setbkcolor(15);
			cleardevice();
			Login();
		}
		if(ctrl == 80 && choice < 7) {
			choice++;
		}
		else if(ctrl == 72 && choice > 0) {
			choice--;
		}
	} while(1);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//THI
//DONG HO DEM NGUOC --> SU DUNG <time.h>
int Clock(time_t start, int limit) { //time_t tra ve kieu thoi gian voi giay dem tu 00:00 UTC January 1 1970
	time_t now;
	time(&now); // tra ve thoi gian hien tai (time = time(NULL))
	return limit - (int)difftime(now,start); //tgian start va now luon chech nhau theo cap so giay --> limit luon giam --> dem nguoc tgian bang cach hien thi chong len nhau
	//diff(time1,time2) tra ve thoi gian chenh lech giua time1 va time2 (time2 - time1)
	//la thoi gian thi duoc nhap vao (tinh bang giay nhung nhap vao la dinh dang phut)
	//start la tgian tai luc khoi tao nen --> ko doi , now la tgian xet tai thoi diem thuc hien phep tinh --> ltuc thay doi tren 1 giay
}

void CountDown(int n) {
	setbkcolor(11);
	setcolor(0);
	settextjustify(CENTER_TEXT,TOP_TEXT);
	rectangle(270,12,370,45);
	time_t start;
	time(&start);
	do{
		int t = Clock(start,n*60); //(phut*60) --> giay
		if(t <= 0) {
			break;
		}
		char *timetext = new char[100]; //hien thi thoi gian len man hinh
		timetext[0] = '\0';
		char *tg = new char[10]; // bien de tinh toan thoi gian
		if(t >= 60) { //hien thi phan phut neu tgian >= 60s
			itoa(t/60,tg,10);
			strcat(timetext,tg);
			strcat(timetext,":");
		}
		itoa(t%60,tg,10); // lay phan du cua tgian dc nhap, la phan hien thi phia sau " : "
		strcat(timetext,tg);
		if(t<60) {
			settextstyle(8,0,2); //khong bi hien thi tgian trc che lap
			outtextxy(320,20,"       ");
			outtextxy(320,20,timetext);
		}
		else {
			settextstyle(8,0,1);
			outtextxy(320,20,"       ");
			outtextxy(320,20,timetext);
		}
		delay(1000);
	}while(1); // lien tuc tra ve thoi gian hien tai (tgian luon giam dan)

//	delay(100000);
}
void THI_UI() {
	setbkcolor(14);
	setfillstyle(1,14);
	bar(160,90,480,120);
	setfillstyle(1,3); //set the login boord color
	settextstyle(8,0,1);
	setcolor(9);
	rectangle(160,90,480,400);
	bar(160,120,480,400); // the centre of screen with resolution divide by 4
	line(160,120,480,120);
	setcolor(0);//set the title color
	settextjustify(CENTER_TEXT,TOP_TEXT);
	outtextxy(320,95,"THONG TIN THI"); //dis
	setcolor(1);
	setbkcolor(15);
	outtextxy(120,415,"[F5]:lam moi trang");
	setcolor(12);
	outtextxy(80,440,"[ESC]:thoat");
	outtextxy(80 + textwidth("////") + textwidth("[ESC]:thoat"),440,"[TAB]:len dong");
	outtextxy(80 + textwidth("////////") + textwidth("[ESC]:thoat") + textwidth("[TAB]:len dong "),440,"[ENTER]:xac nhan");
	setbkcolor(3);
	setcolor(0);
	settextjustify(LEFT_TEXT,TOP_TEXT);
	outtextxy(190,160,"MA MON HOC");
	outtextxy(190,215,"SO CAU HOI"); //display pass title
	outtextxy(190,270,"THOI GIAN (PHUT)");
	setfillstyle(1,11); //set login space color
	rectangle(190,180,460,210);//LOgin space
	rectangle(190,235,460,265); //PASS Lo/ higher than the text 15
	rectangle(190,290,460,320);
	bar(190,180,460,210); // display text below 5
	bar(190,235,460,265); //ID login space
	bar(190,290,460,320);
	setbkcolor(11);
	setcolor(0); //set text color

}
// kiem tra ma mon va gan ma vao mang chua phu hop
cauhoi* takeMH(PTRCH &root,char *a,int &dem,cauhoi *C){
										// mang chua cau hoi ung voi ma mon hoc	
		int const size=100;
		PTRCH Stack[size];
		int sp = -1;	// hang doi rong
		PTRCH p  = root; // cho p = root de duyet tu dau
		C = new cauhoi;
		
		while(p!=NULL){
			
			if(strcmp(a,p->ch.mamh)==0){
				int x=dem;
				dem++;
				//C = new cauhoi[dem];
				strcpy(C[x].mamh,a);
				strcpy(C[x].info,p->ch.info);
				strcpy(C[x].A,p->ch.A);
				strcpy(C[x].B,p->ch.B);
				strcpy(C[x].C,p->ch.C);
				strcpy(C[x].D,p->ch.D);
				strcpy(C[x].ans,p->ch.ans);
				//cout<<C[x].info<<endl;
				//cout<<x<<endl;
			}
			
			
			if(p->right!=NULL)
				Stack[++sp]=p->right;
			if(p->left!=NULL)
				p=p->left;
			else if(sp==-1)
				break;
			else p=Stack[sp--];
		}
		return C;
	}
void HS_THI(int x,int y,PTRCH p,char *a){			// x:thoi gian thi
	
	cleardevice();
	PTRD diem;
	//DisText inf(16),A(53),B(53),C(53),D(53),dapan(2);
	readCH(p);										// y: so luong cau hoi thi
	//Preorder(p);									// a: ma mon hoc
	int dem=0;
	int chosen;
	cauhoi *CH;
	CH=takeMH(p,a,dem,CH);
	int k=0;// bien chuyen trang
	char move;
	int right=0;
	int arr[dem];
	int ktra[dem];
	for(int i=0;i<dem;i++)
		ktra[i]=0;
	for(int i=0;i<dem;){
		int rnum=randomab(0,dem-1);
		if(ktra[rnum]==0)
		{
			arr[i]=rnum;
			ktra[rnum]=1;
			i++;
		}
	}
	int updown=0;//bien len xuong
	do{
		setfillstyle(1,11);
		setcolor(0);
		bar(65,75,575,125);
		bar(65,155,575,205);
		bar(65,235,575,285);
		bar(65,315,575,365);
		bar(65,395,575,445);
		rectangle(65,75,575,125);
		rectangle(65,155,575,205);
		rectangle(65,235,575,285);
		rectangle(65,315,575,365);
		rectangle(65,395,575,445);
		setbkcolor(15);
		setcolor(12);
		outtextxy(65,20,"<-/->:CHUYEN CAU");
		outtextxy(400,20,"ENTER:CHON");
		setbkcolor(11);
		setcolor(0);
		outtextxy(70,90,CH[arr[k]].info);
		outtextxy(70,170,CH[arr[k]].A);
		outtextxy(70,250,CH[arr[k]].B);
		outtextxy(70,330,CH[arr[k]].C);
		outtextxy(70,410,CH[arr[k]].D);
		if(updown == 0){
			setfillstyle(1,2);
			bar(65,155,575,205);
			setcolor(0);
			setbkcolor(2);
			outtextxy(70,170,CH[arr[k]].A);
		}
		else if(updown == 1){
			setfillstyle(1,2);
			bar(65,235,575,285);
			setcolor(0);
			setbkcolor(2);
			outtextxy(70,250,CH[arr[k]].B);
		}
		else if(updown == 2){
			setfillstyle(1,2);
			bar(65,315,575,365);
			setcolor(0);
			setbkcolor(2);
			outtextxy(70,330,CH[arr[k]].C);
		}
		else if(updown == 3){
			setfillstyle(1,2);
			bar(65,395,575,445);
			setcolor(0);
			setbkcolor(2);
			outtextxy(70,410,CH[arr[k]].D);
		}
		do {
			move = getch();
		}while(!(move == 77 && k < y - 1) && !(move == 75 && k > 0)&&!(move == 80 && updown < 3)&&!(move == 72 && updown > 0)&&!(move==13));
		if(move == 77) k++;
		else if(move == 75) k--;
		else if(move==72) updown--;
		else if(move==80)	updown++;
		else if(move==13){
			chosen++;
			if(chosen<y){
				if(updown == 0){
					if(strcmp("A",CH[arr[k]].ans)==0||strcmp("a",CH[arr[k]].ans)==0)
						right++;
					k++;
					if(k==y){
						break;
					}		
				}
				else if(updown == 1){
					if(strcmp("B",CH[arr[k]].ans)==0||strcmp("b",CH[arr[k]].ans)==0)
						right++;
					k++;
					if(k==y){
						break;
					}		
				}
				else if(updown == 2){
					if(strcmp("C",CH[arr[k]].ans)==0||strcmp("c",CH[arr[k]].ans)==0)
						right++;
					k++;
					if(k==y){
						break;
					}		
				}
				else if(updown == 3){
					if(strcmp("D",CH[arr[k]].ans)==0||strcmp("d",CH[arr[k]].ans)==0)
						right++;
					k++;
					if(k==y){
						break;
					}		
				}
			}
		}
		
	}while(1);
	//cout<<(float)(right*(10/y))<<endl;
	/*char* kqthi;
	char login;
	do{
		itoa((float)(right*(10/y)),kqthi,10);
		cleardevice();
		setfillstyle(1,11);
		settextstyle(8,0,1);
		setbkcolor(11);
		setcolor(10);
		settextjustify(CENTER_TEXT,TOP_TEXT);
		outtextxy(320,240,kqthi);
		if(!kbhit()){
			login=getch();
			if(login==13)
				break;
		}
	}while(1);*/
}
void HS_INPUT() {
	THI_UI();
	nodeMH listHS;// danh sach mon hoc
	ReadMH(listHS);
	//setbkcolor(3);
	PTRCH test;
	test=NULL;
	DisText Ma(16), soCH(4), time(4);
	char ma, CH, tg;
	int x,y;
	char *checkMA;
	checkMA= new char[16];
	int enter = 0;
	do{
		if(enter==0){
			setcolor(12);
			setbkcolor(11);
			rectangle(190,180,460,210);
			ma=getch();
			if(ma==13){
				if(CheckMH_CH(Ma.distext(),listHS)==0){
					setcolor(12);
					setbkcolor(3);
					Ma.emptytext();
					outtextxy(200,340,"MA MON HOC KHONG TON TAI");
					delay(1500);
					outtextxy(200,340,"                        ");
					enter=0;
				}
				else{
					setcolor(0);
					rectangle(190,180,460,210);
					enter++;
				}
			}
			else if(ma==63){
				Ma.emptytext();
				soCH.emptytext();
				time.emptytext();
				THI_UI();
				enter=0;
			}
			else if((ma>=65&&ma<=90)||(ma>=97&&ma<=122)||(CH>=48&&CH<=57)){
				if(!Ma.FullText())
				{
					Ma.addtext(ma);
					setcolor(0);
					outtextxy(195,185,Ma.distext());
				}
				else{
					setcolor(12);
					setbkcolor(3);
					outtextxy(200,340,"NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(200,340,"                        ");
					enter=0;
				}
			}
			else if(ma==127||ma==8){
				Ma.deltext();
				THI_UI();
				setcolor(0);
				outtextxy(195,185,Ma.distext());
				outtextxy(195,240,soCH.distext());
				outtextxy(195,295,time.distext());
			}
			else if(ma==27){
				Ma.emptytext();
				soCH.emptytext();
				time.emptytext();
				enter=4;
			}
		}
		else if(enter==1){
			setcolor(12);
			setbkcolor(11);
			rectangle(190,235,460,265);
			CH=getch();
			if(CH==13){
				setcolor(0);
				rectangle(190,235,460,265);
				enter++;
			}
			else if(CH==0){
				CH=getch();
				if(CH==63){
					Ma.emptytext();
					soCH.emptytext();
					time.emptytext();
					THI_UI();
					enter=0;
				}
			}
			else if(CH>=48&&CH<=57){
				if(!soCH.FullText()){
					soCH.addtext(CH);
					setcolor(0);
					outtextxy(195,240,soCH.distext());
				}else{
					setcolor(12);
					setbkcolor(3);
					outtextxy(200,340,"NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(200,340,"                        ");
					enter=1;
				}
			}
			else if(CH==127||CH==8){
				soCH.deltext();
				THI_UI();
				setcolor(0);
				outtextxy(195,185,Ma.distext());
				outtextxy(195,240,soCH.distext());
				outtextxy(195,295,time.distext());
			}
			else if(CH==9){
				setcolor(0);
				rectangle(190,235,460,265);
				enter--;
			}
			else if(CH==27){
				Ma.emptytext();
				soCH.emptytext();
				time.emptytext();
				enter=4;
			}
		}
		else if(enter==2){
			setcolor(12);
			setbkcolor(11);
			rectangle(190,290,460,320);
			tg=getch();
			if(tg==13){
				if(!Ma.NullText()&&!soCH.NullText()&&!time.NullText()){
						outtextxy(200,340,"THI:Y/N");
						char thi=getch();
						if(thi==13||thi=='Y'||thi=='y'){
							enter++;
						}
						else if(thi=='N'||thi=='n'||thi==27)
						{
							setbkcolor(3);
							setcolor(0);
							rectangle(190,290,460,320);
							outtextxy(200,340,"            ");
							enter = 0;
						}
				}
				else if(Ma.NullText()){
					setcolor(12);
					setbkcolor(3);
					outtextxy(200,340,"MA MON HOC TRONG");
					delay(1000);
					outtextxy(200,340,"                        ");
					setcolor(0);
					setbkcolor(11);
					rectangle(190,290,460,320);
					enter=0;
				}
				else if(soCH.NullText()){
					setcolor(12);
					setbkcolor(3);
					outtextxy(200,340,"CHUA NHAP SO CAU HOI");
					delay(1000);
					outtextxy(200,340,"                        ");
					setcolor(0);
					setbkcolor(11);
					rectangle(190,290,460,320);
					enter=1;
				}
				else if(time.NullText()){
					setcolor(12);
					setbkcolor(3);
					outtextxy(200,340,"CHUA NHAP THOI GIAN THI");
					delay(1000);
					outtextxy(200,340,"                        ");
					setcolor(0);
					setbkcolor(11);
					rectangle(190,290,460,320);
					enter=2;
				}
			}
			else if(tg==9){
				setcolor(0);
				rectangle(190,290,460,320);
				enter--;
			}
			else if(tg==0){
				if(tg==63){
					Ma.emptytext();
					soCH.emptytext();
					time.emptytext();
					THI_UI();
					enter=0;
				}
			}
			else if(tg>=48&&tg<=57){
				if(!time.FullText()){
					time.addtext(tg);
					setcolor(0);
					setbkcolor(11);
					outtextxy(195,295,time.distext());
				}
				else{
					setcolor(12);
					setbkcolor(3);
					outtextxy(200,340,"NHAP QUA DO DAI KI TU");
					delay(1000);
					outtextxy(200,340,"                        ");
					enter=2;
				}
			}
			else if(tg==127||tg==8){
				time.deltext();
				THI_UI();
				setcolor(0);
				outtextxy(195,185,Ma.distext());
				outtextxy(195,240,soCH.distext());
				outtextxy(195,295,time.distext());
			}
			else if(tg==27){
				Ma.emptytext();
				soCH.emptytext();
				time.emptytext();
				enter=4;
			}
		}
		else if(enter==3){
			setbkcolor(15);
			cleardevice();
			x = atoi(time.distext());
			y = atoi(soCH.distext());
			strcpy(checkMA,Ma.distext());
			HS_THI(x,y,test,checkMA);
			delay(3000);
			enter++;			
		}
		else if(enter==4){
			setbkcolor(15);
			cleardevice();
			Login();
		}
	}while(1);
}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//CHAY CHUONG TRINH
int main() {

	srand(time(NULL));
	initwindow(640,480);// init window graphics
	setbkcolor(15);// set background
	cleardevice();
	nodeMH listMH;
	nodeL listL;
	PTRCH p;
	p=NULL;
	//InputMH(listMH);
	//InputL(listL);
	//DeleteMH(listMH);
	//Login();
	//OutputL(listL);
	//GV_CHOICE(0);
//	THI_UI();
	//InputSV(listL);
//	CountDown(5);
	//CH_UI();
	//InputCH(p);
	//readCH(p);
	//Preorder(p);
	HS_INPUT();
	//HS_THI(5);

	return 0;
}
                      
                                       
To share this paste please copy this url and send to your friends
RAW Paste Data
Recent Pastes