Source Code Apoterk Pointer
- 3. SOURCE CODE
#include”stdlib.h”
#include”iostream.h”
class apotek
{
protected :
long int satuan,jumlah;
char obat[20];
int nota,tgl;
public :
long int x;
void beli()
{
cout<<“\n\nNama Obat = “; cin>>obat;
cout<<“Harga Satuan = Rp. “; cin>>satuan;
cout<<“Jumlah Barang = “; cin>>jumlah;
x=satuan*jumlah;
cout<<“Total Harga = Rp. “<<x<<endl;
};
};
class display : public apotek
{
public:
void utama()
{
cout<<“\n APOTEK SUMBER WARAS\n”;
cout<<“—————————\n”;
cout<<“Input ID Nota = “); cin>>nota;
cout<<“Input Tgl sekarang = “;cin>>tgl;
};
void beli()
{
apotek a[10];
int i,n;
long int z;
cout<<“Jumlah Item = “; cin>>n;
for(i=0; i<n; i++)
{ a[i].beli();
}
if(n==1)
z=a[0].x;
else if(n==2)
z=a[0].x+a[1].x;
else if(n==3)
z=a[0].x+a[1].x+a[2].x;
else if(n==4)
z=a[0].x+a[1].x+a[2].x+a[3].x;
else if(n==5)
z=a[0].x+a[1].x+a[2].x+a[3].x+a[4].x;
cout<<“\nTotal Yang Harus anda bayar Rp. “<<z<<endl;
cout<<“\n”;
};
};
void main()
{
display d, *bptr;
apotek b;
bptr = &d;
bptr->utama();
bptr->beli();
}
Tinggalkan komentar