#include "stdafx.h" #include #include #include using namespace std; class thisinh { private: char sbd[25]; float toan, ly, hoa; public: void nhap() { fflush(stdin); cout << "\n------------------------------------------------------------\n"; cout << "Nhap so bao danh : "; cin >> sbd; do{ cout << "Nhap diem toan : "; cin >> toan; if (toan<0 || toan>10){ cout << "\nNhap lai 0 < diem toan <10" << endl; system("cls"); } } while (toan<0 || toan>10); do{ cout << "Nhap diem ly : "; cin >> ly; if (ly<0 || ly>10){ cout << "\nNhap lai 0 < diem ly <10" << endl; system("cls"); } } while (ly<0 || ly>10); do{ cout << "Nhap diem hoa : "; cin >> hoa; if (hoa<0 || hoa>10){ cout << "\nNhap lai 0 < diem hoa <10" << endl; system("cls"); } } while (hoa<0 || hoa>10); } void in() { cout << "SBD: " << sbd; cout << "\tDiem toan:" << toan << "\tDiem ly:" << ly << "\tDiem hoa:" << hoa; cout << "\tTong diem: " << tongdiem() << endl; } float tongdiem() { return(toan + ly + hoa); } }; class ds { private: int n; thisinh ts[100]; public: void nhapds() { cout << "Nhap vao so luong thi sinh: "; cin >> n; for (int i = 0; i < n; i++) ts[i].nhap(); } void inds() { for (int i = 0; i < n; i++) ts[i].in(); } void sapxep() { for (int i = 0; i < n - 1; i++) for (int j = i + 1; jts[j].tongdiem()) { thisinh tg; tg = ts[i]; ts[i] = ts[j]; ts[j] = tg; } } void tongdiemtren18() { for (int i = 0; i18) ts[i].in(); } }; int main() { ds ds1; ds1.nhapds(); system("cls"); cout << "\nDanh sach cac thi sinh sap xep theo thu tu tang dan ve tong diem:\n" << endl; ds1.sapxep(); ds1.inds(); cout << "--------------------------------------------------------------------------\n"; cout << "\nDanh sach cac thi sinh co tong diem tren 18 la: \n" << endl; ds1.tongdiemtren18(); return 0; }