#include"console.h" #include #include #include using namespace std; /* TÀI KHOẢNG CỦA GIÁO VIÊN / HỌC SINH */ #define TEACHER_USERNAME "trucvy" #define TEACHER_PASSWORD "abc123!" #define STUDENT_USERNAME "dinhhuukien" #define STUDENT_PASSWORD "abc123!" typedef struct Student { string MSSV; string Ho; string Lot; string Ten; string hoTen = Ho + Lot + Ten; float ANHVAN, GDTC, NMLT, PLDC, TCC, TH_NMLT, TH_PCMT, THUD, VLDC; }; typedef struct StudentNode { Student student; StudentNode *next; }; typedef struct StudentList{ StudentNode *head; StudentNode *tail; }; void modifyStudent(Student &sd1, Student &sd2) { sd1.hoTen = sd2.hoTen; } void printStudentList(StudentList &l) { StudentNode *p = l.head; cout << "Ma so sinh vien: Ten Sinh vien:"<student.MSSV << " " << p->student.hoTen << endl; p = p->next; } } StudentNode *getStudentNode(Student sd) { StudentNode *p = new StudentNode; if (p == NULL) { cout << "Khong du bo nho"; exit(NULL); } p->student.MSSV = sd.MSSV; p->student.Ho = sd.Ho; p->student.Lot = sd.Lot; p->student.Ten = sd.Ten; p->student.hoTen = sd.Ho +" "+ sd.Lot +" "+ sd.Ten; p->next = NULL; return p; } void insertHead(StudentList &l, Student sd) { StudentNode *p = getStudentNode(sd); if (p == NULL){ cout << "Sai du lieu"; exit(NULL); } if (l.head == NULL) l.head = l.tail = p; else { p->next = l.head; l.head = p; } } string getClientPerm() { appMenu(); int clientAnswer; cout << " DANG NHAP VOI QUYEN HAN LA \n" << endl; cout << " 1. Giao vien (Teacher)\n 2. Sinh vien (Student)\n 3. Thoat chuong trinh\n -> ";; cin >> clientAnswer; switch (clientAnswer) { case 1: return "teacher"; break; case 2: return "student"; break; default: exit(NULL); break; } } void loadStudentToList(StudentList &l, char *fileName) { Student sd; StudentNode *p = l.head; char MSSV[50]; char Ho[50]; char Lot[50]; char Ten[50]; FILE *f; f = fopen(fileName, "r"); if (f == NULL) { cout << "Khong tim thay du lieu"; exit(NULL); } for (int i = 0; i < 275; i++) { fscanf(f, "%s", &MSSV); fseek(f, 10, SEEK_SET); fscanf(f, "%s %s %s", &Ho, &Lot, &Ten); sd.MSSV = string(MSSV); sd.Ho = string(Ho); sd.Lot = string(Lot); sd.Ten = string(Ten); insertHead(l, sd); } fclose(f); } void appMenu(){ cout << "= = = = = = = = = = = = = = = = = = = = = = = = " << endl; cout << "= = " << endl; cout << "= CHUONG TRINH QUAN LY HOC SINH/SINH VIEN = " << endl; cout << "= ( STUDENTS MANAGEMENT SYSTEM ) = " << endl; cout << "= = " << endl; cout << "= = = = = = = = = = = = = = = = = = = = = = = = " << endl; cout << endl << endl; } bool isTeacherAccount() { string password; string username; clrscr(); appMenu(); cout << " DANG NHAP TAI KHOANG \n" << endl; do { fflush(stdin); cout << "\n [*] Nhap tai khoang Giao Vien:\n ->"; getline(cin, username); cout << "\n [*] Nhap mat khau Giao Vien:\n ->"; getline(cin, password); if (password != TEACHER_PASSWORD || username != TEACHER_USERNAME) { cout << "\nTai khoang hoac Mat Khau da nhap khong chinh xac" << endl; cout << "An ESC de tro lai. An bat ky de Dang Nhap lai"; } else return true; } while (_getch() != 27); return false; } void main() { //int clientAnswer; //appMenu(); //cout << " NHAP SO DE CHON TINH NANG TUONG UNG\n" << endl; //cout << " 1. Dang nhap\n 2. Thoat chuong trinh\n -> "; //cin >> clientAnswer; // //switch (clientAnswer) { // case 1: // clrscr(); // break; // case 2: // exit(NULL); // break; // default: // clrscr(); // main(); // break; //} //if ("teacher" == getClientPerm()) // if (isTeacherAccount()) { // cout << "Dang nhap Thanh Cong, chuyen den giao dien Quan Ly"; // Sleep(1000); // clrscr(); // } //else // clrscr(); StudentList l; l.head = l.tail = NULL; char *fileName = "mssv_hoten.txt"; loadStudentToList(l, fileName); printStudentList(l); _getch(); }