Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <iomanip>
- #include <string.h>
- #include <malloc.h>
- using namespace std;
- class Date{
- private:
- int ngay,thang,nam;
- public:
- void nhap(){
- cout<<"\t\tNgay: "; cin>>ngay;
- cout<<"\t\tThang: "; cin>>thang;
- cout<<"\t\tNam: "; cin>>nam;
- }
- void xuat(){
- cout<<setw(2)<<right<<setfill('0')<<ngay<<"/";
- cout<<setw(2)<<right<<setfill('0')<<thang<<"/";
- cout<<setw(4)<<right<<setfill(' ')<<nam<<" ";
- }
- };
- class NoiDK{
- private:
- char huyen[30];
- char tinh[30];
- public:
- void nhap(){
- cout<<"\t\tHuyen: "; fflush(stdin); gets(huyen);
- cout<<"\t\tTinh: "; fflush(stdin); gets(tinh);
- }
- void xuat(){
- cout<<setw(15)<<left<<huyen;
- cout<<setw(15)<<left<<tinh;
- }
- };
- class Xe {
- protected:
- char hoTen[30];
- char bienSo[15];
- NoiDK noiDK;
- Date ngayDK;
- public:
- void nhap(){
- cout<<"\tHo ten chu : "; fflush(stdin); gets(hoTen);
- cout<<"\tBien so : "; fflush(stdin); gets(bienSo);
- cout<<"\tNoi dk:"<<endl; noiDK.nhap();
- cout<<"\tNgay dk: "<<endl; ngayDK.nhap();
- }
- void xuat(){
- cout<<setw(20)<<left<<hoTen;
- cout<<setw(15)<<left<<bienSo;
- noiDK.xuat();
- ngayDK.xuat();
- }
- };
- class XeMay:public Xe{
- private:
- double giaTien;
- char mauSon[10];
- public:
- void nhap(){
- Xe::nhap();
- cout<<"\tGia tien: "; cin>>giaTien;
- cout<<"\tMau son: "; fflush(stdin); gets(mauSon);
- }
- void xuat(){
- Xe::xuat();
- cout<<setw(15)<<left<<giaTien;
- cout<<setw(10)<<left<<mauSon<<endl;
- }
- friend class List;
- };
- class List{
- private:
- int n;
- XeMay *a;
- public:
- void nhap(){
- cout<<"Nhap so luong xe: "; cin>>n;
- a = new XeMay[n];
- for(int i=0;i<n;i++)
- {
- cout<<"\tNhap thong tin xe thu "<<i+1<<endl;
- a[i].nhap();
- }
- }
- void xuat(){
- cout<<setw(20)<<left<<"Ho ten";
- cout<<setw(15)<<left<<"Bien so";
- cout<<setw(30)<<left<<" Noi dang ky";
- cout<<setw(11)<<left<<"Ngay dk";
- cout<<setw(15)<<left<<"Gia tien";
- cout<<setw(10)<<left<<"mau son"<<endl;
- cout<<setw(20)<<left<<"";
- cout<<setw(15)<<left<<"";
- cout<<setw(15)<<left<<"Huyen";
- cout<<setw(15)<<left<<"Tinh";
- cout<<setw(11)<<left<<"";
- cout<<setw(15)<<left<<"";
- cout<<setw(10)<<left<<""<<endl;
- for(int i=0;i<n;i++)
- a[i].xuat();
- }
- double tongTien(){
- double T =0;
- for(int i=0;i<n;i++)
- if(strcmp(a[i].mauSon,"do")==0)
- T+= a[i].giaTien;
- return T;
- }
- void Xoa(){
- int k;
- do{
- cout<<"Nhap vt can xoa 1<= k<=n: " ; cin>>k;
- }
- while(k<1||k>n);
- for(int i=k-1;i<n-1;i++)
- a[i]=a[i+1];
- a = (XeMay*) realloc(a,(n-1)*sizeof(XeMay));
- n--;
- }
- void Xoamauxanh(){
- for(int i=0;i<n;i++)
- while(strcmp(a[i].mauSon,"xanh")==0)
- {
- //int k=i+1;
- for(int j=i;j<n-1;j++)
- a[j]=a[j+1];
- a = (XeMay*) realloc(a,(n-1)*sizeof(XeMay));
- n--;
- }
- }
- };
- int main()
- {
- List l;
- l.nhap();
- l.xuat();
- cout<<"Tong tien nhung xe mau do: "<<l.tongTien();
- //l.Xoamauxanh();
- l.Xoa();
- cout<<"\t\tDanh sach sau khi xoa: "<<endl;
- l.xuat();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement