Untitled
unknown
plain_text
a year ago
5.5 kB
156
Indexable
#include<iostream> #include<string> #include<vector> using namespace std; class Nguoi{ protected : string Hoten; int NamSinh; public : Nguoi (){} Nguoi(string Hoten,int NamSinh){ this->Hoten=Hoten; this->NamSinh=NamSinh; } ~Nguoi(){} virtual void input(){ cin.ignore (); cout<<"nhap Hoten :"; getline(cin,Hoten); cout<<"nhap NamSinh : "; cin>>NamSinh; } virtual void output (){ cout<<"Hoten : "<<this->Hoten<<endl; cout<<"NamSinh : "<<this->NamSinh<<endl; } }; class BN_O: public Nguoi { private : string Tenbenh ; int Tiendieutri ; public: BN_O(){} BN_O(string Hoten, int NamSinh , string TenBenh ,int Tiendieutri): Nguoi (Hoten,NamSinh){ this ->Tenbenh=Tenbenh; this->Tiendieutri=Tiendieutri; } ~BN_O (){} void input(){ Nguoi::input(); cin.ignore() ; cout<<"nhap Tenbenh :" ;getline(cin,Tenbenh); cout<<" nhap Tiendieutri :"; cin>>Tiendieutri; } void output(){ Nguoi::output(); cout<<"nhap Tenbenh :" <<this->Tenbenh<<endl; cout<<"nhap Tiendieutri : "<<this ->Tiendieutri<<endl; } }; class BN_I: public Nguoi{ private : string Tenbenh ; int Tienthuoc ; int Tieno ; public : BN_I(){} BN_I(string Hoten, int NamSinh , string TenBenh ,int Tienthuoc, int Tieno): Nguoi (Hoten,NamSinh){ this ->Tenbenh=Tenbenh; this->Tienthuoc=Tienthuoc; this->Tieno=Tieno; } ~BN_I (){} void input(){ Nguoi::input(); cin.ignore() ; cout<<"nhap Tenbenh :" ;getline(cin,Tenbenh); cout<<" nhap Tienthuoc :"; cin>>Tienthuoc; cout<<"nhap Tieno : "; cin>>Tieno; } void output(){ Nguoi::output(); cout<<"nhap Tenbenh :" <<this->Tenbenh<<endl; cout<<"nhap Tienthuoc : "<<this ->Tienthuoc<<endl; cout<<"nhap Tieno : "<<this->Tieno<<endl; } }; class menu{ private: vector<Nguoi*> ds; public: menu(){} ~menu(){ for(int i = 0;i<ds.size();i++){ delete ds[i]; } ds.clear(); } void NhapDS(){ while(true){ cout << "===Lua chon Xe===" << endl; cout << "1. Benh nhan ngoai tru " << endl; cout << "2. Benh nham noi tru " << endl; cout<<"3.Xuat danh sach "<<endl; cout << "0. Thoat" << endl; int loai; cout << "Nhap: "; cin >>loai; if(loai == 1){ Nguoi *ngoaitru = new BN_O(); ngoaitru->input(); ds.push_back(ngoaitru); }else if(loai == 2){ Nguoi *noitru = new BN_I(); noitru->input(); ds.push_back(noitru); }else if(loai == 0){ break; }else{ cout << "Lua chon khong dung!" << endl; } } } void XuatDS(){ for(int i = 0; i < ds.size(); i++){ cout << "==Thong tin benh nhan thu " << (i+1) << ": " << endl; ds[i]->output(); int tongtien = 0; cout << "Tong tien thanh toan: " << tongtien << endl; } } void Menu(){ while(true){ cout << "===MENU===" << endl; cout << "1. Nhap DS" << endl; cout << "2. Xuat DS" << endl; cout << "0. Thoat" << endl; int luachon; cout << "Nhap lua chon: "; cin >> luachon; if(luachon == 1){ NhapDS(); }else if(luachon == 2){ XuatDS(); }else{ cout << "Lua chon khong dung!" << endl; } } } }; int main (){ menu *ql=new menu(); ql->Menu(); delete ql; return 0; }
Editor is loading...
Leave a Comment