Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <Windows.h>
- #include <conio.h>
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- using namespace std;
- struct diem{
- float gk1, ck1, tb1, gk2, ck2, tb2;
- float hk1, hk2, cn;
- };
- struct ketqua{
- diem mon[10];
- float tbm;
- int xeploai;
- };
- struct sinhvien{
- char ten[31];
- char namsinh[5];
- char cmnd[15];
- char sdt[15];
- char diachi[31];
- char lop[15];
- char mssv[9];
- int gioi, kha, tb, yeu;
- ketqua ketquasv;
- };
- void xeploai1(sinhvien sv[], int n, int somon, int &gioi, int &kha, int &tb, int &yeu);
- void nhapdiem(sinhvien &sv, int n)
- {
- int i;
- for (i = 1; i <= n; i++)
- {
- printf("\tMon %d: \n", i);
- printf("\t\tHoc ki 1:\n");
- printf("\t\t\tDiem thi giua ki: "); scanf_s("%f.\n", &sv.ketquasv.mon[i].gk1);
- printf("\t\t\tDiem thi cuoi ki: "); scanf_s("%f.\n", &sv.ketquasv.mon[i].ck1);
- sv.ketquasv.mon[i].hk1 = sv.ketquasv.mon[i].gk1 * 0.3 + sv.ketquasv.mon[i].ck1 * 0.7;
- printf("\n\t\tHoc ki 2:\n");
- printf("\t\t\tDiem thi giua ki: "); scanf_s("%f.\n", &sv.ketquasv.mon[i].gk2);
- printf("\t\t\tDiem thi cuoi ki: "); scanf_s("%f.\n", &sv.ketquasv.mon[i].ck2);
- sv.ketquasv.mon[i].hk2 = sv.ketquasv.mon[i].gk2 * 0.3 + sv.ketquasv.mon[i].ck2 * 0.7;
- sv.ketquasv.mon[i].cn = (sv.ketquasv.mon[i].hk1 + sv.ketquasv.mon[i].hk2) / 2;
- }
- sv.ketquasv.tbm = 0;
- for (i = 1; i <= n; i++)
- sv.ketquasv.tbm += sv.ketquasv.mon[i].cn;
- sv.ketquasv.tbm = sv.ketquasv.tbm / n;
- }
- void nhapthongtin(sinhvien &sv, int i, fstream &tt, int &n)
- {
- system("cls");
- scanf_s("%*c");
- printf("*********** Phan thong tin sinh vien ***********\n");
- printf("Sinh vien thu %d:\n", i);
- printf("Ho va ten : "); gets_s(sv.ten);
- printf("MSSV : "); gets_s(sv.mssv);
- printf("Dia chi : "); gets_s(sv.diachi);
- printf("So dien thoai : "); gets_s(sv.sdt);
- printf("Lop hoc : "); gets_s(sv.lop);
- printf("Nam sinh : "); gets_s(sv.namsinh);
- printf("So cmnd : "); gets_s(sv.cmnd);
- printf("\n************ Phan diem thi sinh vien ***********\n");
- nhapdiem(sv, n);
- }
- void loadtt(sinhvien sv[], int &n, int m)
- {
- fstream tt;
- tt.open("d:/thongtin.dat", ios::in | ios::binary);
- tt.read((char *)&n, sizeof(n));
- for (int i = 1; i <= n; i++) tt.read((char *)&sv[i], sizeof(sv[i]));
- tt.close();
- }
- void xuatdiem(sinhvien &sv, int n)
- {
- printf("\t gk1\t ck1\t hk1\t gk2\t ck2\t hk2\t tbm\n");
- for (int i = 1; i <= n; i++)
- printf("mon %d\t %.1f\t %.1f\t %.1f\t %.1f\t %.1f\t %.1f\t %.1f\t\n", i, sv.ketquasv.mon[i].gk1, sv.ketquasv.mon[i].ck1, sv.ketquasv.mon[i].hk1, sv.ketquasv.mon[i].gk2, sv.ketquasv.mon[i].ck2, sv.ketquasv.mon[i].hk2, sv.ketquasv.mon[i].cn);
- printf("\n\n\t\tTrung binh mon ca nam: %.2f", sv.ketquasv.tbm);
- }
- void xuatthongtin(sinhvien &sv, int i, int n)
- {
- system("cls");
- printf("\n****************** Phan thong tin sinh vien *****************\n");
- printf("Sinh vien thu %d:\n", i);
- printf("Ho va ten : %s\n", sv.ten);
- printf("MSSV : %s\n", sv.mssv);
- printf("So CMND : %s\n", sv.cmnd);
- printf("Dia chi : %s\n", sv.diachi);
- printf("So dien thoai : %s\n", sv.sdt);
- printf("Lop hoc : %s\n", sv.lop);
- printf("Nam sinh : %s\n", sv.namsinh);
- printf("\n******************* Phan diem thi sinh vien *****************\n");
- xuatdiem(sv, n);
- printf("\n\t\t\tXep Loai: ");
- if (sv.ketquasv.xeploai == 4) printf("Gioi");
- else if (sv.ketquasv.xeploai == 3) printf("Kha");
- else if (sv.ketquasv.xeploai == 2) printf("Trung Binh");
- else printf("Yeu");
- _getch();
- }
- void indiem(sinhvien &sv, int n, fstream &in)
- {
- in << "\n\t\tGK 1\tCK 1\tHK 1\tGK 2\tCK 2\tHK 2\tTBM\n";
- for (int i = 1; i <= n; i++)
- in << "\tMon " << i << "\t\t" << sv.ketquasv.mon[i].gk1 << "\t" << sv.ketquasv.mon[i].ck1 << "\t" << sv.ketquasv.mon[i].hk1 << "\t" << sv.ketquasv.mon[i].gk2 << "\t" << sv.ketquasv.mon[i].ck2 << "\t" << sv.ketquasv.mon[i].hk2 << "\t" << sv.ketquasv.mon[i].cn << "\t\n";
- in << "\n\t\tTrung binh mon ca nam: " << sv.ketquasv.tbm;
- }
- void inthongtin(sinhvien &sv, int n)
- {
- fstream in;
- in.open("d:/infile.doc", ios::out | ios::app);
- in << "\n\n************************ Phan Thong Tin Sinh Vien ***********************\n";
- in << "\n\t\tHo va ten\t\t\t: " << sv.ten;
- in << "\n\t\tSo CMND\t\t\t: " << sv.cmnd;
- in << "\n\t\tNam sinh\t\t\t: " << sv.namsinh;
- in << "\n\t\tDia chi\t\t\t: " << sv.diachi;
- in << "\n\t\tLop hoc\t\t\t: " << sv.lop;
- in << "\n\t\tMSSV\t\t\t\t: " << sv.mssv;
- in << "\n\t\tSo dien thoai\t\t: " << sv.sdt;
- in << "\n\n\n************************ Phan Diem Thi Sinh Vien ************************\n";
- indiem(sv, n, in);
- in << "\n\t\t\tXep Loai: ";
- if (sv.ketquasv.xeploai == 4) in << "Gioi";
- else if (sv.ketquasv.xeploai == 3) in << "Kha";
- else if (sv.ketquasv.xeploai == 2) in << "Trung Binh";
- else in << "Yeu";
- in << "\n\n=========================================================================\n";
- in << "=========================================================================\n";
- in.close();
- }
- void gotoxy(int x, int y)
- {
- HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
- COORD position = { x, y };
- SetConsoleCursorPosition(hStdout, position);
- }
- void inbaocao(sinhvien sv[], int n, int somon, int &g, int &k, int &tb, int &y)
- {
- loadtt(sv, n, somon);
- xeploai1(sv, n, somon, g, k, tb, y);
- fstream bc;
- bc.open("D:/BaoCao.doc", ios::out);
- bc << "\t\t\t Cong Hoa Xa Hoi Chu Nghia Viet Nam\n\t\t\t\tDoc Lap - Tu Do - Hanh Phuc\n\t\t\t\t\t\t ***\n \t\t\t\tBAN BAO CAO KET QUA HOC TAP";
- bc << "\n\nTen\t\t\t\tLop\t\t\tMSSV\t\t\tTBCN\tXL\n";
- for (int i = 1; i <= n; i++)
- {
- bc << sv[i].ten;
- for (int x = 3; x > strlen(sv[i].ten) / 10; x--) bc << "\t";
- bc << sv[i].lop << "\t\t" << sv[i].mssv << "\t\t" << sv[i].ketquasv.tbm << "\t";
- if (sv[i].ketquasv.xeploai == 4) bc << "Gioi\n";
- else if (sv[i].ketquasv.xeploai == 3) bc << "Kha\n";
- else if (sv[i].ketquasv.xeploai == 2) bc << "TB\n";
- else bc << "Yeu\n";
- }
- bc << "\n\tTong ket: \n\t+Gioi: " << g << "\tChiem: " << g * 100 / n << "%\n\t+Kha : " << k << "\tChiem: " << k * 100 / n << "%\n\t+TB : " << tb << "\tChiem: " << tb * 100 / n << "%\n\t+Yeu : " << y << "\tChiem: " << y * 100 / n << "%\n";
- bc.close();
- }
- int timsv(sinhvien &sv, char tukhoa[])
- {
- char s1[31];
- char s2[15];
- strcpy_s(s2, tukhoa);
- _strlwr_s(s2);
- int i = 0;
- while (i <= (strlen(sv.ten) - strlen(s2)))
- {
- strncpy_s(s1, sv.ten + i, strlen(s2));
- s1[strlen(s2) + 1] = '\0';
- _strlwr_s(s1);
- if (strcmp(s2, s1) == 0) break;
- i++;
- }
- if (i <= (strlen(sv.ten) - strlen(s2))) return 1;
- i = 0;
- if (strlen(s2) <= strlen(sv.mssv))
- {
- while (i <= (strlen(sv.mssv) - strlen(s2)))
- {
- strncpy_s(s1, sv.mssv + i, strlen(s2));
- s1[strlen(s2) + 1] = '\0';
- _strlwr_s(s1);
- if (strcmp(s2, s1) == 0) break;
- i++;
- }
- if (i <= (strlen(sv.mssv) - strlen(s2))) return 1;
- }
- return 0;
- }
- void xephang(sinhvien sv[], int &n, int somon, int stt[])
- {
- int t, a=0;
- loadtt(sv, n, somon);
- for (int i = 1; i <= n; i++) stt[i] = i;
- for (int i = 1; i <= n; i++)
- {
- for (int j = 1; j <= n; j++)
- {
- if (sv[stt[i]].ketquasv.tbm > sv[stt[j]].ketquasv.tbm)
- {
- t = stt[i];
- stt[i] = stt[j];
- stt[j] = t;
- }
- }
- }
- }
- void suathongtin(int n, int somon, int i)
- {
- fstream tt;
- sinhvien sv[11];
- loadtt(sv, n, somon);
- nhapthongtin(sv[i], i, tt, somon);
- cout << "\nSave (s/n)";
- int luachon;
- luachon = _getch();
- if (luachon == 83 || luachon == 115)
- {
- tt.open("d:/thongtin.dat", ios::out | ios::binary);
- tt.write((char *)&n, sizeof(n));
- for (i = 1; i <= n; i++) tt.write((char *)&sv[i], sizeof(sv[i]));
- tt.flush();
- tt.close();
- }
- else loadtt(sv, n, somon);
- }
- int admin()
- {
- char pass[15];
- int i = 0, dem = 0;
- do
- {
- i = 0;
- system("cls");
- cout << " ******** NHAP PASS ********\n" << " ";
- while ((pass[i] = _getch()) != 13 && i++ < 13) cout << "*";
- pass[i] = '\0';
- if (strcmp(pass, "HuuTho") == 0) return 1;
- else dem++;
- } while (dem < 3);
- if (dem == 3) return 0;
- }
- void danhsachsv(sinhvien sv[], int somon)
- {
- int n, t, a =0;
- int stt[11];
- fstream tt;
- loadtt(sv, n, somon);
- tt.open("d:/thongtin.dat", ios::in | ios::binary);
- for (int x = 1; x <= n; x++) stt[x] = x;
- for (int i = 1; i <= n; i++)
- {
- for (int j = 1; j <= n; j++)
- {
- if (i == j) continue;
- if (strcmp(sv[stt[i]].ten, sv[stt[j]].ten) > 1)
- {
- t = stt[i];
- stt[i] = stt[j];
- stt[j] = t;
- }
- }
- }
- do
- {
- system("cls");
- for (int i = 1; i <= n; i++) cout << "\n" << i << ". " << sv[stt[i]].ten;
- int i;
- i = _getch();
- i = i - 48;
- if (i <= n && i > 0)
- {
- xeploai1(sv, n, somon, a, a, a, a);
- xuatthongtin(sv[stt[i]], stt[i], somon);
- cout << "\n\n\t\tEDIT (y/n) ?";
- if (_getch() == 121 && n != 0) if (admin() == 1)
- {
- tt.close();
- suathongtin(n, somon, i);
- }
- else tt.close();
- }
- } while (_getch() != 27);
- }
- void xoatt(sinhvien sv[], int &n, int j, int somon)
- {
- fstream tt;
- int i;
- loadtt(sv, n, somon);
- tt.open("d:/thongtin.dat", ios::out | ios::binary);
- n = n - 1;
- tt.write((char *)&n, sizeof(n));
- for (i = 1; i <= n + 1; i++)
- {
- if (i != j) tt.write((char *)&sv[i], sizeof(sv[i]));
- }
- tt.flush();
- tt.close();
- }
- int xeploai(sinhvien &sv, int n, int somon, int &gioi, int &kha, int &tb, int &yeu)
- {
- int min = 10;
- for (int i = 1; i <= somon; i++)
- {
- if (min > sv.ketquasv.mon[i].hk1) min = sv.ketquasv.mon[i].hk1;
- if (min > sv.ketquasv.mon[i].hk2) min = sv.ketquasv.mon[i].hk2;
- }
- if (sv.ketquasv.tbm < 5) sv.ketquasv.xeploai = 1;
- if (sv.ketquasv.tbm >= 5) sv.ketquasv.xeploai = 2;
- if (sv.ketquasv.tbm >= 6.5 && min < 5) sv.ketquasv.xeploai = 2;
- if (sv.ketquasv.tbm >= 6.5 && min >= 5) sv.ketquasv.xeploai = 3;
- if (sv.ketquasv.tbm >= 8 && min >= 5) sv.ketquasv.xeploai = 3;
- if (sv.ketquasv.tbm >= 8 && min >= 6.5) sv.ketquasv.xeploai = 4;
- if (sv.ketquasv.xeploai == 1) yeu++; else if (sv.ketquasv.xeploai == 2) tb++; else if (sv.ketquasv.xeploai == 3) kha++; else if (sv.ketquasv.xeploai == 4) gioi++;
- return 1;
- }
- void xeploai1(sinhvien sv[], int n, int somon, int &gioi, int &kha, int &tb, int &yeu)
- {
- gioi = 0; kha = 0; tb = 0; yeu = 0;
- for (int x = 1; x <= n; x++)
- xeploai(sv[x], n, somon, gioi, kha, tb, yeu);
- }
- void menu1()
- {
- printf("\n+***************************** Ghi Thong Tin ****************************+");
- printf("\n+------------------------------------------------------------------------+");
- printf("\n+ 1. Ghi thong tin chi tiet +");
- printf("\n+ 2. Ghi bao cao hoc tap lop +");
- printf("\n+------------------------------------------------------------------------+");
- printf("\n+ ESC. Thoat +");
- printf("\n+------------------------------------------------------------------------+\n");
- }
- void menu()
- {
- printf("\n+*************************** Quan Ly Sinh Vien **************************+");
- printf("\n+------------------------------------------------------------------------+");
- printf("\n+ 1. Bo sung du lieu ve sinh vien +");
- printf("\n+ 2. Ghi thong tin ra file +");
- printf("\n+ 3. Load thong tin tren bo nho +");
- printf("\n+ 4. Tim sv bang tu khoa +");
- printf("\n+ 5. Danh sach Sv +");
- printf("\n+ 6. Xep hang sinh vien +");
- printf("\n+ 7. De suat hoc bong +");
- printf("\n+ 8. Sua thong tin sinh vien +");
- printf("\n+ 9. Xoa thong tin sinh vien +");
- printf("\n+------------------------------------------------------------------------+");
- printf("\n+ ESC. Thoat +");
- printf("\n+------------------------------------------------------------------------+\n");
- }
- void main()
- {
- int g = 0, k = 0, tb = 0, y = 0;
- sinhvien sv[11];
- int sokt = 0, sodong = 1;
- int i, n = 0, somon = 6, stt[10];
- int c, luachon; int *mang;
- fstream tt, d, hb;
- int dem = 0, dem1;
- do
- {
- loadtt(sv, n, somon);
- int dem = 0, sothongtin;
- system("cls");
- menu();
- switch (_getch())
- {
- case 49:
- tt.open("D:/thongtin.dat", ios::out | ios::binary);
- system("cls");
- printf("So sinh vien can nhap thong tin: ");
- scanf_s("%d.\n", &c);
- n = n + c;
- tt.write((char *)&n, sizeof(n));
- for (i = n - c + 1; i <= n; i++)
- nhapthongtin(sv[i], i, tt, somon);
- for (i = 1; i <= n; i++) tt.write((char *)&sv[i], sizeof(sv[i]));
- tt.flush();
- tt.close();
- xeploai1(sv, n, somon, g, k, tb, y);
- for (i = 1; i <= n; i++)
- xuatthongtin(sv[i], i, somon);
- break;
- case 50:
- xeploai1(sv, n, somon, g, k, tb, y);
- do
- {
- system("cls");
- menu1();
- do
- {
- luachon = _getch();
- } while (luachon != 49 && luachon != 50 && luachon != 27);
- switch (luachon)
- {
- case 49:
- for (i = 1; i <= n; i++) inthongtin(sv[i], somon);
- cout << "successful " << "\nOpen file...";
- system("d:/infile.doc");
- break;
- case 50:
- inbaocao(sv, n, somon, g, k, tb, y);
- cout << "successful " << "\nOpen file...";
- system("d:/BaoCao.doc");
- break;
- default:
- break;
- }
- break;
- } while (_getch() != 27);
- break;
- case 51:
- xeploai1(sv, n, somon, g, k, tb, y);
- for (i = 1; i <= n; i++)
- xuatthongtin(sv[i], i, somon);
- break;
- case 52:
- char tukhoa[15];
- c = 0;
- system("cls");
- cout << "******** Nhap tu khoa tim kiem ********\n";
- gets_s(tukhoa);
- cout << "\n***** Ket qua tim kiem cho: '" << tukhoa << "' *****\n";
- for (i = 1; i <= n; i++) if (timsv(sv[i], tukhoa) == 1) cout << "\n" << i << ". " << sv[i].ten << "\tMSSV: " << sv[i].mssv;
- break;
- case 53:
- system("cls");
- xeploai1(sv, n, somon, g, k, tb, y);
- cout << "******** Danh sach: ********\n";
- danhsachsv(sv, somon);
- break;
- case 54:
- system("cls");
- cout << "******** Xep Hang: ********\n";
- xephang(sv, n, somon, stt);
- do
- {
- system("cls");
- for (int i = 1; i <= n; i++) cout << i << "." << sv[stt[i]].ten << "\t\tDat: " << sv[stt[i]].ketquasv.tbm << "\n";
- int i;
- cout << "\nNhap vi thu tren bang xep hang ";
- i = _getch();
- i = i - 48;
- xeploai1(sv, n, somon, g, k, tb, y);
- if (i > 0 && i <= n) xuatthongtin(sv[stt[i]], stt[i], somon);
- } while (_getch() != 27);
- break;
- case 55:
- dem1 = 1;
- xeploai1(sv, n, somon, g, k, tb, y);
- xephang(sv, n, somon, stt);
- hb.open("D:/Hocbong.doc", ios::out);
- hb << "\t\t\t Cong Hoa Xa Hoi Chu Nghia Viet Nam\n\t\t\t\tDoc Lap - Tu Do - Hanh Phuc\n\t\t\t\t\t\t ***\n \t\t\t\t DANH SACH DE SUAT HOC BONG\n\n";
- hb << "\n\nTen\t\t\t\tLop\t\t\tMSSV\t\t\tTBCN\n";
- while (10 * dem1 < n || dem1 == 1) //rang buoc dieu kien in it nhat 1 nguoi trong truong hop so sv < 10
- {
- if (sv[stt[dem1]].ketquasv.tbm >= 7)
- {
- hb << sv[stt[dem1]].ten << "\t\t" << sv[stt[dem1]].lop << "\t\t" << sv[stt[dem1]].mssv << "\t\t" << sv[stt[dem1]].ketquasv.tbm << "\n";
- dem1++;
- }
- else break;
- }
- hb << "\n\n\t\tCo " << dem1 - 1 << " tren tong so " << n << " sinh vien\n";
- hb.close();
- system("D:/Hocbong.doc");
- cout << "Opening...";
- break;
- case 56:
- int a;
- do
- {
- system("cls");
- cout << "Co " << n << "thong tin duoc luu tru" << "\nBan muon chinh sua thong tin bao nhieu nguoi: ";
- scanf_s("%d.\n", &a);
- } while (a > n);
- cout << "Nhap stt nhung nguoi ban muon sua tt (stt trong muc load thong tin)\n";
- mang = new int[a];
- for (int x = 1; x <= a; x++)
- {
- cout << "\nstt nguoi thu " << x << " ";
- cin >> mang[x];
- if (mang[x] > n) x--;
- cout << "\n";
- }
- if (admin() == 1) for (int x = 1; x <= a; x++) suathongtin(n, somon, mang[x]);
- xeploai1(sv, n, somon, g, k, tb, y);
- break;
- case 57:
- do
- {
- system("cls");
- cout << "Co " << n << "thong tin duoc luu tru" << "\nBan muon xoa thong tin bao nhieu nguoi: ";
- scanf_s("%d.\n", &a);
- } while (a > n);
- cout << "Nhap stt nhung nguoi ban muon xoa (stt trong muc load thong tin)\n";
- mang = new int[a];
- for (int x = 1; x <= a; x++)
- {
- cout << "\nstt nguoi thu " << x << " ";
- cin >> mang[x];
- if (mang[x] > n) x--;
- cout << "\n";
- }
- if (admin() == 1) for (int x = 1; x <= a; x++) xoatt(sv, n, mang[x], somon);
- loadtt(sv, n, somon);
- xeploai1(sv, n, somon, g, k, tb, y);
- break;
- default:
- break;
- }
- } while (_getch() != 27);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement