bai6-week4
// 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:
void nhap();
void in();
int ktra();
int operator>(HD);
friend float gt(HD);
};
void HD::nhap()
{ fflush(stdin);
cout<<"nhap ma vat tu: ";gets(ma);
cout<<"nhap ten vat tu: ";gets(ten);
cout<<"nhap 1-neu phieu nhap // nhap 0-neu phieu xuat:";cin>>lp;
cout<<"nhap ngay thang nam lap:
";cin>>ngay>>thang>>nam;
cout<<"nhap khoi luong(kg)vat tu: ";cin>>kl;
cout<<"nhap don gia(vnd/kg)vat tu: ";cin>>dg;
tt=kl*dg;
}
void HD::in()
{
cout<<ma<<'
'<<ten<<'
'<<"loai phieu(1-nhap;0-xuat): "<<lp<<'
'<<setw(2)<<ngay<<"-"<<setw(2)<<thang<<"-"<<setw(4)<<nam<<'
'<<kl<<"kg-"<<dg<<"vnd/kg"<<"
thanh tien: "<<tt<<"vnd";
}
int HD::ktra()
{
if(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++)
{ a[i].nhap(); cout<<'
'; }
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++)
{ a[i].in();
if(a[i].ktra()) 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: AzTruyen.Top