Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace std;
- struct NgaySinh
- {
- int d, m, y;
- };
- struct HocSinh
- {
- char Ten[25];
- float DTB;
- float Toan, Ly, Hoa;
- NgaySinh NS;
- };
- void NhapNgaySinh(NgaySinh &NS)
- {
- cout << "Ngay : ";
- cin >> NS.d;
- cout << "Thang: ";
- cin >> NS.m;
- cout << "Nam : ";
- cin >> NS.y;
- fflush(stdin);
- if (NS.d < 0 || NS.d > 31)
- {
- cout << "ERROR";
- NhapNgaySinh(NS);
- }
- else
- {
- if (NS.m == 4 || NS.m == 6 || NS.m == 9 || NS.m == 11)
- {
- if (NS.d == 31)
- {
- cout << "ERROR";
- NhapNgaySinh(NS);
- }
- }
- if (NS.m == 2)
- {
- if (NS.y % 4 == 0 && NS.y % 100 != 0)
- {
- if (NS.d > 29)
- {
- cout << "ERROR";
- NhapNgaySinh(NS);
- }
- }
- else
- {
- if (NS.y % 400 == 0)
- {
- if (NS.d > 29)
- {
- cout << "ERROR";
- NhapNgaySinh(NS);
- }
- }
- }
- }
- }
- }
- void XuatNgaySinh(NgaySinh NS)
- {
- cout << "Ngay : " << NS.d << endl;
- cout << "Thang: " << NS.m << endl;
- cout << "Nam : " << NS.y << endl;
- }
- void NhapThongTin(HocSinh &Hs)
- {
- fflush(stdin);
- cout << "Nhap Ten: ";
- cin.getline(Hs.Ten, 25);
- do
- {
- cout << "Toan: ";
- cin >> Hs.Toan;
- } while (Hs.Toan < 0.0 || Hs.Toan > 10.0);
- do
- {
- cout << "Ly : ";
- cin >> Hs.Ly;
- } while (Hs.Ly < 0.0 || Hs.Ly > 10.0);
- do
- {
- cout << "Hoa : ";
- cin >> Hs.Hoa;
- } while (Hs.Hoa < 0.0 || Hs.Hoa > 10.0);
- Hs.DTB = (Hs.Toan * 2 + Hs.Ly + Hs.Hoa) / 4;
- fflush(stdin);
- NhapNgaySinh(Hs.NS);
- }
- void XuatThongTin(HocSinh &Hs)
- {
- cout << "Ten : " << Hs.Ten << endl;
- cout << "Toan: " << Hs.Toan << endl;
- cout << "Ly : " << Hs.Ly << endl;
- cout << "Hoa : " << Hs.Hoa << endl;
- cout << "DTB : " << Hs.DTB << endl;
- XuatNgaySinh(Hs.NS);
- }
- void NhapDanhSach(HocSinh *Hs, int n)
- {
- for (int i = 0; i < n; i++)
- NhapThongTin(Hs[i]);
- }
- void XuatDanhSach(HocSinh *Hs, int n)
- {
- for (int i = 0; i < n; i++)
- XuatThongTin(Hs[i]);
- }
- void Swap(HocSinh &a, HocSinh &b)
- {
- HocSinh t;
- t = a;
- a = b;
- b = t;
- }
- void QuickSort(HocSinh Hs[], int l, int r)
- {
- int i = l, j = r;
- float x = Hs[(i + j) / 2].DTB;
- do
- {
- while (Hs[i].DTB > x) i++;
- while (Hs[j].DTB < x) j--;
- if (i <= j)
- {
- Swap(Hs[i], Hs[j]);
- i++;
- j--;
- }
- } while (i <= j);
- if (i < r) QuickSort(Hs, i, r);
- if (j > l) QuickSort(Hs, l, j);
- }
- void main()
- {
- int n;
- HocSinh *Hs = NULL;
- cout << "So sinh vien can nhap: ";
- cin >> n;
- Hs = new HocSinh[n];
- NhapDanhSach(Hs, n);
- QuickSort(Hs, 0, n - 1);
- int luachon;
- do
- {
- system("cls");
- cout << "1. Sap xep theo diem trung binh\n2. Danh sach nguoi co DTB < 5.0";
- luachon = getch();
- luachon -= 48;
- switch (luachon)
- {
- case 1:
- XuatDanhSach(Hs, n);
- break;
- case 2:
- for (int i = n - 1; i >= 0; i--)
- {
- if (Hs[i].DTB < 5.0) XuatThongTin(Hs[i]);
- else break;
- }
- break;
- default:
- break;
- }
- } while (luachon != 1 || luachon != 2);
- delete[] Hs;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement