Advertisement
huutho_96

thisinh

Jan 19th, 2016
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.11 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include<string>
  4. #include<windows.h>
  5. using namespace std;
  6. class thisinh
  7. {
  8. private:
  9.     char sbd[25];
  10.     float toan, ly, hoa;
  11. public:
  12.  
  13.     void nhap()
  14.     {
  15.         fflush(stdin);
  16.         cout << "\n------------------------------------------------------------\n";
  17.  
  18.         cout << "Nhap so bao danh :    ";
  19.         cin >> sbd;
  20.         do{
  21.             cout << "Nhap diem toan :    ";
  22.             cin >> toan;
  23.             if (toan<0 || toan>10){
  24.  
  25.                 cout << "\nNhap lai 0 < diem toan <10" << endl;
  26.                 system("cls");
  27.             }
  28.         } while (toan<0 || toan>10);
  29.  
  30.         do{
  31.             cout << "Nhap diem ly :    ";
  32.             cin >> ly;
  33.             if (ly<0 || ly>10){
  34.                 cout << "\nNhap lai 0 < diem ly <10" << endl;
  35.                 system("cls");
  36.             }
  37.  
  38.         } while (ly<0 || ly>10);
  39.         do{
  40.             cout << "Nhap diem hoa :    ";
  41.             cin >> hoa;
  42.             if (hoa<0 || hoa>10){
  43.  
  44.                 cout << "\nNhap lai 0 < diem hoa <10" << endl;
  45.                 system("cls");
  46.             }
  47.         } while (hoa<0 || hoa>10);
  48.     }
  49.     void in()
  50.     {
  51.         cout << "SBD: " << sbd;
  52.         cout << "\tDiem toan:" << toan << "\tDiem ly:" << ly << "\tDiem hoa:" << hoa;
  53.         cout << "\tTong diem: " << tongdiem() << endl;
  54.     }
  55.  
  56.  
  57.     float tongdiem()
  58.     {
  59.         return(toan + ly + hoa);
  60.     }
  61. };
  62.  
  63. class ds
  64. {
  65. private:
  66.     int n;
  67.     thisinh ts[100];
  68.  
  69. public:
  70.  
  71.  
  72.     void nhapds()
  73.     {
  74.         cout << "Nhap vao so luong thi sinh:  ";
  75.         cin >> n;
  76.         for (int i = 0; i < n; i++)
  77.             ts[i].nhap();
  78.     }
  79.  
  80.  
  81.     void inds()
  82.     {
  83.         for (int i = 0; i < n; i++)
  84.             ts[i].in();
  85.     }
  86.     void sapxep()
  87.     {
  88.  
  89.         for (int i = 0; i < n - 1; i++)
  90.         for (int j = i + 1; j<n; j++)
  91.         if (ts[i].tongdiem()>ts[j].tongdiem())
  92.         {
  93.             thisinh tg;
  94.             tg = ts[i];
  95.             ts[i] = ts[j];
  96.             ts[j] = tg;
  97.         }
  98.     }
  99.  
  100.     void tongdiemtren18()
  101.     {
  102.  
  103.         for (int i = 0; i<n; i++)
  104.         if (ts[i].tongdiem()>18)
  105.             ts[i].in();
  106.     }
  107.  
  108. };
  109. int main()
  110. {
  111.     ds ds1;
  112.     ds1.nhapds();
  113.     system("cls");
  114.     cout << "\nDanh sach cac thi sinh sap xep theo thu tu tang dan ve tong diem:\n" << endl;
  115.     ds1.sapxep();
  116.     ds1.inds();
  117.     cout << "--------------------------------------------------------------------------\n";
  118.     cout << "\nDanh sach cac thi sinh co tong diem tren 18 la: \n" << endl;
  119.     ds1.tongdiemtren18();
  120.  
  121.     return 0;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement