bai6-week5
// quan ly hoa don
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdio.h>
class HD
{ char ma[10],ten[25];
int lp,ngay,thang,nam;
float kl,dg,tt;
public:
friend istream& operator>>(istream& is,HD &b);
friend ostream& operator<<(ostream& os,HD b);
friend int ktra(HD);
int operator>(HD);
friend float gt(HD);
};
istream& operator>>(istream& is,HD &b)
{ fflush(stdin);
cout<<"nhap ma vat tu: ";gets(b.ma);
cout<<"nhap ten vat tu: ";gets(b.ten);
cout<<"nhap 1-neu phieu nhap // nhap 0-neu phieu xuat:";is>>b.lp;
cout<<"nhap ngay thang nam lap:
";is>>b.ngay>>b.thang>>b.nam;
cout<<"nhap khoi luong(kg)vat tu: ";is>>b.kl;
cout<<"nhap don gia(vnd/kg)vat tu: ";is>>b.dg;
b.tt=b.kl*b.dg;
return(is);
}
ostream& operator<<(ostream& os,HD b)
{
os<<b.ma<<'
'<<b.ten<<'
'<<"loai phieu(1-nhap;0-xuat): "<<b.lp<<'
'<<setw(2)<<b.ngay<<"-"<<setw(2)<<b.thang<<"-"<<setw(4)<<b.nam<<'
'<<b.kl<<"kg-"<<b.dg<<"vnd/kg"<<"
thanh tien: "<<b.tt<<"vnd";
return(os);
}
int ktra(HD b)
{
if(b.lp==1) return(1);
else return(0);
}
int HD::operator>(HD b)
{
if((tt-b.tt)>0) return(1);
else return(0);
}
float gt(HD b)
{
return(b.tt);
}
main()
{ HD a[50]; int n;float s=0;
cout<<"nhap so luong vat tu: ";cin>>n;
for(int i=0;i<n;i++)
{ cin>>a[i]; cout<<'
'; } clrscr();
for(i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
if(a[j]>a[i])
{ HD tg=a[i];
a[i]=a[j];
a[j]=tg;
}
for(i=0;i<n;i++)
{ cout<<a[i];
if(ktra(a[i])) cout<<"
la phieu nhap
";
else cout<<"
la phieu xuat
";
}
for(i=0;i<n;i++)
{ s=s+gt(a[i]); }
cout<<"tong gia tri cac hoa don: "<<s<<"vnd";
getch();
}
Bạn đang đọc truyện trên: Truyen247.Pro