[r]
(1)#include <iostream.h> #include "stdio.h" #include <conio.h> class Date{
int ngay,thang,nam; friend class HD; };
class KHACH{
char mk[10],tk[30],phone[15]; public :
void nhap(); void xuat(); };
class HANG{ char mh[10],th[40]; int solg;
float dongia; public : void nhap(); void xuat(); friend class HD; };
class HD{ int k,sohd; Date ngaylap; KHACH y; HANG H[40]; float tongtien; public : void nhap(); void xuat(); };
void KHACH::nhap()
{ cout<<"nhap ma khach : "; fflush(stdin); gets(mk); cout<<"nhap ten khach : "; fflush(stdin); gets(tk);
cout<<"nhap so phone khach : "; fflush(stdin); gets(phone); }
void KHACH::xuat()
{ cout<<"\tma khach : " <<mk<<endl; cout<<"\tten khach : " <<tk<<endl;
cout<<"\tphone khach : " <<phone<<endl; }
void HANG::nhap()
(2)cout<<"nhap so luong : ";cin>>solg; }
void HANG::xuat()
{ cout<<"\tma hang : " <<mh<<endl; cout<<"\tten hang : " <<th<<endl; cout<<"\tdon gia : " <<dongia<<endl; cout<<"\tso luong : " <<solg<<endl; }
void HD::nhap()
{ cout<<"nhap so hoa don : ";cin>>sohd; cout<<"ngay lap hoa don : "<<endl;
cin>>ngaylap.ngay>>ngaylap.thang>>ngaylap.nam; cout<<"nhap thong tin khach hang : "<<endl;
y.nhap();
cout<<"so hang hoa hoa don : "; cin>>k; cout<<"nhap danh sach hang hoa : ";
for(int i=0;i<k;i++)
{ cout<<"\tnhap hang thu "<<(i+1)<<" : "<<endl; H[i].nhap();
}
float tg=0;
for(int j=0;j<k;j++)
tg=tg+H[j].dongia * H[j].solg; tongtien=tg;
}
void HD::xuat()
{ cout<<"so hoa don : " <<sohd<<endl; cout<<"ngay : "
<<ngaylap.ngay<<"/"<<ngaylap.thang<<"/"<<ngaylap.nam<<endl; cout<<"khach : "<<endl;
y.xuat();
cout<<"danh sach hang hoa : "<<endl; for(int i=0;i<k;i++)
{ cout<<" Mat Hang thu "<<(i+1)<<" : "<<endl; H[i].xuat();
}
cout<<"tong tien toan : "<<tongtien; }
void main() { HD X;
cout<<"Nhap thong tin : "<<endl; X.nhap();
cout<<"Thong tin hoa don:"<<endl; X.xuat();
(3)