Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<conio.h>
- #define long long long
- #define nln '\n'
- using namespace std;
- // khai báo lớp cha: class XE
- class XE{
- protected:
- string HoTenNguoiThue;
- float SoGioThue;
- public:
- void NhapThongTin(){
- cin.ignore(); // xóa phím enter đang ở trong bộ nhớ đệm
- cout << "Nhap ho ten nguoi thue: ";
- getline(cin, HoTenNguoiThue);
- cout << "Nhap so gio thue: ";
- cin >> SoGioThue;
- }
- void XuatThongTin(){
- cout << "Ho ten nguoi thue la: " << HoTenNguoiThue << nln;
- cout << "So gio thue la: " << SoGioThue << nln;
- }
- };
- // khai báo lớp con: class XEDAP kế thừa lại class XE
- class XEDAP : public XE{
- private:
- public:
- float TinhTienThueXe(){
- return 10000 + ((SoGioThue - 1) * 8000);
- }
- };
- // khai báo lớp con: class XEMAY kế thừa lại class XE
- class XEMAY : public XE{
- private:
- int LoaiXe;
- string BienSo;
- public:
- void NhapThongTin(){
- XE::NhapThongTin();
- cout << "Nhap loai xe can thue(100 - 250 phan khoi): ";
- cin >> LoaiXe;
- cin.ignore(); // xóa phím enter đang ở trong bộ nhớ đệm
- cout << "Nhap bien so: ";
- getline(cin, BienSo);
- }
- float TinhTienThueXe(){
- float s = 0;
- if (LoaiXe == 100)
- s = 150000;
- else
- s = 200000;
- return s + ((SoGioThue - 1) * 100000);
- }
- void XuatThongTin(){
- XE::XuatThongTin();
- cout << "Loai xe: " << LoaiXe << nln;
- cout << "Bien so: " << BienSo << nln;
- cout << "Tien thue: " << TinhTienThueXe() << nln;
- }
- };
- void thong_tin_thue_xe_dap(XEDAP ds_xedap[], int n)
- {
- int dem = 1;
- cout << "\n\n\t\t DANH SACH THUE XE DAP\n";
- for (int i = 0; i < n; i++){
- cout << "\n\tTHONG TIN THUE XE DAP THU " << dem++ << endl;
- ds_xedap[i].XuatThongTin();
- }
- }
- void thong_tin_thue_xe_may(XEMAY ds_xemay[], int m)
- {
- cout << "\n\n\t\t DANH SACH THUE XE MAY\n";
- int pos=1;
- for (int i = 0; i < m; i++){
- cout << "\n\tTHONG TIN THUE MAY THU " << pos++ << endl;
- ds_xemay[i].XuatThongTin();
- }
- }
- void Xuat_Tat_Ca_Thong_Tin_Thue_Xe(XEDAP ds_xedap[], int n, XEMAY ds_xemay[], int m)
- {
- thong_tin_thue_xe_dap(ds_xedap, n);
- thong_tin_thue_xe_may(ds_xemay, m);
- cout << nln << nln;
- }
- float Tinh_Tong_Tien_Thue_Xe(XEDAP ds_xedap[], int n, XEMAY ds_xemay[], int m)
- {
- float tong = 0;
- // duyệt danh sách xe đạp
- for (int i = 0; i < n; i++)
- tong += ds_xedap[i].TinhTienThueXe();
- // duyệt danh sách xe máy
- for (int i = 0; i < m; i++)
- tong += ds_xemay[i].TinhTienThueXe();
- return tong;
- }
- // Menu chính thể hiện các chức năng
- void Menu(XEDAP ds_xedap[], int n, XEMAY ds_xemay[], int m)
- {
- int luachon;
- while (true){
- system("cls");
- cout << "========== QUAN LY XE ==========" << nln;
- cout << "1. Nhap danh sach thue xe dap hoac xe may" << nln;
- cout << "2. Xuat tat ca thong tin thue xe" << nln;
- cout << "3. Tinh tong so tien cho thue xe" << nln;
- cout << "4. Xuat tat ca cac thong tin lien quan den viec cho thue xe dap" << nln;
- cout << "5. Xuat tat ca cac thong tin lien quan den viec cho thue xe may" << nln;
- cout << "0. Ket thuc" << nln;
- cout << "============== END =============" << nln;
- cout << "Ban muon lam gi(0->6): ";
- cin >> luachon;
- if (!luachon)
- break;
- switch (luachon){
- case 1:
- int chon;
- while (1){
- system("cls");
- cout << "1. Thue XE DAP" << nln;
- cout << "2. Thue XE MAY" << nln;
- cout << "0. Ket thuc" << nln;
- cout << "Nhap loai xe muon thue: ";
- cin >> chon;
- if (chon == 1){
- XEDAP x;
- cout << "NHAP THONG TIN THUE XE DAP\n";
- x.NhapThongTin();
- ds_xedap[n] = x;
- n++;
- }
- else
- if (chon == 2){
- XEMAY x;
- cout << " NHAP THONG TIN THUE XE MAY\n";
- x.NhapThongTin();
- ds_xemay[m] = x;
- m++;
- }
- else
- break;
- }
- break;
- case 2:
- Xuat_Tat_Ca_Thong_Tin_Thue_Xe(ds_xedap, n, ds_xemay, m);
- system("pause");
- break;
- case 3:
- system("clrscr");
- cout << "\n\n\t\tTONG TIEN THUE XE: " << (size_t)Tinh_Tong_Tien_Thue_Xe(ds_xedap, n, ds_xemay, m) << nln;
- cout << nln << nln;
- system("pause");
- break;
- case 4:
- thong_tin_thue_xe_dap(ds_xedap, n);
- cout << nln << nln << nln;
- system("pause");
- break;
- case 5:
- thong_tin_thue_xe_may(ds_xemay, m);
- cout << nln << nln << nln;
- system("pause");
- break;
- }
- }
- }
- int main()
- {
- XEDAP ds_xedap[100];
- int n = 0;
- XEMAY ds_xemay[100];
- int m = 0;
- Menu(ds_xedap, n, ds_xemay, m);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement