Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://www.facebook.com/pages/C%C3%B9ng-h%E1%BB%8Dc-l%E1%BA%ADp-tr%C3%ACnh/632038696941833
- #include <iostream>
- #include <string>
- using namespace std;
- class Ve
- {
- protected:
- string MaVe, HoTen;
- int NamSinh, SoTroChoi;
- public:
- Ve(string MaVe = "", string HoTen = "", int NamSinh = 0, int SoTroChoi = 0)
- {
- this->HoTen = HoTen;
- this->MaVe = MaVe;
- this->NamSinh = NamSinh;
- this->SoTroChoi = SoTroChoi;
- }
- virtual void Nhap()
- {
- fflush(stdin);
- cout << "Nhap ma ve: ";
- getline(cin, this->MaVe);
- cout << "Nhap ten: ";
- getline(cin, this->HoTen);
- cout << "Nhap nam sinh: ";
- cin >> this->NamSinh;
- }
- virtual int TienVe() = 0;
- virtual int LayLoaiVe() = 0;
- virtual ~Ve(){}
- };
- class VeTronGoi : public Ve
- {
- public:
- VeTronGoi(string MaVe = "", string HoTen = "", int NamSinh = 0) : Ve(MaVe, HoTen, NamSinh, 0)
- {
- }
- ~VeTronGoi(){}
- void Nhap()
- {
- Ve::Nhap();
- }
- int TienVe()
- {
- return 200000;
- }
- int LayLoaiVe()
- {
- return 0;
- }
- };
- class VeTungPhan : public Ve
- {
- public:
- VeTungPhan(string MaVe = "", string HoTen = "", int NamSinh = 0, int SoTroChoi = 0) : Ve(MaVe, HoTen, NamSinh, SoTroChoi)
- {
- }
- ~VeTungPhan(){}
- void Nhap()
- {
- Ve::Nhap();
- cout << "Nhap so tro choi: ";
- cin >> this->SoTroChoi;
- }
- int TienVe()
- {
- return (70000 + 20000 * this->SoTroChoi);
- }
- int LayLoaiVe()
- {
- return 1;
- }
- };
- class DSVe
- {
- Ve **dsVe;
- int SoVe;
- int TongTien;
- public:
- DSVe()
- {
- do
- {
- cout << "So ve can nhap: ";
- cin >> this->SoVe;
- } while (this->SoVe < 0);
- TongTien = 0;
- dsVe = new Ve*[this->SoVe];
- }
- ~DSVe()
- {
- delete[] dsVe;
- }
- int NhapLoaiVe()
- {
- int a;
- do
- {
- cout << "1. Ve tron goi\n2. Ve tung phan\n\tNhap so tuong ung: ";
- cin >> a;
- if (a == 1 || a == 2) return (a - 1);
- } while (1);
- }
- void Nhap()
- {
- for (int i = 0; i < SoVe; i++)
- {
- cout << "Ve thu " << i + 1 << ": \n";
- switch (NhapLoaiVe())
- {
- case 0:
- dsVe[i] = new VeTronGoi;
- break;
- case 1:
- dsVe[i] = new VeTungPhan;
- break;
- }
- dsVe[i]->Nhap();
- }
- }
- int TinhTongTien()
- {
- for (int i = 0; i < this->SoVe; i++)
- TongTien += dsVe[i]->TienVe();
- return this->TongTien;
- }
- int LayTongTien()
- {
- return this->TongTien;
- }
- int SoVeTungPhan()
- {
- int s = 0;
- for (int i = 0; i < this->SoVe; i++)
- {
- if (dsVe[i]->LayLoaiVe() == 1)
- s++;
- }
- return s;
- }
- };
- void main()
- {
- DSVe DS;
- DS.Nhap();
- cout << DS.TinhTongTien() << endl;
- cout << DS.SoVeTungPhan();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement