#include #include #include using namespace std; const int MAX = 50; struct monhoc { char d_ma[5]; char d_hoten[50]; int d_stc; }; struct dsmonhoc{ int n; monhoc elem[MAX]; }; void khoitao(dsmonhoc &m) { m.n = 0; } int Empty(dsmonhoc m) { return (m.n == 0) ? 1 : 0; } int Full(dsmonhoc m) { return (m.n = MAX) ? 1 : 0; } void nhap(monhoc &m) { cout << " Ma Mon Hoc:\t"; cin >> m.d_ma; cin.ignore(1); cout << " Ten Mon Hoc :\t"; cin.getline(m.d_hoten, 50); cout << " So tin chi :\t"; cin >> m.d_stc; cout << "+-------------------------------------------------------------------+ \n"; } void xuat(monhoc m) { cout << setw(10) << m.d_ma << setw(20) << m.d_hoten << setw(25) << m.d_stc << endl; cout << "+-------------------------------------------------------------------+ \n"; } void nhapds(dsmonhoc&m) { cout << "Nhap So Luong mon hoc: "; cin >> m.n; for (int i = 0; i < m.n; i++) { cout << "+-------------------------------------------------------------------+ \n"; cout << "Nhap Thong Tin Cho MH Thu [" << i + 1 << "]--" << endl; nhap(m.elem[i]); } } void xuatds(dsmonhoc m) { if (Empty(m) == 1) cout << "Danh Sach Rong\n"; else { system("cls"); cout << " Danh Sach Gom " << m.n << " Mon Hoc " << endl; "\n"; cout << "+-------------------------------------------------------------------+ \n"; cout << "+MH Lan Luot Co Thong Tin: Ma,Ho Ten,So tin Chi," << endl; cout << "+-------------------------------------------------------------------+ \n"; cout << setw(10) << "Ma Mon Hoc|" << setw(20) << " Ten Mon Hoc|" << setw(25) << "So tin chi|" << endl; cout << "+-------------------------------------------------------------------+ \n"; for (int i = 0; i < m.n; i++) { xuat(m.elem[i]); } } } void them(dsmonhoc &m) { int pos; monhoc x; if (Empty(m) == 1) cout << "Danh Sach Rong"; else { cout << "Vi tri can them vao mon hoc : "; cin >> pos; pos = pos - 1; if (pos < 0 || pos > m.n - 1) cout << "Sai Vi tri "; else { nhap(x); for (int i = m.n - 1; i >= pos; i--) { m.elem[i + 1] = m.elem[i]; m.elem[pos] = x; m.n++; break; } } } } void xoa(dsmonhoc & m) { int pos; monhoc x; if (Empty(m) == 1) cout << "Danh Sach Rong"; else { cout << "Vi tri can xoa mon hoc : "; cin >> pos; pos = pos + 1; if (pos > 0 || pos > m.n + 1) cout << "Sai Vi tri "; else { nhap(x); for (int i = pos + 1; i <= m.n; i++) { m.elem[i - 1] = m.elem[i]; //m.elem[pos] = x; m.n--; break; } } } } void sua(dsmonhoc &m) { int pos; monhoc x; if (Empty(m) == 1) cout << "Danh Sach Rong"; else { cout << "Vi tri can sua vao mon hoc : "; cin >> pos; pos = pos - 1; if (pos < 0 || pos > m.n - 1) cout << "Sai Vi tri "; else { nhap(x); //for (int i = m.n- 1; i >= pos; i--) //{ //m.elem[i+1] = m.elem[i]; m.elem[pos] = x; //m.n++; //break; } } } void HoanVi(monhoc &a, monhoc&b) { monhoc temp; temp = a; a = b; b = temp; } void SapXep(dsmonhoc &m) { int menu3; cout << "\n1.Sap xep theo ma."; cout << "\n2.Sap xep theo ten."; cout << "\n3.Sap xep theo gia."; cout << "\n4.Tro lai."; cout << "\nChon:"; cin >> menu3; switch (menu3) { case 1: int menu4; cout << "\n1.Selection Sort."; cout << "\n2.Bubble Sort"; cout << "\nChon:"; cin >> menu4; switch (menu4) { case 1: for (int i = 0; i < m.n - 1; i++) for (int j = i + 1; j < m.n; j++) if (strcmp(m.elem[i].d_ma, m.elem[j].d_ma)>0) { HoanVi(m.elem[i], m.elem[j]); } break; case 2: for (int i = 0; i < m.n - 1; i++) for (int j = m.n - 1; j > i; j--) if (strcmp(m.elem[j].d_ma, m.elem[j - 1].d_ma) > 0) { HoanVi(m.elem[j], m.elem[j - 1]); } break; } break; case 2: int menu5; cout << "\n1.Selection Sort."; cout << "\n2.Bubble Sort"; cout << "\nChon:"; cin >> menu5; switch (menu5) { case 1: for (int i = 0; i < m.n - 1; i++) for (int j = i + 1; j < m.n; j++) if (strcmp(m.elem[i].d_hoten, m.elem[j].d_hoten) > 0) { HoanVi(m.elem[i], m.elem[j]); } break; case 2: for (int i = 0; i < m.n - 1; i++) for (int j = m.n - 1; j > i; j--) if (strcmp(m.elem[j].d_hoten, m.elem[j - 1].d_hoten) > 0) { HoanVi(m.elem[j], m.elem[j - 1]); } break; } break; /*case 3: int menu6; cout << "\n1.Selection Sort."; cout << "\n2.Bubble Sort"; cout << "\nChon:"; cin >> menu6; switch (menu6) { case 1: for (int i = 0; i < hh.n - 1; i++) for (int j = i + 1; j < hh.n; j++) if (hh.dshh[i].gia > hh.dshh[j].gia) { HoanVi(hh.dshh[i], hh.dshh[j]); } break; case 2: for (int i = 0; i < hh.n - 1; i++) for (int j = hh.n- 1; j >i; j--) if (hh.dshh[j].gia > hh.dshh[j - 1].gia) { HoanVi(hh.dshh[j], hh.dshh[j-1]); } break; } break; case 4: break; } }*/ } } int nhaplai() { int chon; system("cls"); cout << endl << endl; //system("color b"); cout << " | Nhom 2: Vo Tan Nam____Bui Binh Minh_____ LOP: C13-TH01 |\n"; cout << " +=================================================+ \n"; cout << " | CHUONG TRINH QUAN LY MON HOC | \n"; cout << " |-------------------------------------------------| \n"; cout << " 1. Them Danh Sach Mon Hoc \n"; cout << " 2. Xuat Danh Sach Mon hoc. \n"; cout << " 3. Them 1 Mon hoc. \n"; cout << " 4. Xoa 1 Mon Hoc \n"; cout << " 5. Sua mon hoc \n"; cout << " 6. sap xep mon hoc \n"; cout << " +-------------------------------------------------+ \n"; cout << endl; cout << "Nhap So De Chon Menu: "; cin >> chon; return chon; } void main() { dsmonhoc m; khoitao(m); int chon; chon = nhaplai(); switch (chon) { case 1: nhapds(m); cout << "Nhap Phim Bat Ky De Quay Ve"; _getch(); nhaplai(); break; case 2: xuatds(m); cout << "Nhap Phim Bat Ky De Quay Ve"; _getch(); nhaplai(); break; case 3: them(m); cout << "Nhap Phim Bat Ky De Quay Ve"; _getch(); nhaplai(); break; //} //} //if(chon < 0) //{ //cout << "Nhap Sai Vui Long Nhap Lai !!"; //goto nhaplai; //} case 4: xoa(m); cout << "Nhap Phim Bat Ky De Quay Ve"; _getch(); nhaplai(); //break; //if(chon< 0) //{ //cout << "Nhap Sai Vui Long Nhap Lai !!"; //goto nhaplai; //} case 5: sua(m); cout << "Nhap Phim Bat Ky De Quay Ve"; _getch(); nhaplai(); //break; //} //if(chon< 0) //{ //cout << "Nhap Sai Vui Long Nhap Lai !!"; //goto nhaplai; //} case 6: cout << "\n5.Sap xep thong tin hang hoa theo 1 tieu chi nao do:" << endl; SapXep(m); /*XuatDS(m)*/; /*break;*/ _getch(); nhaplai(); } }