Thursday 23 December 2010

Contoh Program C++: OOP Rekening Bank

#include "iostream.h"
#include "string.h"
#include "stdlib.h"

struct deposit {
double nominal;
struct deposit *next;
};//
typedef struct deposit *simpul;
class rekening_bank {
protected:
char nama[20];
double saldo;
simpul deposits;
int nomer_rek;
public:
void transaksi()
{
double trans=0.0;
simpul baru=NULL;
cout<<"Saldo Anda : "<<saldo<<endl;
cout<>trans;
if (trans<0) //penarikan
{
if ((abs(trans)+5000) nominal = trans;
baru->next = NULL;
if (deposits == NULL)
deposits = baru;
else
{
baru->next = deposits;
deposits = baru;
}
}
else
cout<<"Saldo tidak mencukupi"<nominal = trans;
baru->next = NULL;
if (deposits == NULL)
deposits = baru;
else
{
baru->next = deposits;
deposits = baru;
}
}
};
void cetak()
{
simpul temp=deposits;
cout<<"Saldo Anda : "<<saldo<<endl;
cout<<"Rekap Transaksi :"<next)
if(temp->nominal < 0)
cout<<"Penarikan "<nominal)<<" + 5000 [biaya]"<<endl;
else cout<<"Setoran "<nominal<<endl;
}
};
class cek : public rekening_bank
{
private:
public:
cek(double d) {
cout<<"Rekening cek dibuat..."<<endl;
deposits=NULL;
saldo=d;
};
};
class tabungan : public rekening_bank
{
private:
float bunga;
public:
tabungan(double d)
{
cout<<"Rekening tabungan dibuat..."<<endl;
deposits=NULL;
saldo=d;
};
void hitung_bunga()
{
simpul baru=NULL;
cout<>bunga;
baru = (simpul) malloc(sizeof(struct deposit));
baru->nominal = saldo*bunga;
baru->next = NULL;
saldo = saldo + (saldo*bunga);
if (deposits == NULL)
deposits = baru;
else
{
baru->next = deposits;
deposits = baru;
}
cout<<"saldo sekarang = "<<saldo<<endl;
}
};
void main()
{
cek c(100000);
c.transaksi();
c.cetak();
c.transaksi();
c.cetak();
tabungan b(130000);
b.transaksi();
b.cetak();
b.hitung_bunga();
b.cetak();
//lebih baik dibuatkan menu program
}

Download Source Code

No comments:

Post a Comment