Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <iomanip>
  4. #include <string.h>
  5. #include <malloc.h>
  6. using namespace std;
  7. class Date{
  8. private:
  9. int ngay,thang,nam;
  10. public:
  11. void nhap(){
  12. cout<<"\t\tNgay: "; cin>>ngay;
  13. cout<<"\t\tThang: "; cin>>thang;
  14. cout<<"\t\tNam: "; cin>>nam;
  15.  
  16. }
  17. void xuat(){
  18. cout<<setw(2)<<right<<setfill('0')<<ngay<<"/";
  19. cout<<setw(2)<<right<<setfill('0')<<thang<<"/";
  20. cout<<setw(4)<<right<<setfill(' ')<<nam<<" ";
  21. }
  22.  
  23. };
  24. class NoiDK{
  25. private:
  26. char huyen[30];
  27. char tinh[30];
  28. public:
  29. void nhap(){
  30. cout<<"\t\tHuyen: "; fflush(stdin); gets(huyen);
  31. cout<<"\t\tTinh: "; fflush(stdin); gets(tinh);
  32.  
  33. }
  34. void xuat(){
  35. cout<<setw(15)<<left<<huyen;
  36. cout<<setw(15)<<left<<tinh;
  37. }
  38. };
  39. class Xe {
  40. protected:
  41. char hoTen[30];
  42. char bienSo[15];
  43. NoiDK noiDK;
  44. Date ngayDK;
  45. public:
  46.  
  47. void nhap(){
  48. cout<<"\tHo ten chu : "; fflush(stdin); gets(hoTen);
  49. cout<<"\tBien so : "; fflush(stdin); gets(bienSo);
  50. cout<<"\tNoi dk:"<<endl; noiDK.nhap();
  51. cout<<"\tNgay dk: "<<endl; ngayDK.nhap();
  52.  
  53. }
  54. void xuat(){
  55. cout<<setw(20)<<left<<hoTen;
  56. cout<<setw(15)<<left<<bienSo;
  57. noiDK.xuat();
  58. ngayDK.xuat();
  59.  
  60. }
  61.  
  62. };
  63. class XeMay:public Xe{
  64. private:
  65. double giaTien;
  66. char mauSon[10];
  67. public:
  68. void nhap(){
  69. Xe::nhap();
  70. cout<<"\tGia tien: "; cin>>giaTien;
  71. cout<<"\tMau son: "; fflush(stdin); gets(mauSon);
  72.  
  73. }
  74. void xuat(){
  75. Xe::xuat();
  76. cout<<setw(15)<<left<<giaTien;
  77. cout<<setw(10)<<left<<mauSon<<endl;
  78. }
  79. friend class List;
  80. };
  81.  
  82. class List{
  83. private:
  84. int n;
  85. XeMay *a;
  86. public:
  87. void nhap(){
  88. cout<<"Nhap so luong xe: "; cin>>n;
  89. a = new XeMay[n];
  90. for(int i=0;i<n;i++)
  91. {
  92. cout<<"\tNhap thong tin xe thu "<<i+1<<endl;
  93. a[i].nhap();
  94. }
  95. }
  96. void xuat(){
  97. cout<<setw(20)<<left<<"Ho ten";
  98. cout<<setw(15)<<left<<"Bien so";
  99. cout<<setw(30)<<left<<" Noi dang ky";
  100. cout<<setw(11)<<left<<"Ngay dk";
  101. cout<<setw(15)<<left<<"Gia tien";
  102. cout<<setw(10)<<left<<"mau son"<<endl;
  103. cout<<setw(20)<<left<<"";
  104. cout<<setw(15)<<left<<"";
  105. cout<<setw(15)<<left<<"Huyen";
  106. cout<<setw(15)<<left<<"Tinh";
  107. cout<<setw(11)<<left<<"";
  108. cout<<setw(15)<<left<<"";
  109. cout<<setw(10)<<left<<""<<endl;
  110. for(int i=0;i<n;i++)
  111. a[i].xuat();
  112.  
  113.  
  114. }
  115. double tongTien(){
  116. double T =0;
  117. for(int i=0;i<n;i++)
  118. if(strcmp(a[i].mauSon,"do")==0)
  119. T+= a[i].giaTien;
  120. return T;
  121. }
  122. void Xoa(){
  123. int k;
  124. do{
  125. cout<<"Nhap vt can xoa 1<= k<=n: " ; cin>>k;
  126.  
  127. }
  128. while(k<1||k>n);
  129. for(int i=k-1;i<n-1;i++)
  130. a[i]=a[i+1];
  131. a = (XeMay*) realloc(a,(n-1)*sizeof(XeMay));
  132. n--;
  133. }
  134. void Xoamauxanh(){
  135.  
  136. for(int i=0;i<n;i++)
  137. while(strcmp(a[i].mauSon,"xanh")==0)
  138. {
  139. //int k=i+1;
  140. for(int j=i;j<n-1;j++)
  141. a[j]=a[j+1];
  142. a = (XeMay*) realloc(a,(n-1)*sizeof(XeMay));
  143. n--;
  144. }
  145. }
  146.  
  147. };
  148. int main()
  149. {
  150. List l;
  151. l.nhap();
  152. l.xuat();
  153. cout<<"Tong tien nhung xe mau do: "<<l.tongTien();
  154. //l.Xoamauxanh();
  155. l.Xoa();
  156. cout<<"\t\tDanh sach sau khi xoa: "<<endl;
  157. l.xuat();
  158.  
  159. return 0;
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement