Advertisement
Iamtui1010

kiem_soat_thue_xe.cpp

Feb 2nd, 2023 (edited)
1,184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.52 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<conio.h>
  4.  
  5. #define long long long
  6. #define nln '\n'
  7.  
  8. using namespace std;
  9.  
  10. // khai báo lớp cha: class XE
  11. class XE{
  12. protected:
  13.     string HoTenNguoiThue;
  14.     float SoGioThue;
  15. public:
  16.     void NhapThongTin(){
  17.         cin.ignore(); // xóa phím enter đang ở trong bộ nhớ đệm
  18.         cout << "Nhap ho ten nguoi thue: ";
  19.         getline(cin, HoTenNguoiThue);
  20.         cout << "Nhap so gio thue: ";
  21.         cin >> SoGioThue;
  22.     }
  23.     void XuatThongTin(){
  24.         cout << "Ho ten nguoi thue la: " << HoTenNguoiThue << nln;
  25.         cout << "So gio thue la: " << SoGioThue << nln;
  26.     }
  27. };
  28. // khai báo lớp con: class XEDAP kế thừa lại class XE
  29. class XEDAP : public XE{
  30. private:
  31. public:
  32.     float TinhTienThueXe(){
  33.         return 10000 + ((SoGioThue - 1) * 8000);
  34.     }
  35. };
  36. // khai báo lớp con: class XEMAY kế thừa lại class XE
  37. class XEMAY : public XE{
  38. private:
  39.     int LoaiXe;
  40.     string BienSo;
  41. public:
  42.     void NhapThongTin(){
  43.         XE::NhapThongTin();
  44.         cout << "Nhap loai xe can thue(100 - 250 phan khoi): ";
  45.         cin >> LoaiXe;
  46.         cin.ignore(); // xóa phím enter đang ở trong bộ nhớ đệm
  47.         cout << "Nhap bien so: ";
  48.         getline(cin, BienSo);
  49.  
  50.     }
  51.     float TinhTienThueXe(){
  52.         float s = 0;
  53.         if (LoaiXe == 100)
  54.             s = 150000;
  55.         else
  56.             s = 200000;
  57.         return s + ((SoGioThue - 1) * 100000);
  58.     }
  59.     void XuatThongTin(){
  60.         XE::XuatThongTin();
  61.         cout << "Loai xe: " << LoaiXe << nln;
  62.         cout << "Bien so: " << BienSo << nln;
  63.         cout << "Tien thue: " << TinhTienThueXe() << nln;
  64.     }
  65. };
  66.  
  67. void thong_tin_thue_xe_dap(XEDAP ds_xedap[], int n)
  68. {
  69.     int dem = 1;
  70.     cout << "\n\n\t\t DANH SACH THUE XE DAP\n";
  71.     for (int i = 0; i < n; i++){
  72.         cout << "\n\tTHONG TIN THUE XE DAP THU " << dem++ << endl;
  73.         ds_xedap[i].XuatThongTin();
  74.     }
  75. }
  76.  
  77. void thong_tin_thue_xe_may(XEMAY ds_xemay[], int m)
  78. {
  79.     cout << "\n\n\t\t DANH SACH THUE XE MAY\n";
  80.     int pos=1;
  81.     for (int i = 0; i < m; i++){
  82.         cout << "\n\tTHONG TIN THUE MAY THU " << pos++ << endl;
  83.         ds_xemay[i].XuatThongTin();
  84.     }
  85. }
  86.  
  87. void Xuat_Tat_Ca_Thong_Tin_Thue_Xe(XEDAP ds_xedap[], int n, XEMAY ds_xemay[], int m)
  88. {
  89.     thong_tin_thue_xe_dap(ds_xedap, n);
  90.     thong_tin_thue_xe_may(ds_xemay, m);
  91.     cout << nln << nln;
  92. }
  93.  
  94. float Tinh_Tong_Tien_Thue_Xe(XEDAP ds_xedap[], int n, XEMAY ds_xemay[], int m)
  95. {
  96.     float tong = 0;
  97.     // duyệt danh sách xe đạp
  98.     for (int i = 0; i < n; i++)        
  99.         tong += ds_xedap[i].TinhTienThueXe();
  100.     // duyệt danh sách xe máy
  101.     for (int i = 0; i < m; i++)
  102.         tong += ds_xemay[i].TinhTienThueXe();
  103.     return tong;
  104. }
  105. // Menu chính thể hiện các chức năng
  106. void Menu(XEDAP ds_xedap[], int n, XEMAY ds_xemay[], int m)
  107. {
  108.     int luachon;
  109.     while (true){
  110.         system("cls");
  111.         cout << "========== QUAN LY XE ==========" << nln;
  112.         cout << "1. Nhap danh sach thue xe dap hoac xe may" << nln;
  113.         cout << "2. Xuat tat ca thong tin thue xe" << nln;
  114.         cout << "3. Tinh tong so tien cho thue xe" << nln;
  115.         cout << "4. Xuat tat ca cac thong tin lien quan den viec cho thue xe dap" << nln;
  116.         cout << "5. Xuat tat ca cac thong tin lien quan den viec cho thue xe may" << nln;
  117.         cout << "0. Ket thuc" << nln;
  118.         cout << "============== END =============" << nln;
  119.         cout << "Ban muon lam gi(0->6): ";
  120.         cin >> luachon;
  121.  
  122.         if (!luachon)
  123.             break;
  124.         switch (luachon){
  125.             case 1:
  126.                 int chon;
  127.                 while (1){
  128.                     system("cls");
  129.                     cout << "1. Thue XE DAP" << nln;
  130.                     cout << "2. Thue XE MAY" << nln;
  131.                     cout << "0. Ket thuc" << nln;
  132.                     cout << "Nhap loai xe muon thue: ";
  133.                     cin >> chon;
  134.  
  135.                     if (chon == 1){
  136.                         XEDAP x;
  137.                         cout << "NHAP THONG TIN THUE XE DAP\n";
  138.                         x.NhapThongTin();
  139.                         ds_xedap[n] = x;
  140.                         n++;
  141.                     }
  142.                     else
  143.                         if (chon == 2){
  144.                             XEMAY x;
  145.                             cout << " NHAP THONG TIN THUE XE MAY\n";
  146.                             x.NhapThongTin();
  147.                             ds_xemay[m] = x;
  148.                             m++;
  149.                         }
  150.                         else
  151.                             break;
  152.                 }
  153.                 break;
  154.             case 2:
  155.                 Xuat_Tat_Ca_Thong_Tin_Thue_Xe(ds_xedap, n, ds_xemay, m);
  156.                 system("pause");
  157.                 break;
  158.             case 3:
  159.                 system("clrscr");
  160.                 cout << "\n\n\t\tTONG TIEN THUE XE: " << (size_t)Tinh_Tong_Tien_Thue_Xe(ds_xedap, n, ds_xemay, m) << nln;
  161.                 cout << nln << nln;
  162.                 system("pause");
  163.                 break;
  164.             case 4:
  165.                 thong_tin_thue_xe_dap(ds_xedap, n);
  166.                 cout << nln << nln << nln;
  167.                 system("pause");
  168.                 break;
  169.             case 5:
  170.                 thong_tin_thue_xe_may(ds_xemay, m);
  171.                 cout << nln << nln << nln;
  172.                 system("pause");
  173.                 break;
  174.         }
  175.     }
  176. }
  177.  
  178.  
  179. int main()
  180. {
  181.     XEDAP ds_xedap[100];
  182.     int n = 0;
  183.     XEMAY ds_xemay[100];
  184.     int m = 0;
  185.     Menu(ds_xedap, n, ds_xemay, m);
  186.     system("pause");
  187.     return 0;
  188. }
  189.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement